Skip to content

fix: Define hashed __VITE_PRELOAD__ markers when prerendering (Vite 8.4+) - #44

Closed
JoviDeCroock wants to merge 1 commit into
masterfrom
fix/vite-8.4-preload-marker
Closed

JoviDeCroock wants to merge 1 commit into
masterfrom
fix/vite-8.4-preload-marker

Conversation

@JoviDeCroock

@JoviDeCroock JoviDeCroock commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Vite 8.4.0 changed the dynamic-import preload marker from __VITE_PRELOAD__ to __VITE_PRELOAD__<32-hex hash> (see preloadMarkerRE in Vite's importAnalysisBuild). The marker is still in the chunk code when this plugin's generateBundle imports the bundle in Node. We only define globalThis.__VITE_PRELOAD__, so any dynamic import that runs during prerender throws:

ReferenceError: __VITE_PRELOAD__51cb51c33a0121b47e5bb9d47c2613b1 is not defined
> node_modules/preact-iso/src/index.js:6:69

That covers preact-iso's own prerender(), which does import('./prerender.js'), so the unmodified create-preact prerender + router template fails to build on vite@8.4.x. It builds on vite@8.3.1.

Fix: while writing chunks to the temp dir, define every hashed marker found in the chunk code as [], the same as the existing __VITE_PRELOAD__ shim. The code isn't rewritten, so source-map error positions stay correct.

This bug was found and fixed with AI assistance (Claude Code), while auditing the Preact 11 docs for AI coding agents.

Vite 8.4.0 can suffix the preload marker with a hash
(`__VITE_PRELOAD__<hash>`). The marker is still present in chunks during
`generateBundle`, so prerendering any dynamic import threw a ReferenceError.

Found and fixed with AI assistance (Claude Code).

Co-Authored-By: Claude <noreply@anthropic.com>
@rschristian

Copy link
Copy Markdown
Member

I'm not sure a single word of that description was written by you; you have a really prominent voice when you actually write yourself (which is good!) and this just ain't it. I shouldn't have to point at the CoC, but...

Write issues, pull request descriptions, and comments in your own words.

Code of Conduct


If you want to drop the AI and then suggest a change, I'm open, but I'm going to keep ownership over this repo and something like this:

This bug was found and fixed with AI assistance (Claude Code), while auditing the Preact 11 docs for AI coding agents.

will be an insta-close going forward. I'll update the policy for this repo when I can. Equally, it can be moved back to my name as well.

@rschristian rschristian closed this Dec 3, 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.

2 participants