sveltekit-search-params icon indicating copy to clipboard operation
sveltekit-search-params copied to clipboard

Updating to SvelteKit 2 leads to warning

Open myieye opened this issue 1 year ago • 8 comments

Describe the bug

We just updated from "@sveltejs/kit": "^1.24.1" to "@sveltejs/kit": "^2.5.0" and started getting the warning:

Avoid using history.pushState(...) and history.replaceState(...) as these will conflict with SvelteKit's router. Use the pushState and replaceState imports from $app/navigation instead.

Reproduction

This just happens every time we write to the query-params.

Logs

No response

myieye avatar Feb 01 '24 10:02 myieye

Which version of this library you are using?

paoloricciuti avatar Feb 01 '24 10:02 paoloricciuti

using "sveltekit-search-params": "2.1.0", I have also the same thing after removing all replaceState in my own code. I guess that it's coming from sveltekit-search-params

jycouet avatar Feb 19 '24 16:02 jycouet

using "sveltekit-search-params": "2.1.0", I have also the same thing after removing all replaceState in my own code. I guess that it's coming from sveltekit-search-params

If you try to search the codebase there's no instance of replaceState except for the option that i pass to goto but i explored sveltekit code and it's actually using history.replaceState under the hood.

Maybe i should use replaceState instead of passing the option to goto but that would introduce conflicts with previous versions of sveltekit

paoloricciuti avatar Feb 19 '24 17:02 paoloricciuti

I didn't look too much into it.

Would be great if sveltekit warning tells us from where it is 😁

jycouet avatar Feb 19 '24 18:02 jycouet

I just tryed to use replaceState if available...unfortunately it doesn't work because it doesn't propagate changes to the $page store which the library rely on.

paoloricciuti avatar Feb 20 '24 17:02 paoloricciuti

Thx for the test. That mean that you also have the warn in the console?

jycouet avatar Feb 20 '24 18:02 jycouet

Actually I didn't saw a warn in the console...but regardless there's nothing that I can do (except fixing upstream) on my side. :(

paoloricciuti avatar Feb 20 '24 19:02 paoloricciuti

Last kit version release note:

  • fix: prevent false positive history.pushState and history.replaceState warnings

I'll check that and let you know 👍

EDIT: it didn't change anything.

jycouet avatar Feb 28 '24 15:02 jycouet