You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since your project is AMAZING, I was wondering what do you think about creating a "kit for Kit" with Svelte 5 that allows us to save in the page URL any POJO object or scalar type we need with the serializer we need (for example I can use JSON.stringify() and JSON.parse() for now).
This would be amazing for lists filters for example:
I have a players list on page /players
I order the list by created_at DESC
the kit saves this filter in the URL: /players?order_by=created_at_DESC (just an example)
I filter players form team_id: 123
the kit saves this new filter in the URL: /players?order_by=created_at_DESC&team_id=123 (just an example)
I go back with the browser and the URL is now again: /players?order_by=created_at_DESC (just an example)
I reload the page now and since the URL is this the list is ordered like before the reload
I hope you get the idea.
I now can manually add this using in each place I need it url.searchParams.set and afterNavigate but I would like to have an helper to be used everywhere.
If I'm understanding correctly, It sounds like what you are looking for is query string management with different strategies. Svelte UX has queryParamsStore (manage multiple params) as well as queryParamStore (single param) with different types/strategies. There is a pretty robust test suite and docs to see the differences, but maybe I'm misunderstanding what you are looking for.
Thanks for the added context and discussion. If i understand the problem you want:
Fine-grained reactivity (for each param) with the ability to bind each parameters, including nested properties (ex. condition.name or pagination.page
You want to set an initial default value (constant) or default to a props value, but will be overridden by the query param value when set, but used anytime it is not defined in the query string.
You MIGHT be able to use queryParamStore for each parameter (and thus a store for each) instead of managing all params with a single queryParamsStore.
I haven't tried testing this and rather buried with other tasks ATM. I plan to migrate all Svelte UX stores to Svelte 5 with runes but it will take some time.
I'm shocked that I haven't found anything similar to what I need anywhere on the web and yet it's something that should be very useful to a lot of people!
I think rolling something custom like you have in sveltejs/kit#12460 is your best choice right now.
Svelte UX's plan for Svelte 5 is to get it compatible with Svelte 3-5 which is helping to tease out some Svelte 5 regressions. I'm fairly close on getting the full docs running on Svelte 5 (it does locally, but currently fails some svelte-check and I had to remove sveld generated API docs until I find a solution). I think the root issue is the AST changing. I'm considering parsing the AST myself, but just haven't found the bandwidth. There are some additional regressions I've seen while using the docs locally I need to identify a small reproduction and report as well. Migrating the LayerChart docs to Svelte 5 is also a priority.
I already have Github Analysis and Strava Analysis running on Svelte 5, but know there is at least an issue with DateRangeField in some cases I need to investigate / report.
LayerChart's simplified charts is my current priority when I have time for open source, which ebbs and flows.
Activity
techniq commentedon Jul 9, 2024
Thanks for the kinds words @frederikhors 😊.
If I'm understanding correctly, It sounds like what you are looking for is query string management with different strategies. Svelte UX has queryParamsStore (manage multiple params) as well as queryParamStore (single param) with different types/strategies. There is a pretty robust test suite and docs to see the differences, but maybe I'm misunderstanding what you are looking for.
@paoloricciuti also has the wonderful https://github.com/paoloricciuti/sveltekit-search-params which I haven't looked closely at yet, but I think it's similar and likely has better SvelteKit integration (I created
queryParamsStorefor SPAs before SvelteKit existed)frederikhors commentedon Jul 10, 2024
Thanks for your answer.
I tried
queryParamsStoreand it works good (thanks again for your work!) but does not all I need.I created a small reproduction: see the file
/svelte-ux/+page.svelte:since I'm using new Svelte 5's
$props()I'm assigning:and obviously if I assign something to
condition.name = "bob"it doesn't workI cannot assign to
$filters.conditionneitherThe same goes with
searchText(simple string): if I assign it as default props value and I bind it with an input it doesn't workThese are very useful features especially with Svelte 5.
I'm already talking with @paoloricciuti here about this.
techniq commentedon Jul 10, 2024
Thanks for the added context and discussion. If i understand the problem you want:
condition.nameorpagination.pageYou MIGHT be able to use
queryParamStorefor each parameter (and thus a store for each) instead of managing all params with a singlequeryParamsStore.I haven't tried testing this and rather buried with other tasks ATM. I plan to migrate all Svelte UX stores to Svelte 5 with runes but it will take some time.
techniq commentedon Jul 10, 2024
I did try to update your SvelteLab example with the following...
but it didn't work
[-]Just an idea[/-][+][queryParamsStore] enhancements[/+]frederikhors commentedon Jul 10, 2024
I will try in a moment. I think
pushState()has a bug and needssetTimeoutfor now.But in the meantime, I opened sveltejs/kit#12460 right now.
That code works (not so performant or good) but is very repetitive, but it's a start for me.
Do you think the code you posted can do the same?
techniq commentedon Jul 10, 2024
TBH I'm not sure.
queryParamStoredoes not use Svelte 5$effectand just callsgotofrom$app/navigationbased onstore.setbeing called.frederikhors commentedon Jul 10, 2024
I updated https://www.sveltelab.dev/4vnxej0ewwtlwe9?files=.%2Fsrc%2Froutes%2Fsvelte-ux%2F%2Bpage.svelte.
Condition is not persisted in the URL at all.
😢
techniq commentedon Jul 10, 2024
Look in your console 😉. This was the error I was referring to.
frederikhors commentedon Jul 10, 2024
You're right. I don't know what to do.
I'm shocked that I haven't found anything similar to what I need anywhere on the web and yet it's something that should be very useful to a lot of people!
techniq commentedon Jul 10, 2024
I think rolling something custom like you have in sveltejs/kit#12460 is your best choice right now.
Svelte UX's plan for Svelte 5 is to get it compatible with Svelte 3-5 which is helping to tease out some Svelte 5 regressions. I'm fairly close on getting the full docs running on Svelte 5 (it does locally, but currently fails some
svelte-checkand I had to removesveldgenerated API docs until I find a solution). I think the root issue is the AST changing. I'm considering parsing the AST myself, but just haven't found the bandwidth. There are some additional regressions I've seen while using the docs locally I need to identify a small reproduction and report as well. Migrating the LayerChart docs to Svelte 5 is also a priority.I already have Github Analysis and Strava Analysis running on Svelte 5, but know there is at least an issue with DateRangeField in some cases I need to investigate / report.
LayerChart's simplified charts is my current priority when I have time for open source, which ebbs and flows.