Page MenuHomePhabricator

Live preview fails to prevent itself from executing when previewing a user CSS/JS more than once
Closed, DuplicatePublicBUG REPORT

Description

Steps to Reproduce:

  • Check "Show previews without reloading the page" in Preferences -> Editing
  • Open a CSS or JavaScript in the User namespace that you can edit, e.g. Special:MyPage/common.css
  • Click "Show preview" – the page reloads
  • Click "Show preview" again

Actual Results:

  • Only the preview area, not the entire page, reloads, without executing the new code.

Expected Results:

  • The entire page reloads just like the first time, with the new CSS/JS code executed.

It looks like this is because mediawiki.action.edit.preview.js looks for #mw-userjsyoucanpreview and #mw-usercssyoucanpreview, which only appear in the first preview. I believe this can be solved by instead seeing if mw.config.get( 'wgNamespaceNumber' ) returns 2 and if mw.config.get( 'wgPageContentModel' ) returns css or javascript.

Event Timeline

By the way, I've never really understood the point of preventing the live preview when viewing a diff, not a preview, of a user CSS/JS. I've find it a bit annoying when I want to simply check the diff and the entire page reloads.

Change 626846 had a related patch set uploaded (by Gerrit Patch Uploader; owner: Nardog):
[mediawiki/core@master] LivePreview: More reliable way to allow previewing user CSS/JS

https://gerrit.wikimedia.org/r/626846

Ammarpad subscribed.

As I said on Gerrit, the above patch does not actually fix the bug, it just worked it around by 'disabling the live preview feature'. In other words, it means ignoring users' preferences (for live preview) on user config pages at all.
It's not new alternative though, as it has been proposed in T186390 already. But it's not as small change as it looks, and so should probably be mentioned in TechNews first and seek feedback, so that people should not wonder whether it's another bug when they observe preview is ignoring their preferences. T186390 can then be descoped to focus on actually fixing the bug only, whenever it's feasible/someone has time to do it.

Expected Results:
The entire page reloads just like the first time, with the new CSS/JS code executed.

That's not correct. If you want the page to reload entirely, you need to uncheck the Show previews without reloading the page checkbox.

...with the new CSS/JS code executed

That's a known bug. T186390: Javascript preview feature broken when live previews are enabled

The entire page reloads just like the first time...

That initial reload is not intentional itself, see T186390

The entire page reloads just like the first time...

That initial reload is not intentional itself, see T186390

Then why is this code there in the first place?

// Do not enable on user .js/.css pages, as there's no sane way of "previewing"
// the scripts or styles without reloading the page.
if ( $( '#mw-userjsyoucanpreview' ).length || $( '#mw-usercssyoucanpreview' ).length ) {
	return;
}

Expected Results:
The entire page reloads just like the first time, with the new CSS/JS code executed.

That's not correct. If you want the page to reload entirely, you need to uncheck the Show previews without reloading the page checkbox.

...with the new CSS/JS code executed

That's a known bug.

If that were the case, all you need to do is remove the block.

And all T186390 says is:

With the live preview option enabled, previewing a .js page to test the script does not work. (Interestingly, it works the first time, but not afterwards.)

There isn't really a way to unload the old version of a script; live preview should just disable itself on JS pages.