Skip to content

feat(start): reload the page once when a chunk fails to load - #465

Open
lxsmnsyc wants to merge 1 commit into
nextfrom
feat/reload-on-chunk-error
Open

lxsmnsyc wants to merge 1 commit into
nextfrom
feat/reload-on-chunk-error

Conversation

@lxsmnsyc

Copy link
Copy Markdown
Member

Adds start.reloadOnChunkError, on by default. In a production build, the generated client entry reloads the page once when a code-split chunk fails to load, as it does when a deploy replaced the chunk while the page was open. It is the counterpart of SolidStart's reloadOnRouteChunkError.

Changes

  • The generated client entry listens for Vite's vite:preloadError event. Vite fires it when a dynamic import or one of its preloaded files fails.
  • A second failure within 10 seconds of the reload does not reload again, so a chunk that is still missing shows the normal error instead of reloading in a loop. The last reload time is kept in sessionStorage. Without storage the page never reloads. This matches SolidStart's guard.
  • A listener that calls event.preventDefault() skips the reload. The listener is added in the entry body, so one from start.clientSetup runs first.
  • The listener never calls preventDefault() itself, so the failed import still rejects and the app's own error handling runs.
  • It applies to production builds with a generated client entry, in both start modes. Dev output and authored entries are unchanged.
  • README: a new reloadOnChunkError section. The clientSetup example no longer shows a hand-written reload listener.

Difference from SolidStart

SolidStart wraps each route's import and returns an empty component, so the router finishes the navigation and the page reloads at the destination URL. The plugin has no router, so it listens for the global event instead. The page reloads at the current URL.

Testing

  • New chunk-reload mode in examples/start-ssr/test/run.mjs, 9 assertions. It builds the app, opens it in headless Chrome, deletes the chunk a button loads, and checks:
    • the first failure reloads the page and stamps sessionStorage,
    • a second failure within the window rejects without reloading,
    • with the chunk back, the import works and nothing reloads,
    • with reloadOnChunkError: false, no chunk carries the listener and a failure does not reload,
    • the dev client entry has no listener.
  • The prod (77) and client-setup (20) modes of examples/start-ssr and the examples/start-client suite (70) still pass.
  • vitest run passes.

The test app awaits the import instead of chaining .then(onLoad, onError). Vite wraps a chained .then() in its preload helper too, so that rejection handler would catch the error before the event fires. lazy(() => import(...)) is not affected.

🤖 Generated with Claude Code

- New start.reloadOnChunkError option, on by default.
- The generated client entry of a production build listens for Vite's
  vite:preloadError event and reloads the page, as SolidStart's
  reloadOnRouteChunkError does.
- A second failure within 10 seconds does not reload again. The last
  reload time is kept in sessionStorage.
- A listener that calls preventDefault() skips the reload.
- New chunk-reload mode in the start-ssr e2e suite.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@changeset-bot

changeset-bot Bot commented Oct 24, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 228106e

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

This PR includes changesets to release 1 package
Name Type
@solidjs/vite-plugin 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 Oct 24, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@solidjs/vite-plugin@465

commit: 228106e

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.

2 participants