-
Notifications
You must be signed in to change notification settings - Fork 26
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
Should window.navigation fire events fire on page load? #31
Comments
IMO, I'd prefer to get a |
Ugh there was a bug for a long time where safari would trigger the popstate on pageload. What a nightmare. But the nightmare wasn't that it fired, just that it was incompatible with other browsers. I think that I too like getting navigateTo and currententrychange notifications for cross-page navigations. This is especially relevant because in a world where we don't have bfache, loading HTML from network cache is actually pretty confusing. Imagine:
The application would PROBABLY like to re-do whatever additional rendering it did in 2, but it can't do that unless it knows the navigation took place. Having to add a pageshow handler for what is essentially just a back navigation feels weird - and in fact, you might want to KNOW that it was a back navigation from a cross-document page, which the pageshow event doesn't really tell you. |
OK, cool, I'm pretty sold then. The question is what the timing should be. The connection to I guess in general there's a tradeoff with these events, where earlier lets your page start doing important stuff faster, but if it's too early then the script listening for the event might not be loaded. This would be solved by moving to promises (e.g. an |
That's interesting I never considered the wrinkle about pageshow triggering as late as the load event. I do think that we should at least wait to fire these events until the scripts on the page have loaded. Otherwise, it's just so easy to miss these events and then people would just end up reading from current entry which is useful, but doesn't for instance tell you that this is in fact a back navigation to a previous page, unless you do hacks like put little tokens into history state so you know you've been to this page before (which, we currently do). |
I would expect there to be some event and it should fire consistently after pageshow. |
@smaug----, @annevk, @natechapin and I had an offline discussion and we became convinced it's too weird to fire const oldEntry = navigation.currentEntry;
navigation.oncurrententrychange = () => {
console.assert(navigation.currentEntry !== oldEntry);
}; but that assert would fail if we started firing the event on page load. Based on the comments in this thread, it does sound like it'd be useful for developers, if there were some event which fired either at We're hopeful that routing frameworks that use the navigation API will help guide the way here, by figuring out what timing is most useful for web developers, and bundling that up into a single event. Then, in the future, we could add some kind of But in the meantime, creating a shared function that runs in response to both To the point
I will add a web platform test that nothing navigation API-related fires on page load, so as to avoid this issue in the future :) |
See WICG/navigation-api#31 and in particular the concern about previous non-interop with popstate, which we want to head off this time. Bug: 1183545 Change-Id: If16a61a8b0a8846d2bcdbb05b3b7230e0f842b3c
See WICG/navigation-api#31 and in particular the concern about previous non-interop with popstate, which we want to head off this time. Bug: 1183545 Change-Id: If16a61a8b0a8846d2bcdbb05b3b7230e0f842b3c
See WICG/navigation-api#31 and in particular the concern about previous non-interop with popstate, which we want to head off this time. Bug: 1183545 Change-Id: If16a61a8b0a8846d2bcdbb05b3b7230e0f842b3c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3533169 Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Auto-Submit: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/main@{#982939}
See WICG/navigation-api#31 and in particular the concern about previous non-interop with popstate, which we want to head off this time. Bug: 1183545 Change-Id: If16a61a8b0a8846d2bcdbb05b3b7230e0f842b3c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3533169 Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Auto-Submit: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/main@{#982939}
See WICG/navigation-api#31 and in particular the concern about previous non-interop with popstate, which we want to head off this time. Bug: 1183545 Change-Id: If16a61a8b0a8846d2bcdbb05b3b7230e0f842b3c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3533169 Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Auto-Submit: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/main@{#982939}
…vents on initial load, a=testonly Automatic update from web-platform-tests Navigation API: test that there are no events on initial load See WICG/navigation-api#31 and in particular the concern about previous non-interop with popstate, which we want to head off this time. Bug: 1183545 Change-Id: If16a61a8b0a8846d2bcdbb05b3b7230e0f842b3c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3533169 Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Auto-Submit: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/main@{#982939} -- wpt-commits: 49fcc31c450fc3dcb0d01061200a30ee37576459 wpt-pr: 33236
…vents on initial load, a=testonly Automatic update from web-platform-tests Navigation API: test that there are no events on initial load See WICG/navigation-api#31 and in particular the concern about previous non-interop with popstate, which we want to head off this time. Bug: 1183545 Change-Id: If16a61a8b0a8846d2bcdbb05b3b7230e0f842b3c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3533169 Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Auto-Submit: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/main@{#982939} -- wpt-commits: 49fcc31c450fc3dcb0d01061200a30ee37576459 wpt-pr: 33236
…vents on initial load, a=testonly Automatic update from web-platform-tests Navigation API: test that there are no events on initial load See WICG/navigation-api#31 and in particular the concern about previous non-interop with popstate, which we want to head off this time. Bug: 1183545 Change-Id: If16a61a8b0a8846d2bcdbb05b3b7230e0f842b3c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3533169 Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Auto-Submit: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/main@{#982939} -- wpt-commits: 49fcc31c450fc3dcb0d01061200a30ee37576459 wpt-pr: 33236
…vents on initial load, a=testonly Automatic update from web-platform-tests Navigation API: test that there are no events on initial load See WICG/navigation-api#31 and in particular the concern about previous non-interop with popstate, which we want to head off this time. Bug: 1183545 Change-Id: If16a61a8b0a8846d2bcdbb05b3b7230e0f842b3c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3533169 Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Auto-Submit: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/main@{#982939} -- wpt-commits: 49fcc31c450fc3dcb0d01061200a30ee37576459 wpt-pr: 33236
See WICG/navigation-api#31 and in particular the concern about previous non-interop with popstate, which we want to head off this time. Bug: 1183545 Change-Id: If16a61a8b0a8846d2bcdbb05b3b7230e0f842b3c Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3533169 Reviewed-by: Nate Chapin <japhet@chromium.org> Commit-Queue: Domenic Denicola <domenic@chromium.org> Auto-Submit: Domenic Denicola <domenic@chromium.org> Cr-Commit-Position: refs/heads/main@{#982939} NOKEYCHECK=True GitOrigin-RevId: ece85ebfd5d0f2ca9292def2018d8eae2fa3a984
On a cross-document navigation to a new page, we could fire one or more of:
window.navigation.currentEntry
firesnavigateto
window.navigation
firescurrententrychange
The timing would be debatable. After
DOMContentLoaded
? Afterpageshow
? Should it differ for restores-from-bfcache vs. fresh network navigations?Another data point is that
popstate
andhashchange
do not fire on page load. So, this would be a departure from those. I'm not sure what direction that indicates, though: have people been frustrated thatpopstate
doesn't fire on page load? Or would they be more frustrated if it did?The text was updated successfully, but these errors were encountered: