Skip to content

Router changes the URL prematurely #2870

Closed
@ebeloded

Description

@ebeloded

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions