Skip to content

fix: prevent dev server crash when route files are deleted - #16643

Merged
Rich-Harris merged 2 commits into
sveltejs:version-3from
bnn1:version-3
Aug 10, 2026
Merged

fix: prevent dev server crash when route files are deleted#16643
Rich-Harris merged 2 commits into
sveltejs:version-3from
bnn1:version-3

Conversation

@bnn1

@bnn1 bnn1 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

closes #16642

When route files are moved or deleted during development, the existing manifest can temporarily
reference a file that no longer exists. If this happens while SvelteKit is incrementally updating
page options or generated route types, an ENOENT error escapes the filesystem watcher and
terminates the dev server.

There are two reads affected by this race:

  • get_page_options reads route modules while refreshing their page options.
  • createProxy reads the same modules again while updating generated route types.

Commit 8af47eb06
deliberately moved the first read outside the static-analysis try block so incorrectly resolved
paths would remain visible instead of looking like unavailable static analysis. This change
preserves that behavior.

Instead of suppressing missing-file errors at either read site, sync.update now treats ENOENT as
an aborted incremental update and reports that a full manifest rebuild is required. The dev watcher
then schedules that rebuild. Persistent path-resolution and filesystem errors remain visible through
the existing full-rebuild error handling, while transient deletion and rename races no longer crash
the process.

The regression tests cover both possible missing-source reads. The type-generation case creates a
realistic pre-existing output directory and verifies that the aborted update does not write a
partial $types.d.ts file. A separate test confirms that get_page_options continues to throw for
missing files outside the incremental-update recovery path.

Tests

Focused regression tests:

Test Files  2 passed (2)
Tests       30 passed (30)

Additional validation:

  • pnpm -F @sveltejs/kit test:unit — 722 passed, 110 skipped
  • pnpm -F @sveltejs/kit check — passed
  • Prettier check for the changed files — passed
  • git diff --check — passed

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

The focused tests, the complete @sveltejs/kit unit suite, and the package type checks pass. The
repository-wide commands in the checklist have not all been run.

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpm changeset and following the prompts. Changesets that add features should be minor and those that fix bugs should be patch. Please prefix changeset messages with feat, fix, breaking, or chore.

Added a patch changeset for @sveltejs/kit.

Edits

  • Please ensure that 'Allow edits from maintainers' is checked. PRs without this option may be closed.

@pkg-svelte-dev

pkg-svelte-dev Bot commented Aug 4, 2026

Copy link
Copy Markdown

Install the latest version of @sveltejs/kit from d0e2a7d:

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

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

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 Aug 4, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: d0e2a7d

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

@Nic-Polumeyv

Copy link
Copy Markdown
Contributor

Same race can still crash one step later. sync.update continues into write_types, where createProxy does a bare fs.readFileSync on the same route files. Worth catching that too and returning a null proxy, update_types already handles that case.

@bnn1

bnn1 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author

After reviewing the commit that introduced this behavior I realized i've been too eager to fix this.

@Nic-Polumeyv I'm looking into it, thanks

@bnn1
bnn1 marked this pull request as draft August 6, 2026 06:32
@bnn1
bnn1 marked this pull request as ready for review August 6, 2026 06:32
@bnn1

bnn1 commented Aug 10, 2026

Copy link
Copy Markdown
Contributor Author

can someone advise if i should convert this to draft until it's reviewed to avoid running ci/cd when updating the branch with version-3 changes?

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

thank you!

@Rich-Harris
Rich-Harris merged commit 1e198bd into sveltejs:version-3 Aug 10, 2026
22 of 23 checks passed
teemingc added a commit that referenced this pull request Aug 11, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to version-3, this PR
will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`version-3` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `version-3`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @sveltejs/kit@3.0.0-next.19

### Major Changes

