-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Defer pushState until navigation succeeds #4070
Conversation
🦋 Changeset detectedLatest commit: e28bc39 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
One unavoidable side-effect of this change: the |
documentation/docs/08-events.md
Outdated
@@ -2,10 +2,6 @@ | |||
title: Events | |||
--- | |||
|
|||
SvelteKit emits [CustomEvents](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) on the `window` object when certain things happen: | |||
SvelteKit emits a `sveltekit:start` [CustomEvents](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) on the `window` object once the app has hydrated. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be good to do client-side hooks so that we can get rid of this last custom event
I actually think that we can use page.url store(or some variable) and read from it for navigation purposes(for making relative URLs) inside of click event handler instead of doing this whole change. |
We can only manually resolve relative links in situations where the router handles the navigation. If a link has a |
@Conduitry I think you're somewhat right, we are listening to click event handler for window, so we can do the whole routing(event the "browser" part of it) internally, for ex. for rel=external do this, resolve the link with page store, and then do location.href = resolvedUrl; I don't think we have to follow other's rules, but changing this means changing behavior that every other framework defined. Like @Rich-Harris himself wrote in some previous discussion, Youtube, FB and others (and that means user expect it) are using this behavior and now we're changing it. |
Co-authored-by: Ignatius Bagus <[email protected]>
Co-authored-by: Ignatius Bagus <[email protected]>
It's not just links. If you happen to load an image during that limbo period, or do a By far the most widely used SSR framework that does client-side navigation is Next, and they also defer |
Okay, then this move makes sense. |
And I'm not sure about this, so I have to ask, If for ex. person redeploys Kit, and 500 error(missing module) occurs would this PR change URL, so the user can safely reload page? |
Yes, the URL will update when the navigation is settled, whether or not it's 'successful' |
This is a positive change imo—it's something I was wary since Sapper. I haven't had the time to properly review and test it just yet, but wouldn't this add to/replace history even when a navigation was aborted? Couldn't it also run the
While kit/packages/kit/src/runtime/client/router.js Lines 422 to 443 in 1db3a31
Granted, if this is actually what's happening, it'd have already been the case prior to this change, only with a slightly different outcome. |
I'm in favor of this change merely because of integration testing. I understand how things worked prior to this PR well enough to get our integration tests working, but I'm not sure our users could be expected to. Even if we provided the utilities and documentation, I still expect it would be an endless source of confusion |
good catch @mrkishi — adding a test and fixing that case |
Sounds like a breaking change that should be mentioned in the PR description along with the other breaking changes for people to find when they check the changelog and check for details in the PR how to migrate. |
good catch, added another changeset |
Just to add one more data point in favor of this change, I was recently helping a new developer with some end-to-end tests using Playwright. She was learning it by writing tests against the Playwright website. Their site has the behavior that Svelte used to have: the URL changes immediately, and then the content updates some milliseconds later. And her test, which was looking for the first That was very confusing for a new dev, so I'm glad that this decision was made. Because now sites using Svelte won't cause that kind of confusion to other new devs. |
@Rich-Harris In my application, I pass Maybe the new |
<svelte:window so this would no longer work? |
See #2870, and also #4056. This changes the order of operations when navigating: rather than immediately doing a
pushState
, so that the URL changes as soon as you click a link, it waits for navigation to happen first.This is arguably less good UX since it means a user may get no immediate feedback that navigation is occurring. But it more closely mirrors native browser behaviour, and fixes a couple of issues:
page.waitForNavigation()
as well aspage.click(...)
, but that is at least a normal thing people have to do with Playwright.)Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0