Add a hook that runs on only the server or only the client like "asyncdata" hook in Nuxt
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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