sveltejs / sveltejs/kit

Page variants selected based on `URLSearchParams` and/or cookies

Open
#6,312 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
20.8k
Forks
2.3k
Avg merge
1d 16h
Merged PRs (30d)
156

Description

Describe the problem

Currently, if any elements on the page depend on URLSearchParams and/or cookies, they must be rendered every time, with every request from the user.
Even though they sometimes differ in only a few small things, on an on/off basis.

Describe the proposed solution

It would be nice if it would be possible to enter in the route, for example in load, several variants of the same page, so that it would load already ready, and not rendered every time.

I don't have a ready idea how to write different variants.

But the readout (also not very well thought out) is probably the best:

  • in load read URLSearchParams and/or cookies,
  • use a function such as variant() and pass parameters/cookies to it,
  • if there are such parameters in the stored variants, that variant is returned.

Wise heads would surely find a better way, if they found it worth building into SvelteKit.

Alternatives considered
  • Only rendering with each request from the user.
  • Separate pathname for different variations of the same page.
  • Manual server configuration, which would have to be done outside of SvelteKit, bypassing SvelteKit.
  • Introduce a "CSS Cookies Media Query" - A non-existent query that would avoid blank page and blinking. (also standard for URLs, like @-moz-document url-prefix("https://github.com/"))
Importance

would make my life easier

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 SvelteKit route load handling for URLSearchParams and cookies, along with the current page rendering path. Clarify how stored page variants would be selected and what route-level API is expected. Done would mean a documented, tested way to serve the appropriate variant without rendering every request.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.