paoloricciuti / sveltekit-search-params

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

Optimistic store updates, update store before navigation happens. #45

Closed Hugos68 closed 9 months ago

Hugos68 commented 1 year ago

Describe the problem

When writing to a query param the store only updates once the navigation has finished, this can cause a non-instant change when using user input like a select. This feels janky and isn't good UX. This is especially noticable when load functions are doing work since navigation only resolves once the load function finishes.

Describe the proposed solution

I don't know if this is technically feasable within the library but my proposal is to optimistically update the store. So instead of just mutating the URL and letting the subscribe handle the updates you can optimistically set the store before the navigation even happens so the store is updated immediately. Downside would be that the update would cause subscribers to get notified 2 times. (Unless you can detect the value was updated optimistically and only update if the optimistic value doesn't match the actual URL value).

paoloricciuti commented 11 months ago

this should be fixed by #60 since the navigation only happens after the debounce but if you have an actual example i can try