sveltejs / sveltejs/kit

Reactive writable URL Search Params with Svelte 5 runes

Open
#13,746 16 comments 44 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #16031 by @Nic-Polumeyv — closed without merging
needs-decision svelte 5
Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

Storing state in the URL is a common practice and a recommended approach for state management in SvelteKit. Adding a way to easily change the search parameters of the current URL was previously discussed in issue #969, but this discussion predates the introduction of Svelte 5 runes.

With runes, keeping $state variables reliably synchronized with URL search parameters is challenging. page.url.searchParams can be used to read search params state, but not to write it, so we have to ressort on a sophisticated logic with $effect, snapshot, etc.

While community packages like sveltekit-search-params exist to address this pattern, the most popular one is not yet based on runes (see paoloricciuti/sveltekit-search-params#80 and relies on the deprecated $page store. I don't know any popular library that solve this issue the latest rune based APIs

I think SvelteKit should provided a built-in, rune-native, and documented way o manage this synchronization.

Describe the proposed solution

Integrate something like https://gist.github.com/PuruVJ/ed0abefbf512ff2aaa5dbbd377c50f5a by @PuruVJ into the framework.

Alternatives considered

No new api, but a new documentation page about how to read-write state in the URL.

Importance

nice to have

Additional Information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing issue #969, the linked gist, and closed pull request #16031 to understand prior discussion and attempted direction. Done means maintainers have settled whether a rune-native built-in API or documentation-only solution is wanted and have specified its behavior and scope.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.