-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updating the session history seems pretty broken #6197
Comments
I posted #6199 as a first stab to fix this issue, purely going off the above analysis. If any of it is wrong, I'm happy to update the PR accordingly. |
So I reviewed #6199 and two things make me a bit unsettled about your proposed solution:
I think taking the "replace" approach for the "reload" case is probably the right move. I'm less sure about entry update. If you look at entry update's call site, it seems like it really does want to replace the current entry's document, and not create a new entry? At least conceptually, and judging from the non-normative note
i.e. it references the specific entry entry. But, we do want to trigger the (currently faulty) "If newDocument is different than the current entry's document, then" clause for entry-update. Hmm. Finally, I spent some time figuring out what
means, and it has a separate bug I will file. |
Yeah, it's a bit awkward; as you point out, the reason I went with it is because after we "replace the current entry", the value of current entry is now different, which I don't think is what we want because any time we invoke #traverse-the-history with current entry, we're guaranteed to not trip Step 5 and never activate the document. Basically I'm trying to figure out the best way to make sure that whenever we make a Document change, #traverse-the-hisory > Step 5 catches it, as you point out later in your comment.
Well per spec, if you call
I saw that and did like the approach there, however I don't see a great way to weave it into other history handling modes right away while satisfying (1) Keeping the session entry the same (as you point out I think it would be reasonable to modify my PR to create a "correct" version of today's spec like so:
It's possible I'm missing something huge, but from taking a closer look those are my thoughts. WDYT? |
Ugh, yeah, that seems pretty bad. This seems like it was the case even back in 2016 though, so at least it's not a recent regression.
I think this would work, although I'm partial to solving replace and the same-URL case in a single PR so that we're sure we have a plan. I could chip in on top of what you describe. Let's consider some important features that distinguish them:
Let me do some testing on "reload" and same-URL but not reload... |
https://boom-bath.glitch.me/session-history-1.html shows that reload is indeed very similar to entry update. Same URL (non-reload/entry update case, potentially including replace) seems to resets everything in Firefox. In Chrome it resets the scroll position, but does not reset
The results for My recommendation would then be:
|
Thanks for the analysis and the discussion!
I'm prettyyyy sure that this lines up with my latest proposal above, with the exception that you're handling the same-URL case explicitly here as best we can without solving it entirely. Given that, I've updated the PR in #6199 to reflect the latest proposal(s), so PTAL! |
This fixes several related issues surrounding the "update the session history with the new page" and "traverse the history" algorithms. * A mistaken attempted refactoring in #6039 got the wrong Document for the newDocument variable in "traverse the history". To fix this, we explicitly pass in the new document to the algorithm from all its call sites. (Discussed in #6197.) * As discussed more extensively in #6197, the same-URL and entry update/reload conditions in "update the session history with the new page" were not correctly triggering the new-document clause in "traverse the history", despite replacing the document. This was partially due to #6039, although the phrasing before #6039 was extremely ambiguous, so #6039 was mostly a transition from "unclear" to "clearly wrong". * This fixes the "easy bug" discussed in #6202, where the same-URL case was using the wrong URL to determine sameness. That bug was also introduced in #6039. The harder bug, as well as the action-at-a-distance nature of the same-URL check, remain tracked in #6202. * For years, the spec has required deleting the future session history entries after performing a navigation with history handling of "replace", e.g. via location.replace(). This is not correct; a "replace" navigation does not delete future session history entries. Instead it just replaces the current entry, leaving future entries alone. * The latter point makes the handling of same-URL navigations almost identical to "replace" navigations (including non-same-URL "replace" navigations). This change makes this clear, by using the same text for both, but adding a pointer to #6213 which highlights the fact that some browsers treat them slightly differently (and some treat them the same). * Finally, this adds or modifies a few assertions to check that we're in the "default" history handling behavior, so it's clearer to the reader what the non-exceptional path through the spec is. Closes #6197.
Earlier this week I noticed that we don't always set a Window's
associated Document
(via setting the browsing context's active document) right away after creating the Window, which can lead to some weird problems. While going down this rabbit hole and discussing this more with @domenic I realized that the following flow is pretty broken:While trying to figure out the best way to fix this, I think the idea is that we need to plumb in the correct "new document" to the #update-the-session-history-with-the-new-page algorithm so that we can appropriately reference it in Step 1, instead of accidentally referencing the old document.
However even once we fix this, from talking with Domenic I think we still have the following problem:
Let’s analyze the two conditionals in #update-the-session-history-with-the-new-page below:
Let's analyze both cases:
entry-update
entry-update
dfn. The dfn says that we won’t be creating a new session history entry, but instead will update the existing current entry with a brand new document, and traverse to this current entry. However I am not sure how this is actually supposed to work. The flow forentry-update
looks like this:reload
reload
's dfn says. The dfn states that we'll reload the current entry's document by: creating a brand new history entry, putting it in place of the current entry (_which from my understanding doesn't actually change current entry’s value), and navigating to the new entryI don’t think this is doing the right thing. I first read this as if it were setting current entry to a new session history entry, and then traversing the history to it. However after talking to Domenic I think it's doing something different, but equally wrong: Putting a new entry in the session history where current entry is (current entry's value hasn't changed), and invoking traverse-the-history with current entry. I think it should invoke #traverse-the-history with the new entry, so that #traverse-the-history > step 5 actually compares the two distinct entries. Does that make sense?
If my analysis is right, then I think to fix all of these there are the following action items:
active document
, and (b) Window's associated Document`, so that we can set a Window's associated Document ASAP, without setting the browsing context's active document.Thoughts?
The text was updated successfully, but these errors were encountered: