fix: inject client entry on islands-free pages for HMR (#3810)

Fixes denoland/fresh#3806

---------

Co-authored-by: fibibot <fibibot@users.noreply.github.com>
Co-authored-by: Bartek Iwańczuk <biwanczuk@gmail.com>
This commit is contained in:
Fibi
2026-05-27 08:15:51 +02:00
committed by GitHub
co-authored by fibibot Bartek Iwańczuk
parent 1fcf2d9ad5
commit 072d09297e
4 changed files with 41 additions and 0 deletions
+8
View File
@@ -17,6 +17,12 @@ export interface FileSnapshot {
export interface BuildSnapshot<State> {
version: string;
clientEntry: string;
/**
* When defined, forces the boot script to be emitted in dev so HMR
* listeners attach even on island-free pages. The value itself is
* currently unused — only its presence matters. Undefined outside of dev.
*/
hmrClientEntry?: string;
fsRoutes: FsRouteFile<State>[];
staticFiles: Map<string, FileSnapshot>;
islands: ServerIslandRegistry;
@@ -51,6 +57,7 @@ export class ProdBuildCache<State> implements BuildCache<State> {
#snapshot: BuildSnapshot<State>;
islandRegistry: ServerIslandRegistry;
clientEntry: string;
hmrClientEntry: string | undefined;
features = { errorOverlay: false };
constructor(public root: string, snapshot: BuildSnapshot<State>) {
@@ -58,6 +65,7 @@ export class ProdBuildCache<State> implements BuildCache<State> {
this.#snapshot = snapshot;
this.islandRegistry = snapshot.islands;
this.clientEntry = snapshot.clientEntry;
this.hmrClientEntry = snapshot.hmrClientEntry;
}
getEntryAssets(): string[] {
@@ -458,6 +458,7 @@ export async function generateSnapshotServer(
outDir: string;
buildId: string;
clientEntry: string;
hmrClientEntry?: string;
islands: IslandModChunk[];
// deno-lint-ignore no-explicit-any
fsRoutesFiles: FsRouteFileNoMod<any>[];
@@ -524,12 +525,17 @@ export async function generateSnapshotServer(
const entryAssets = options.entryAssets.map((url) => JSON.stringify(url))
.join(",\n");
const hmrClientEntryDecl = options.hmrClientEntry !== undefined
? `export const hmrClientEntry = ${JSON.stringify(options.hmrClientEntry)}`
: "";
return `${EDIT_WARNING}
import { IslandPreparer } from "fresh/internal";
${islandImports}
${fsRouteImports}
export const clientEntry = ${JSON.stringify(options.clientEntry)}
${hmrClientEntryDecl}
export const version = ${JSON.stringify(options.buildId)}
export const islands = new Map();