Skip to content

fix: stop deleting the root route $types.d.ts on every sync run - #17489

Open
CloudCorpRecords wants to merge 3 commits into
sveltejs:mainfrom
CloudCorpRecords:fix/root-types-sync-delete-17465
Open

CloudCorpRecords wants to merge 3 commits into
sveltejs:mainfrom
CloudCorpRecords:fix/root-types-sync-delete-17465

Conversation

@CloudCorpRecords

Copy link
Copy Markdown

Fixes #17465

Root cause

In write_all_types (packages/kit/src/core/sync/write_types/index.js), the set of directories whose files should be kept is built with path.posix.join(routes_dir, route.id). For the root route, route.id is '/', so the entry becomes e.g. src/routes/ with a trailing slash. The cleanup loop compares that against path.posix.dirname(file), which never produces a trailing slash (src/routes). The root route's $types.d.ts therefore never matched and was deleted as surplus on every sync run (then wastefully rewritten, since the empty output dir forced regeneration).

The fix strips the trailing slash when building the expected-directories set, so the comparison matches. No behavior change for any other route: only the root route id produces a trailing slash from path.posix.join.

Test evidence

New regression test Root route $types.d.ts is not deleted on subsequent sync runs in packages/kit/src/core/sync/write_types/index.spec.js: it builds a minimal project with a root route, runs write_all_types twice, and asserts the root $types.d.ts is never passed to rmSync on the second run.

  • Against unfixed code it fails with exactly the reported bug: root $types.d.ts was deleted on a second sync run (the rmSpy recorded .../types/src/routes/$types.d.ts).
  • Against the fix it passes.
  • Full spec file: 21/21 tests pass (pnpm vitest run src/core/sync/write_types/index.spec.js).

Honest limits

  • The repo's full pre-submission checklist (pnpm run format, lint, check, prepublishOnly) was not run here; the changeset (patch for @sveltejs/kit) follows the repo's convention. Happy to adjust if the checks surface anything.
  • The integration fixture loop in the spec file was not exercised beyond the unit suite (those tests passed as part of the 21).

Fixes sveltejs#17465. The expected_directories set was keyed with a
trailing slash for the root route (path.posix.join(routes_dir, '/')),
while path.posix.dirname never produces one, so the root $types.d.ts was
treated as surplus and deleted on every sync. Strip the trailing slash so
the comparison matches.

Adds a regression test that runs write_all_types twice and asserts the
root $types.d.ts is never passed to rmSync on the second run, plus a
changeset.

Signed-off-by: Rene Turcios <95189389+CloudCorpRecords@users.noreply.github.com>
@pkg-svelte-dev

pkg-svelte-dev Bot commented Oct 17, 2026 •

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from 3ccbd11:

pnpm add https://pkg.svelte.dev/@sveltejs/kit/c/3ccbd1155c9358a825ce8726306c0e0391cd743b

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

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 Oct 17, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 3ccbd11

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

Fixes the lint-all failure (oxfmt --check flagged the spec file).

Signed-off-by: Rene Turcios <95189389+CloudCorpRecords@users.noreply.github.com>
Fixes tsc-native check (TS7034/TS7005): the mock-recording array had an
implicit any[] type.

Signed-off-by: Rene Turcios <95189389+CloudCorpRecords@users.noreply.github.com>
@CloudCorpRecords
CloudCorpRecords force-pushed the fix/root-types-sync-delete-17465 branch from f9df57b to 3ccbd11 Compare October 18, 2026 18:38

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

1 participant