- breaking: move `defineParams` and associated types to
`@sveltejs/kit/params`
([#16716](#16716))

- breaking: run all errors through the `handleError` hook
([#16664](#16664))

- breaking: move `Page`, `ReadonlyURL` and `ReadonlyURLSearchParams`
from `@sveltejs/kit` to `$app/state`
([#16694](#16694))

- breaking: move `BeforeNavigate`, `OnNavigate`, `AfterNavigate`,
`Navigation`, `NavigationTarget`, `NavigationType`, `GotoOptions` and
the `Navigation*` variant types from `@sveltejs/kit` to
`$app/navigation` ([#16694](#16694))

- breaking: move `ActionResult` and `SubmitFunction` from
`@sveltejs/kit` to `$app/forms`
([#16694](#16694))

- breaking: remove `handleValidationError` and pass remote function
validation errors to `handleError` with `kind: 'validation'`
([#16672](#16672))

### Minor Changes

- feat: ignore files with + prefix if they contain test/spec/stories
([#16715](#16715))

### Patch Changes

- fix: rebuild the dev manifest when route files disappear during an
incremental update
([#16643](#16643))

- fix: externalize `@opentelemetry/api` to prevent bundler chunk
colocation between `instrumentation.server.js` and application code
([#16302](#16302))

- fix: surface prerender errors during development
([#16507](#16507))
## @sveltejs/adapter-node@6.0.0-next.9

### Patch Changes

- fix: externalize `@opentelemetry/api` to prevent bundler chunk
colocation between `instrumentation.server.js` and application code
([#16302](#16302))
- Updated dependencies
[[`04f9ab4`](04f9ab4),
[`1e198bd`](1e198bd),
[`813726d`](813726d),
[`a115a7b`](a115a7b),
[`031ac69`](031ac69),
[`dc7442c`](dc7442c),
[`19c4478`](19c4478),
[`dc7442c`](dc7442c),
[`dc7442c`](dc7442c),
[`0b3e2b3`](0b3e2b3)]:
  - @sveltejs/kit@3.0.0-next.19

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Tee Ming <chewteeming01@gmail.com>
teemingc pushed a commit that referenced this pull request Aug 11, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to version-3, this PR
will be updated.

⚠️⚠️⚠️⚠️⚠️⚠️

`version-3` is currently in **pre mode** so this branch has prereleases
rather than normal releases. If you want to exit prereleases, run
`changeset pre exit` on `version-3`.

⚠️⚠️⚠️⚠️⚠️⚠️

# Releases
## @sveltejs/kit@3.0.0-next.19

### Major Changes

- breaking: move `defineParams` and associated types to
`@sveltejs/kit/params`
([#16716](#16716))

- breaking: run all errors through the `handleError` hook
([#16664](#16664))

- breaking: move `Page`, `ReadonlyURL` and `ReadonlyURLSearchParams`
from `@sveltejs/kit` to `$app/state`
([#16694](#16694))

- breaking: move `BeforeNavigate`, `OnNavigate`, `AfterNavigate`,
`Navigation`, `NavigationTarget`, `NavigationType`, `GotoOptions` and
the `Navigation*` variant types from `@sveltejs/kit` to
`$app/navigation` ([#16694](#16694))

- breaking: move `ActionResult` and `SubmitFunction` from
`@sveltejs/kit` to `$app/forms`
([#16694](#16694))

- breaking: remove `handleValidationError` and pass remote function
validation errors to `handleError` with `kind: 'validation'`
([#16672](#16672))

### Minor Changes

- feat: ignore files with + prefix if they contain test/spec/stories
([#16715](#16715))

### Patch Changes

- fix: rebuild the dev manifest when route files disappear during an
incremental update
([#16643](#16643))

- fix: externalize `@opentelemetry/api` to prevent bundler chunk
colocation between `instrumentation.server.js` and application code
([#16302](#16302))

- fix: surface prerender errors during development
([#16507](#16507))

- fix: adjust error overload for optional `App.Error` parameters
([#16725](#16725))
## @sveltejs/adapter-node@6.0.0-next.9

### Patch Changes

- fix: externalize `@opentelemetry/api` to prevent bundler chunk
colocation between `instrumentation.server.js` and application code
([#16302](#16302))
- Updated dependencies
[[`04f9ab4`](04f9ab4),
[`1e198bd`](1e198bd),
[`813726d`](813726d),
[`a115a7b`](a115a7b),
[`031ac69`](031ac69),
[`dc7442c`](dc7442c),
[`19c4478`](19c4478),
[`dc7442c`](dc7442c),
[`dc7442c`](dc7442c),
[`0b3e2b3`](0b3e2b3),
[`c5d0ce2`](c5d0ce2)]:
  - @sveltejs/kit@3.0.0-next.19

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

Dev server sometimes crashes when route files are moved or deleted

3 participants