Skip to content

fix: reload the browser when the server entry or middleware changes in dev - #2255

Closed
birkskyum wants to merge 1 commit into
solidjs:mainfrom
birkskyum:fix-entry-server-hmr-issue
Closed

fix: reload the browser when the server entry or middleware changes in dev#2255
birkskyum wants to merge 1 commit into
solidjs:mainfrom
birkskyum:fix-entry-server-hmr-issue

Conversation

@birkskyum

@birkskyum birkskyum commented Jul 27, 2026

Copy link
Copy Markdown
Member

Problem

entry-server.tsx and the configured middleware are server-only, so they have no module in the client graph and Vite has nothing to send the browser when they change. The dev server re-imports the server entry per request, so the edit is live on the next request, but the open page keeps showing the shell rendered from the previous version until you refresh by hand. Reproduced on the current RC: editing src/entry-server.tsx in apps/fixtures/bare produces zero messages on the client HMR socket.

Fix

Adds a serverOnlyReload() plugin to devServer(). On hotUpdate for the ssr environment, if the changed file is the resolved server entry or the configured middleware, it sends a full-reload on the client hot channel (debounced so one save touching both only reloads once). Both paths are resolved through the ssr environment's plugin container, so an extensionless or aliased middleware path still matches.

Only those two entries are handled: modules that also exist on the client (routes, components, server functions) are left to Vite, since reloading on top of a client HMR update would needlessly throw away the page's state. This is also why the check is not the broader "file has no module in the client graph" rule, which would reload and reset the current page whenever you edit a lazy route you have not navigated to yet.

Verification

Browser check on apps/fixtures/bare: before the change the page never updates and needs a manual refresh; after it, the edit appears on its own and the hydrated counter resets, confirming a real reload. An HMR socket probe shows exactly one full-reload for entry-server.tsx and for middleware.ts (in apps/fixtures/experiments), while editing src/app.tsx stays silent as before. New unit tests cover both entries plus the cases that must stay silent. tsc --noEmit, vitest run (77 passed), oxfmt --check, and the apps/tests Playwright suite (35 passed) are green.

@changeset-bot

changeset-bot Bot commented Jul 27, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 299566c

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

@netlify

netlify Bot commented Jul 27, 2026

Copy link
Copy Markdown

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

Name Link
🔨 Latest commit 299566c
🔍 Latest deploy log https://app.netlify.com/projects/solid-start-landing-page/deploys/6a66a54b809f6e000889afa4
😎 Deploy Preview https://deploy-preview-2255--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.

@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@2255

commit: 299566c

export function devServer(serverEntryPath: string): Array<PluginOption> {
export function devServer(serverEntryPath: string, middlewarePath?: string): Array<PluginOption> {
return [
serverOnlyReload(serverEntryPath, middlewarePath),

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.

probably good if someone else reviews this but overall looks good

@lxsmnsyc

Copy link
Copy Markdown
Member

Doesn't the refresh reload pragma work

@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.

[Feature]: HMR for entry-server.tsx

3 participants