sveltejs / sveltejs/kit

Add a hook that runs on only the server or only the client like "asyncdata" hook in Nuxt

Open
#12,993 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

Ensures logs are written on only the server or only the client.

Describe the proposed solution

If a person goes to https://abc.def. Code in this new hook would be executed on only the server and the html passed to the client.
If the person uses an anchor tag to navigate to https://abc.def/a. Code in the new hook would be executed on only the client to get data and then navigate to the next page.

Code currently written in +page.ts runs on both the server and client side. It's only the "fetch" requests that only run server side. All other code will occur on the server and the client. The good news about +page.ts is that all subsequent navigations cause the code to only occur on the client side

Alternatives considered

No response

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 reading the existing +page.ts behavior and its fetch handling, focusing on the difference between an initial direct visit and anchor-based navigation. Define how a new hook would distinguish server-only and client-only execution, then verify that the proposed behavior holds for both navigation paths.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.