Description
We recently found an interesting case with history navigation to/from entries created with history.pushState
or history.replaceState
.
- Navigate to A.html
- pushState B.html, we're still showing the page to A.html but the URL in the address bar is set to B.html (expected)
- Navigate to C.html
- Do a back navigation, we'll load B.html (expected)
- Do a back navigation, we will still show the page loaded for B.html, but the URL in the address bar changes to A.html (not expected, according to spec - see below)
(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:
- Step 1 wil create a new entry "entry1"
- Step 2 will create a new entry "entry2" with URL and history update steps
- Step 3 will navigate away. The entry created in step 2 might retain its document if it's bfcached, otherwise the document will get discarded. Let's assume the latter case for now.
- Step 4 will navigate to the "entry2" created in step 2. This will run traverse the history, and since the document for that is already discarded we will run navigate that loads B.html
- Step 5 will navigate to the "entry1" created in step 1. The document for "entry1" should also already be discarded at this point so we will run navigate that loads A.html (instead of only updating the URL bar like what happens in Chrome/Firefox/Safari)
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).