-
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
Clarify history.pushState/replaceState behavior with history navigation, bfcache #6207
Comments
This sounds a lot like #4488 and https://www.w3.org/Bugs/Public/show_bug.cgi?id=27188. Personally I think the behavior makes sense, but as discussed A.html needs to be given the appropriate events so it can make the document appear as expected. (Unfortunately back then no tests or browser bugs would be filed if the specification was deemed acceptable...) |
If we want to allow this, we might need to add a "document ID" or something like that to session history entry, and modify the traverse the history steps to only trigger a navigation/new load if the document ID differs. This is what Chrome does with Document Sequence Numbers. The behavior is pretty not obvious to me, so maybe we also want to add clarifying notes in the spec. Not sure if this can have side effects in other parts of the spec too. cc @jakearchibald in case this affects #5767 (maybe not, if we only need to add the document ID part) |
I think the behavior is somewhat obvious, as much as it can be given the weird behavior pushState with an URL causes. |
Let's say there is a block of history entries that all came from the same document via 1 If the page came out of bfcache, that navigation will just be a URL/state change (this is exactly the same as if I had never left the block) If I history-navigate to more and more of those pages I will turn that previously contiguous block that shared a document into a block of entries each with distinct documents. It actually seems reasonable (in fact what's implemented) that for 2, we would do no more navigations and full loads of pages as we move around inside that block. @smaug---- Are you saying 2 is obvious or that what we've implemented is obvious? Obviously the right thing? I cannot find anything in the spec that would reset the If we don't reset to null then we will almost never enter the |
The current browser behaviour (rather than the spec behaviour) makes way more sense when it comes to hash navigations:
The spec says that step 6 should result in another network request, creating a new document. Whereas browsers just change the hash. The spec behaviour doesn't make sense to me, so I'm glad that browsers do what they do. The browser Let's say the developer used However, it isn't obvious that the code at I don't have any better ideas though. It feels like it should load |
It might not be the full app but it also seems reasonable to say, that all URLs that can I don't know the history of
result in a navigation for the first Back and a URL change only for the next move. So, the impl assumes that that entire block of history is 1 app and it doesn't really matter how you get into it, once you're in it, you're in the app. |
Here's another scenario A->pushState(B)->C->Back(1)->C->Back(1)->Back(1) In chrome that last navigation will just change URL and not do a load. So the history looks like but at the point of the last navigation A and B's only connection is that when they were created they were the same document so I think having concept of the original document for an entry might be useful. |
In #6315 I'm going to spec what browsers currently do. In this model, a session history entry has a document state. That state is shared between history entries that share the same document. That means, if the document is discarded, or is updated following a reload, it updates across all the history entries that share the document state. I followed up in WICG/navigation-api#99 (comment), in case we need to help developer to do the right thing. |
That sounds great. So it seems like the current behaviour and the bfcache behaviour are in line and only the spec is out of line and @rakina's original concerns are not a problem? |
That's certainly my view. Others may reject my changes though 😄 |
Fwiw, I created a video going through this behaviour https://www.youtube.com/watch?v=CY-Zv0bmmRk |
Oh, wow, that video is mind-blowing. I guess we have to spec it, but there's a good amount of non-normative or semi-normative text that will need updating. Ctrl+Fing "contiguous" finds a good number of them. |
Bug: 1107415, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
Bug: 1107415, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
Bug: 1107415, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
Bug: 1107415, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
Bug: 1107415, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
Bug: 1107415, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
Bug: 1107415, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
When doing history navigation to an entry that's created via pushState, the page should be: - With BFCache: Restored from BFCache. - Without BFCache: Loaded from the URL set by `pushState()`. While this test contradicts the current spec but matches the desired behavior, and the spec will be fixed as part of whatwg/html#6315. Bug: 1107415, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
When doing history navigation to an entry that's created via pushState, the page should be: - With BFCache: Restored from BFCache. - Without BFCache: Loaded from the URL set by `pushState()`. While this test contradicts the current spec but matches the desired behavior, and the spec will be fixed as part of whatwg/html#6315. Bug: 1107415, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
When doing history navigation to an entry that's created via pushState, the page should be: - With BFCache: Restored from BFCache. - Without BFCache: Loaded from the URL set by `pushState()`. While this test contradicts the current spec but matches the desired behavior, and the spec will be fixed as part of whatwg/html#6315. Tests pass on Firefox/Safari/Chrome, except for Safari on non-BFCache case (just because WebLock doesn't disable BFCache). Bug: 1107415, 1298336, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c
When doing history navigation to an entry that's created via pushState, the page should be: - With BFCache: Restored from BFCache. - Without BFCache: Loaded from the URL set by `pushState()`. While this test contradicts the current spec but matches the desired behavior, and the spec will be fixed as part of whatwg/html#6315. Tests pass on Firefox/Safari/Chrome, except for Safari on non-BFCache case (just because WebLock doesn't disable BFCache). Bug: 1107415, 1298336, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3199857 Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Domenic Denicola <domenic@chromium.org> Reviewed-by: Rakina Zata Amni <rakina@chromium.org> Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Cr-Commit-Position: refs/heads/main@{#972799}
When doing history navigation to an entry that's created via pushState, the page should be: - With BFCache: Restored from BFCache. - Without BFCache: Loaded from the URL set by `pushState()`. While this test contradicts the current spec but matches the desired behavior, and the spec will be fixed as part of whatwg/html#6315. Tests pass on Firefox/Safari/Chrome, except for Safari on non-BFCache case (just because WebLock doesn't disable BFCache). Bug: 1107415, 1298336, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3199857 Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Domenic Denicola <domenic@chromium.org> Reviewed-by: Rakina Zata Amni <rakina@chromium.org> Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Cr-Commit-Position: refs/heads/main@{#972799}
When doing history navigation to an entry that's created via pushState, the page should be: - With BFCache: Restored from BFCache. - Without BFCache: Loaded from the URL set by `pushState()`. While this test contradicts the current spec but matches the desired behavior, and the spec will be fixed as part of whatwg/html#6315. Tests pass on Firefox/Safari/Chrome, except for Safari on non-BFCache case (just because WebLock doesn't disable BFCache). Bug: 1107415, 1298336, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3199857 Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Domenic Denicola <domenic@chromium.org> Reviewed-by: Rakina Zata Amni <rakina@chromium.org> Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Cr-Commit-Position: refs/heads/main@{#972799}
When doing history navigation to an entry that's created via pushState, the page should be: - With BFCache: Restored from BFCache. - Without BFCache: Loaded from the URL set by `pushState()`. While this test contradicts the current spec but matches the desired behavior, and the spec will be fixed as part of whatwg/html#6315. Tests pass on Firefox/Safari/Chrome, except for Safari on non-BFCache case (just because WebLock doesn't disable BFCache). Bug: 1107415, 1298336, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3199857 Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Domenic Denicola <domenic@chromium.org> Reviewed-by: Rakina Zata Amni <rakina@chromium.org> Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Cr-Commit-Position: refs/heads/main@{#972799}
…n-BFCache cases, a=testonly Automatic update from web-platform-tests [WPT] BFCache: pushState() in BFCache/non-BFCache cases When doing history navigation to an entry that's created via pushState, the page should be: - With BFCache: Restored from BFCache. - Without BFCache: Loaded from the URL set by `pushState()`. While this test contradicts the current spec but matches the desired behavior, and the spec will be fixed as part of whatwg/html#6315. Tests pass on Firefox/Safari/Chrome, except for Safari on non-BFCache case (just because WebLock doesn't disable BFCache). Bug: 1107415, 1298336, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3199857 Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Domenic Denicola <domenic@chromium.org> Reviewed-by: Rakina Zata Amni <rakina@chromium.org> Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Cr-Commit-Position: refs/heads/main@{#972799} -- wpt-commits: a400637a6ee3b7b6f315be2a17a7b28257663b4b wpt-pr: 31083
…n-BFCache cases, a=testonly Automatic update from web-platform-tests [WPT] BFCache: pushState() in BFCache/non-BFCache cases When doing history navigation to an entry that's created via pushState, the page should be: - With BFCache: Restored from BFCache. - Without BFCache: Loaded from the URL set by `pushState()`. While this test contradicts the current spec but matches the desired behavior, and the spec will be fixed as part of whatwg/html#6315. Tests pass on Firefox/Safari/Chrome, except for Safari on non-BFCache case (just because WebLock doesn't disable BFCache). Bug: 1107415, 1298336, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3199857 Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Domenic Denicola <domenic@chromium.org> Reviewed-by: Rakina Zata Amni <rakina@chromium.org> Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Cr-Commit-Position: refs/heads/main@{#972799} -- wpt-commits: a400637a6ee3b7b6f315be2a17a7b28257663b4b wpt-pr: 31083
work is ongoing |
When doing history navigation to an entry that's created via pushState, the page should be: - With BFCache: Restored from BFCache. - Without BFCache: Loaded from the URL set by `pushState()`. While this test contradicts the current spec but matches the desired behavior, and the spec will be fixed as part of whatwg/html#6315. Tests pass on Firefox/Safari/Chrome, except for Safari on non-BFCache case (just because WebLock doesn't disable BFCache). Bug: 1107415, 1298336, whatwg/html#6207 Change-Id: I609276fe865fa92409fd7a547777dba222bac36c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3199857 Reviewed-by: Kouhei Ueno <kouhei@chromium.org> Reviewed-by: Domenic Denicola <domenic@chromium.org> Reviewed-by: Rakina Zata Amni <rakina@chromium.org> Commit-Queue: Hiroshige Hayashizaki <hiroshige@chromium.org> Cr-Commit-Position: refs/heads/main@{#972799} NOKEYCHECK=True GitOrigin-RevId: 760e13ee79efa16c7dfc42e86c12da60e1aed9d6
Was this resolved by the navigation and history rewrite? |
I'm not sure. The spec might have a sensible answer now, but I'm pretty sure we didn't create WPTs for that answer if so, so leaving this open to track that work seems good. |
Hey all, we just ran into this today on our site. Our use-case is something like the following: We have a "main page", where you can view an artist and modals displaying their albums, songs, activity, etc and several "sub pages" for each individual list (e.g. an artist songs list, and artist albums list, etc). These subpages are relatively simple, but for SEO reasons we want to make sure they have the same URL no matter how the user views that content (either through the modal from the "main page" or from the "sub page") Using pushState, this looks something like:
This all works fine. However, once the user navigates away, the problems start:
Is there any way we can work around this as-is today? Maybe something with the history state object? |
We recently found an interesting case with history navigation to/from entries created with
history.pushState
orhistory.replaceState
.(Also, if you change step 4 to do a back-2-steps navigation it will load the contents of A.html, and if you go forward it will still show A.html but with the URL bar showing B.html)
Here's a repro page. I think according to the current spec, step 5 we would load the contents of A.html, but looks like in Chrome, Firefox, and Safari we will stay with the contents of B.html page. Steps according to the spec:
With bfcache, the expectation is different. On step 4, if the document is still around, we will just load the bfcached A.html document (but the URL bar is set to B.html). On step 5, the document is also still alive so we will stay in A.html + set the URL bar to A.html. This is the same as the current non-bfcache behavior in Chrome/Firefox/Safari.
I'm wondering if the current non-bfcache behavior is desirable, and if so whether we should update the spec to allow this. If we decide that the currently-implemented behavior is wrong, this means the behavior with vs without bfcache will be different (not sure if that's a big deal).
cc navigation/history-related folks @annevk @csreis @domenic @cdumez @altimin
(see bug where we originally found this).
The text was updated successfully, but these errors were encountered: