Skip to content

fix: avoid deleting root route types and metadata cache during sync cleanup - #17591

Open
praveen-kumary wants to merge 1 commit into
sveltejs:mainfrom
praveen-kumary:fix/sync-root-route-types-deletion-17465
Open

praveen-kumary wants to merge 1 commit into
sveltejs:mainfrom
praveen-kumary:fix/sync-root-route-types-deletion-17465

Conversation

@praveen-kumary

Copy link
Copy Markdown
Contributor

Summary

Fixes #17465 and fixes #17464.

During write_all_types, the obsolete route cleanup pass previously deleted:

  1. .svelte-kit/types/src/routes/$types.d.ts: For the root route (route.id === '/'), path.posix.join(routes_dir, route.id) produces 'src/routes/' (with a trailing slash), whereas path.posix.dirname(file) returns 'src/routes'. Because 'src/routes' was missing from expected_directories, the root route types were deleted on every sync pass.
  2. route_meta_data.json: walk(types_dir) yields route_meta_data.json, whose dirname is '.'. Because '.' is not a route directory, the metadata cache file was deleted on line 74 immediately before fs.existsSync(meta_data_file) was called on line 84, defeating the sync cache across runs.

Changes

  • Normalize trailing slashes when building expected_directories in packages/kit/src/core/sync/write_types/index.js.
  • Skip route_meta_data.json during the obsolete-route cleanup loop.
  • Added regression test verifying root route $types.d.ts and route_meta_data.json retention across repeated sync runs.
  • Added changeset.

…leanup (sveltejs#17465)

Signed-off-by: praveen-kumary <praveenkumar2000y@gmail.com>
@pkg-svelte-dev

pkg-svelte-dev Bot commented Nov 1, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 2902dcb:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/2902dcbf41ec7db7ffe8943092f8556332fe757d

Open in pkg.svelte.dev: https://pkg.svelte.dev/repos/kit/pr/17591

Note

This PR is from a fork. A maintainer must approve approve each commit before it can be built and installed.

@changeset-bot

changeset-bot Bot commented Nov 1, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 2902dcb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR


if (fs.existsSync(types_dir)) {
for (const file of walk(types_dir)) {
if (file === 'route_meta_data.json') continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preserving the metadata cache causes subsequent syncs to leave layout route IDs and params stale when child pages are added or deleted without changing load files.

Fix on Vercel


if (fs.existsSync(types_dir)) {
for (const file of walk(types_dir)) {
if (file === 'route_meta_data.json') continue;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With metadata now retained, moving a component-only route directory via files.routes leaves its generated $types.d.ts missing after sync.

Fix on Vercel

This branch has not been deployed

No deployments
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.

Root route $types.d.ts is deleted on every sync run svelte-kit sync cache doesn't work

1 participant