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

page.url does not update when pushState is called #13569

Open
ottomated opened this issue Mar 11, 2025 · 3 comments
Open

page.url does not update when pushState is called #13569

ottomated opened this issue Mar 11, 2025 · 3 comments
Labels

Comments

@ottomated
Copy link
Contributor

Describe the bug

When calling pushState from $app/navigation, I expect page imported from $app/state to update its url. However, neither this url nor the one from $app/stores updates correctly.

Reproduction

https://stackblitz.com/edit/page-state-url-bug?file=src%2Froutes%2F%2Bpage.svelte

Logs

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @sveltejs/adapter-auto: ^4.0.0 => 4.0.0 
    @sveltejs/kit: ^2.16.0 => 2.19.0 
    @sveltejs/vite-plugin-svelte: ^5.0.0 => 5.0.3 
    svelte: ^5.0.0 => 5.22.6 
    vite: ^6.0.0 => 6.2.1

Severity

serious, but I can work around it

Additional Information

No response

@stefanVaporTrade
Copy link

I believe my issue is likely related to this. When I store any state using pushState or replaceState, and the user later navigates back to that page using history.back, the page store no longer has that state — it’s empty.

@hmnd
Copy link
Contributor

hmnd commented Apr 3, 2025

Apparently this is intentional, but it doesn't feel right... I think it's logical to expect page.url to always reflect the current url, whereas page.route et al make sense to keep as is, since we're likely shallow routing.

@hmnd
Copy link
Contributor

hmnd commented Apr 3, 2025

@Rich-Harris sorry for the ping, but given you were the original one to respond on this, I figured you could help. I think your decision may be worth reconsidering. Not updating page.url leads to more inconsistencies and unexpected behavior than doing so, in my experience (see also #10661).

In one case, for instance, I have a modal containing tabs. I want to store the state of these tabs in the url, so I have a ?mode={tab} searchparam. I would have expected the modal to be able to pickup the set searchparam using page.url, so that I can trigger different tabs to show on modal load, just by doing pushState. Instead I don't get anything and have to duplicate the effort by injecting the searchparam value from my modal's load function or similar.

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

No branches or pull requests

4 participants