Skip to content

fix: recover from SSR errors in dev without a manual refresh#2256

Closed
birkskyum wants to merge 2 commits into
solidjs:mainfrom
birkskyum:tsx-syntax-error-recovery
Closed

fix: recover from SSR errors in dev without a manual refresh#2256
birkskyum wants to merge 2 commits into
solidjs:mainfrom
birkskyum:tsx-syntax-error-recovery

Conversation

@birkskyum

@birkskyum birkskyum commented Jul 27, 2026

Copy link
Copy Markdown
Member

Problem

A syntax error in app.tsx leaves a 500 page that never recovers: fixing the file does nothing until you refresh by hand.

The ErrorOverlay branch in dev-server.ts looks like it covers this, but it is unreachable in a standard v2 app. configureServer bails out early when the server environment has dispatchFetch, and Nitro implements exactly that, so Nitro renders its own error page with no /@vite/client on it. None of that page's modules are registered for HMR, so the update that fixes the file is dropped, and Vite's client only self-reloads when the page has a vite-error-overlay mounted or receives a full-reload.

Fix

A dev middleware buffers HTML 5xx responses and appends a script that connects them to the HMR channel and reloads once the server renders again. Anything that is not an HTML 5xx passes through untouched, as do pages that already talk to the HMR client.

Two details worth calling out:

  • Status and content type arrive as writeHead arguments rather than on res, and Nitro passes headers as a flat [name, value, ...] array. Reading only res.statusCode never detects the error, and leaving content-length in the array form truncates the body.
  • Reloading on the HMR update alone is racy: Vite broadcasts it before the server environment picks the change up, so the reload re-renders the same 500. The script polls with backoff until the server returns non-5xx. Polling only starts on an HMR event, so an idle error page does not spam the terminal with error traces.

Testing

15 unit tests over injection, both writeHead header forms, and the middleware's buffering and pass-through paths. Verified the reporter's repro in Chromium: break app.tsx, fix it, page recovers on its own in ~0.5s. Units, typecheck, both e2e suites, and format:check pass.

@netlify

netlify Bot commented Jul 27, 2026

Copy link
Copy Markdown

Deploy Preview for solid-start-landing-page ready!

Name Link
🔨 Latest commit cea0314
🔍 Latest deploy log https://app.netlify.com/projects/solid-start-landing-page/deploys/6a66a8fa5948a8000891cb07
😎 Deploy Preview https://deploy-preview-2256--solid-start-landing-page.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cea0314

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

This PR includes changesets to release 1 package
Name Type
@solidjs/start 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

@pkg-pr-new

pkg-pr-new Bot commented Jul 27, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@solidjs/start@2256

commit: cea0314

@birkskyum
birkskyum marked this pull request as draft July 27, 2026 00:33
@birkskyum birkskyum closed this Jul 27, 2026
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.

[Bug?]: syntax errors in ./app.tsx causes uncaught 500 error

1 participant