Skip to content

[codex] Avoid state updates in preload tutorial effect#1977

Open
Sean-Kenneth-Doherty wants to merge 1 commit into
sveltejs:mainfrom
Sean-Kenneth-Doherty:codex/preload-tutorial-navigation-hooks
Open

[codex] Avoid state updates in preload tutorial effect#1977
Sean-Kenneth-Doherty wants to merge 1 commit into
sveltejs:mainfrom
Sean-Kenneth-Doherty:codex/preload-tutorial-navigation-hooks

Conversation

@Sean-Kenneth-Doherty
Copy link
Copy Markdown

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty commented May 17, 2026

Description of Problem

The preloading tutorial measures navigation timing by updating $state inside a $effect. Svelte guidance recommends avoiding state synchronization inside effects, and issue #1366 tracks this tutorial as an example that should be updated.

Closes #1366.

Proposed Solution

Use SvelteKit navigation lifecycle callbacks instead:

  • beforeNavigate captures the navigation and start time
  • afterNavigate records the completed duration

This keeps the visible tutorial behavior while moving state updates out of $effect.

Additional Information

Validation:

  • SHARP_IGNORE_GLOBAL_LIBVIPS=1 mise exec node@24.15.0 -- pnpm install --frozen-lockfile
  • mise exec node@24.15.0 -- pnpm prettier --write apps/svelte.dev/content/tutorial/04-advanced-sveltekit/03-link-options/01-preload/+assets/app-a/src/routes/+layout.svelte apps/svelte.dev/content/tutorial/04-advanced-sveltekit/03-link-options/01-preload/+assets/app-b/src/routes/+layout.svelte
  • mise exec node@24.15.0 -- pnpm -r package
  • mise exec node@24.15.0 -- pnpm --filter svelte.dev lint
  • mise exec node@24.15.0 -- pnpm --filter svelte.dev check
  • Direct Svelte compiler pass over both changed tutorial layout files
  • git diff --check

Current GitHub check note: the only red status is Vercel authorization for the Svelte team account, not a test failure.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 17, 2026

@Sean-Kenneth-Doherty is attempting to deploy a commit to the Svelte Team on Vercel.

A member of the Team first needs to authorize it.

@Sean-Kenneth-Doherty Sean-Kenneth-Doherty marked this pull request as ready for review May 17, 2026 06:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid setting state in an effect in tutorial

1 participant