Page MenuHomePhabricator

Media Viewer: Scroll position is lost on original page after accessing the original file
Closed, ResolvedPublic

Description

When a user clicks on an image in a page to open Media Viewer and then proceeds to view the original file, previous page position is lost when navigating back to the host page.

  1. Go to any article with images and scroll down a way.
  2. Click on any image.
  3. In Media Viewer, click the image again to go to the full-size version.
  4. Finish looking at the full-size version, so click browser "back" button and then "X" in MV, or click browser "back" button twice.
  5. You return to the top of the original page, not where you were scrolled to

Version: unspecified
Severity: normal

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:54 AM
bzimport added a project: MediaViewer.
bzimport set Reference to bz71796.
bzimport added a subscriber: Unknown Object (MLST).

This is default browser behavior when reopening a hash link through the history. We can build something specific to act as a workaround, like storing the scroll position for a given hash in local storage, or making the scroll position part of the hash code.

This should not be the default behavior for at least some browsers, as they normally cache the page state in memory for history navigation ("bfcache"). We should figure out what in MediaViewer (or MediaWiki) breaks bfcache.

https://developer.mozilla.org/en-US/docs/Using_Firefox_1.5_caching
http://stackoverflow.com/questions/1195440/ajax-back-button-and-dom-updates/1195934#1195934

I think the cache is doing what it's supposed to. If you have media viewer open, the page scroll is 0. So at the time you move to another page, that's what the browser remembers and restores.

I.e. the browser can't be aware that media viewer "isn't really the page".

As for storing page location in localStorage, we are building hack upon hack to pretend we have a zoom function. If the current state is not acceptable, instead of further twiddling we should just suck it up and actually build one.

I didn't suggest that we should implement this hack, I'm just listing possibilities for posterity :) I personally think that trying to compensate for the browser's natural behavior isn't the way to go.

(In reply to Gilles Dubuc from comment #3)

I think the cache is doing what it's supposed to. If you have media viewer
open, the page scroll is 0. So at the time you move to another page, that's
what the browser remembers and restores.

MediaViewer stores the scroll position in a JS variable. If bfcache worked properly, upon backnavigation the browser would reload the page with MediaViewer open and the scroll position variable set, and MediaViewer uses that to restore the scroll position on close.

What actually happens is that the page is restored in its initial position, with MediaViewer closed; and the scroll position is reset due to the hash, so by the time MV opens and stores the scroll position it's zeroed out.

On the topic of relying on the browser, I guess then the solution is to close Media Viewer's UI like ninjas onbeforeunload, but without clearing the hash. This way when navigating back, the browser scroll cache kicks in, and the hash makes media viewer open.

Still an ugly hack... albeit a much faster one to implement.

Mass-removing the Multimedia tag from MediaViewer tasks, as this is now being worked on by the Reading department, not Editing's Multimedia team.

Change 560576 had a related patch set uploaded (by Aron Manning; owner: Aron Manning):
[mediawiki/extensions/MultimediaViewer@master] After closing, browser sometimes scrolls to the top of the page

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

Change 560576 had a related patch set uploaded (by Aron Manning; owner: Aron Manning):
[mediawiki/extensions/MultimediaViewer@master] Save history position before opening MMV; remove need to restore scroll position; replace javascript-positioning with static css; cleanup html and css.

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

Demian subscribed.

The submitted patch resolves this bug too.

[Resetting assignee due to inactive user account]

Change 560576 abandoned by Ladsgroup:

[mediawiki/extensions/MultimediaViewer@master] Save history position before opening MMV; remove need to restore scroll position; replace javascript-positioning with static css; cleanup html and css.

Reason:

The author has been banned indef from our tech spaces and the patch has not been touched for really long time.

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

Not sure why this is "low" priority. This is experienced by and an annoyance of almost everyone who has ever visited Wikipedia on desktop - which is a lot of people. Should be high in my opinion...

matmarex changed the task status from Open to Stalled.May 25 2023, 9:31 PM
matmarex subscribed.

This seems to work as desired these days: following the reproduction steps, I return to the previous scroll position on the original page. Likely this is caused by some behavior changes in the browsers, rather than in our code. Can anyone still reproduce the issue? And on which browsers?

No reply; closing for now. Please reopen (with exact browser and browser version info, after reproducing the problem in safemode) if this is still an issue. Thanks!