-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Navigating to same url - replace or add? #6682
Comments
Like a reload, or like a same-URL replace? As visible to service workers :).
This was fairly surprising to me!
Strongly agreed; it'd be good to settle on whether we're doing a replace or push synchronously, and not change our mind later. |
So @rakina found an added wrinkle here, which is the connection to #6213. In Chrome currently, whether you do replace/default depends on comparing the original request URL to the document's current URL (*). Whereas, whether you carry over the history.state value depends on comparing the final response URL to the document's current URL (*). This means that if you do More broadly, we have three options:
The current spec discussion seems to be leaning toward (3), but maybe there's value in the consistency of (1) or (2). (*) "document's current URL": this is further complicated by #6649. I'm not sure which of the two possible "current URLs" Chrome uses in |
This gets complicated if we need to change behaviour if any of the redirects are cross-origin. I'm not sure if the cross-origin thing is a real issue, but it feels bad.
You'd still need to check the response URL to avoid transferring history state cross-origin… so would you change replace/append here too for consistency?
As in, what Chrome currently does? I think this is what I prefer. The asymmetry is weird, but |
A detail that I haven't seen covered elsewhere, but thankfully it's consistent between browsers: POST navigations to the same URL append a new entry, rather than replace the current entry. GET form submissions appear to behave like link clicks (phew). Navigations from a page that loaded via a form submission don't appear to behave in any special way (also phew). TestsTest:
Chrome, Firefox, Safari: add add Test:
Chrome, Firefox, Safari: Replace Test:
Chrome, Firefox, Safari: Replace |
(in fact, form submission is kinda forgotten about in 'navigate'. Eg, the spec says that a form submission to a URL that only differs by fragment shouldn't submit at all, and should just perform an in-page navigation) |
Test:
Chrome, Firefox: add I'm going to stick with what Chrome & Firefox do here. |
It seems like:
/a
to/a
is treated like a reload (replaces history entry)./a
to/a#foo
is a hash change navigation./a#foo
to/a
is a full navigation to/a
(adds a history entry).However, replace should only happen if the initiator is same origin to the current document.
There's a non-interoperable case when it comes to redirects:
/b
which redirects to/a
In this case Chrome & Safari will add a new history entry, whereas Firefox will replace the existing entry (or treat it like a reload, I'm not sure which).
I don't think it matters too much which behaviour we go with, but the Chrome/Safari behaviour seems simpler.
Firefox will switch to 'replace' even if part of the redirect is cross-origin, but I don't think that really matters in this case, because I'm pretty sure it's already observable.
@annevk @domenic @smaug---- this is the case we 'discovered' in the meeting.
Tests
Test:
/a
Chrome, Firefox, Safari: replace doc in entry1
Test:
/a#foo
- entry2/a
Chrome, Firefox: 3 history entries, first two share a document
Safari: 3 buggy history entries. Going back results in no doc change. Going back again results in no doc change, but also no hash change.
Test:
/b
which redirects to/a
Chrome, Safari: 2 history entries, separate documents
Firefox: replace doc in entry1
Firefox will still replace if the redirect goes via another origin.
Test:
/a#foo
- entry2/b
which redirects to/a
Chrome, Firefox: 3 history entries, first two share a document
Safari: 3 buggy history entries. Going back results in no doc change. Going back again results in no doc change, but also no hash change.
Test:
/a#foo
- entry2/b
which redirects to/a#hello
Chrome, Firefox: Entry 3 has a different doc to entries 1 and 2 (which continue to share a doc).
Safari: 3 buggy history entries. Going back results in no doc change. Going back again results in no doc change, but also no hash change.
The text was updated successfully, but these errors were encountered: