paoloricciuti / sveltekit-search-params

The easiest way to read and WRITE from query parameters in sveltekit.
https://sveltekit-search-params.netlify.app
MIT License
497 stars 15 forks source link

[Bug] queryParam store not updating the url when url.searchParams is used in server.ts #12

Closed hazre closed 1 year ago

hazre commented 1 year ago

I've encountered a weird behavior where if im getting any data from the url params on the server, I can't update it at all on the page.

Once I remove the url.searchParams.get() methods, it starts working again, it's very odd..

here's a reproduction https://stackblitz.com/edit/sveltejs-kit-template-default-zzzvcz

stackblitz[bot] commented 1 year ago

Fix this issue in StackBlitz Codeflow Start a new pull request in StackBlitz Codeflow.

paoloricciuti commented 1 year ago

Thanks for reporting this...in 1.0 there were 2 goto...one for the actual update of the url and one just to add the history entry. Apparently this was messing things up when the url object was accessed in the server 🤷

I fixed it in 1.0.1, let me know if the issue is solved otherwise i'll reopen this issue.

paoloricciuti commented 1 year ago

I've published the package but it still doesn't fix the issue...i was having some problem with stackblitz and i tought i fixed it....reopening this now, i'll work on this later.

hazre commented 1 year ago

I just tested it in my local environment and still no luck on v1.0.2

paoloricciuti commented 1 year ago

Yes unfortunately I was having some issues on stackblitz and that made me think I fixed the issue but it is still there. Btw if you don't care about history entries you can disable history and that will fix this issue for the moment. I'll try to fix this tomorrow.

paoloricciuti commented 1 year ago

Ok third time the charm...this should be fixed on 1.0.3. I've verified on your repro and seem to be ok.

Closing this and hopefully i don't need to reopen it. Let me know if it's ok on your part (also i've opened an issue on the sveltekit repo)

hazre commented 1 year ago

I just tried it in my local environment and it works perfectly now. Thanks for the quick fix 😁

paoloricciuti commented 1 year ago

This is kinda of a work around and hopefully it will be fixed on the sveltekit side. Glad to help and thank to you for reporting.

pke commented 1 year ago

I think I have encountered the same problem. I had a call to URLSearchParams of $page in my code and the URL updating did not work. When I removed that call it started to work. What is the reason for this?

pke commented 1 year ago

I still can't get it to work, to calculate a reactive value based on the query param:

const length = queryParam("length", ssp.number(12));
$: (result = calc({ length: $length});

Here, as soon as I add the calculation, the URL stops updating and the result stays empty.

paoloricciuti commented 1 year ago

Would you please open a new issue and provide a minimal reproduction? Thanks ;)