sveltejs / sveltejs/kit

Mark code to only run in `load` during an actual navigation

Open
#13,112 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Describe the problem

Is there a possibility mark a piece of code as only runnable when an actual navigation has occurred in a load?

export const load = async function ({ route }) {
	/**
	* Some other code fetching data that will be shown when entering the page
	*/

	// This will now run on pre-load since it references route.id, so there's no guarantee that the user visited the page if pre-load was on hover
	track('visited page', {
		route: route.id // Tracking that a page was visited
	})
};
Describe the proposed solution

A way to mark a piece of code as only runnable when the actual navigation has been performed

Alternatives considered

Moving it into the +page.svelte file, but it can quickly clutter up the +page.svelte file if there's a lot of things you just want to run during a navigation.

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 the load lifecycle described in the issue, especially how route.id causes code to run during pre-load. Compare that behavior with the proposed +page.svelte alternative and identify the navigation signal or API needed. Done means a documented, agreed way to run selected load-related code only after actual navigation.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
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.