Closed Bug 1561900 Opened 6 years ago Closed 5 years ago

Scroll-to-line when going back or restoring closed tab is broken

Categories

(Core :: Layout, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
Tracking Status
firefox74 --- fixed

People

(Reporter: kats, Assigned: emilio)

References

(Regression)

Details

(Keywords: regression)

Attachments

(2 files)

Start at a URL with a line number, e.g. https://searchfox.org/mozilla-central/source/dom/events/PendingFullscreenEvent.h#27

Click on things and navigate forward ~5 pages (enough that the original URL is no longer in the bfcache, I think). In my case I clicked on Document function and did a symbol search, then clicked on the single use of it, then clicked on the CancelPendingFullscreenEvents function name and did another symbol search, and then clicked on the single use of that.

Then hit back repeatedly until you're back at the starting URL.

Expected: when the starting URL loads (not from bfcache), it scrolls down to show the appropriate line number

Actual: it doesn't.

You can then repeat hit "forward" repeatedly to go the "last" URL (in my example it's at Document.cpp#5986) and the same thing happens, because that page isn't in the bfcache any more.

Pretty sure this is a regression from one of the hashchange/scroll-to-line patches that went along with bug 1533802

Easier STR:

Expected:

  • page scrolls down to show line number

Actual:

  • page is at the top
Summary: Scroll-to-line when going back is broken → Scroll-to-line when going back or restoring closed tab is broken

This might be a load race, possibly due to how sessionstore reloads tabs?

I just did the steps in your excellent comment 1 STR and easily reproduced. I then brought up devtools and did:

document.getElementById('62')
<div id="62" class="goto">

That "goto" thing is our synthetic anchor which is what makes the browser able to jump to the right position including the scrolling position padding (which we can switch to using https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-padding now that 68 is in release). This magic is more essential for cases like "#68-70" where the browser could never do that even if we changed our anchors so that the line numbers were "68" instead of "l68".

So the question is why we're not jumping to that anchor given that the magic does seem to be trying to do the right thing. I'd guess we're creating the div too late. Or sessionstore is betraying us.

I'm cc'ing bz for his interest and wisdom in this scenario previously in case there's something more subtle we should know about with how the anchor seeking works.

So there are four things that may happen during the history load here, presumably:

  1. Gecko trying to restore the scroll position from the history entry. This generally works, but seems to be broken on searchfox, probably because one of the other things that are going on stomps on it. That part is annoying in its own right, actually: if I got back/forward to a searchfox tab it loses my scroll position if I've scrolled it, again modulo bfcache. :(
  2. Gecko trying to scroll to the anchor position from the URL. This is meant to happen before #1, so #1 should win.
  3. The page trying to scroll to somewhere manually from the searchfox scripts
  4. The page adding that goto div.

Presumably the intent is that #4 happens before #3, right? Is that the case during the history load?

I had a patch here that seemed to work btw, and involved using pageshow and tweaking the anchor scrolling code in searchfox...

(In reply to Emilio Cobos Álvarez (:emilio) from comment #5)

I had a patch here that seemed to work btw, and involved using pageshow and tweaking the anchor scrolling code in searchfox...

That sounds good! Assigning to you!

Assignee: nobody → emilio
Status: NEW → ASSIGNED
Attached file Reduced test-case.

STR:

  • Scroll to some position.
  • Click on the link.
  • Navigate back.

ER:

  • Restored scroll position.

AR:

  • Scroll position is lost.

So this is a Gecko bug?

There is no way this ever properly worked, as we always passed null for
aFrameState.

So it'd only work if we reframed the document element or such... Which is not
amazing.

For simpler test-cases, when we don't construct the scrollframe via
PresShell::Initialize, but via the regular frame constructor updates
(ContentAppended, etc...), those end up working because we go through lazy frame
construction, which ends up in RecreateFramesForContent, which passes
mTempFrameTreeState.

(In reply to Andrew Sutherland [:asuth] (he/him) from comment #9)

So this is a Gecko bug?

Yes ;)

(So I'm glad I did this instead of my searchfox wallpaper)

https://github.com/mozsearch/mozsearch/pull/269 is the only part that's worth landing for searchfox, I think.

Here's a green try run: https://treeherder.mozilla.org/#/jobs?repo=try&revision=5fa52306675d5e082e2a4a74da3f2f412e0fc6f6

And I verified that the test fails without the patch applied.

(In reply to Emilio Cobos Álvarez (:emilio) from comment #11)

(In reply to Andrew Sutherland [:asuth] (he/him) from comment #9)

So this is a Gecko bug?

Yes ;)

\o/

Amazing work! (Although I'm a little worried that I'll learn the wrong lesson here... make sure when I next regress things to speak up if you're confident I just regressed things ;)

(In reply to Emilio Cobos Álvarez (:emilio) from comment #12)

(So I'm glad I did this instead of my searchfox wallpaper)

Can we still have this too? :)

(In reply to Andrew Sutherland [:asuth] (he/him) from comment #15)

Can we still have this too? :)

Well the searchfox wallpaper would basically scroll the anchor into view on pageshow. That's better / more likely to be correct than the current behavior, but it's worse than the restoration behavior. We could try to detect it if scrollTop == 0 and then scroll into view... But that's not always great.

Oh, I thought you meant like you were making a desktop background wallpaper. Like http://blog.seanmartell.com/wp-content/uploads/2012/03/logo_0013_14.png writ large or what not. I get your meaning now, though!

(In reply to Andrew Sutherland [:asuth] (he/him) from comment #17)

Oh, I thought you meant like you were making a desktop background wallpaper. Like http://blog.seanmartell.com/wp-content/uploads/2012/03/logo_0013_14.png writ large or what not. I get your meaning now, though!

Oh! Whoops nope, my art skills are probably terrible anyway... But now I wonder how a Searchfox wallpaper would look like! :D

Pushed by ealvarez@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/802afff4c1de Fix scroll state restoration when not coming from the bfcache on the initial frame construction. r=bzbarsky
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED

This is still reproducible for me on the latest Nightly. I'm using the URL below[1] to test with. Restoring a closed tab, or a browser restart with session restore results in the page loading at the top of the page and not automatically scrolling to the URL anchor. I tried mozregression, but could not find a good revision to test with.

Was bug 1569820 erroneously closed as a duplicate? Or should we file a new bug to tackle this again?

  1. https://searchfox.org/mozilla-central/rev/40e889be8ff926e32f7567957f4c316f14f6fbef/widget/cocoa/nsToolkit.mm#205
Flags: needinfo?(emilio)

Yes, that bug looks different. This is about the bfcache. There's no bfcache involved when restoring the session afaict. It may be a sessionrestore bug, or a different layout bug, or a searchfox bug (the anchors for line numbers are dynamic).

Flags: needinfo?(emilio)
Component: Searchfox → Layout
Product: Webtools → Core
Has Regression Range: --- → yes
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: