Skip to content
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

Router changes the URL prematurely #2870

Closed
ebeloded opened this issue Nov 23, 2021 · 6 comments
Closed

Router changes the URL prematurely #2870

ebeloded opened this issue Nov 23, 2021 · 6 comments
Labels

Comments

@ebeloded
Copy link

ebeloded commented Nov 23, 2021

Describe the bug

When using links within the SvelteKit app, the URL gets updated immediately, even though the underlying page is still loading. In this simple demonstration the second-page loads for 1s, but the URL is updated a immediately:

CleanShot 2021-11-23 at 14 09 45

This is unconventional and results in asynchrony between the URL and the page content.

For contrast, here is what happens when clicking on the second link with rel="external", which triggers normal browser behavior:

CleanShot 2021-11-23 at 14 10 35

Here you can see that both the URL and the page change at the same time. The page represents the URL at every moment. This behavior and universal across browsers.

SvelteKit mimicks browser behavior with History API. To do it correctly, the URL needs to be changed after the page is loaded.

Reproduction

Stackblitz
Source Code

Logs

No response

System Info

-

Severity

annoyance

Additional Information

No response

@harshmandan
Copy link

harshmandan commented Nov 23, 2021

Can confirm it happens with me as well.
Edit: For some reason the URL does not change in stackBlitz but it does when visited the URL directly.
Edit 2: You need to open stackBlitz first, then copy and paste URL to open in a new tab.

@Rich-Harris
Copy link
Member

Explanation of why the current behaviour is intentional: #2917 (comment)

@ebeloded
Copy link
Author

Given the split in opinions regarding the URL change behavior, could this be added as a configuration option?

@rmunn
Copy link
Contributor

rmunn commented Dec 1, 2021

Explanation of why the current behaviour is intentional: #2917 (comment)

But since the browser's built-in behavior is the opposite (see second GIF in #2870 (comment)), IMHO it should be the other way around, with the URL not updating until after load() completes. There's also the fact that the current behavior is causing #2945, and may be causing other issues as well.

@benmccann
Copy link
Member

I wonder, if we did want to mirror the browser behavior, if the most analogous place to update the url would be in between the network fetch and dom rendering, which I think would be here:

for (let i = 0; i < filtered.length; i += 1) {

@Rich-Harris
Copy link
Member

Did a reverse ferret on this — pushState is now deferred until navigation completes: #4070

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants