feat(islands): serve the island runtime in dev, prod, and static builds

Adds /__wrnexus/islands.js (the bootstrap) and the /__wrnexus/island/
prefix (mount runtime, island bundles, shared chunks) to all three
serving paths.

Dev reuses the browserArtifactPaths registry pattern from pipeline.ts.
Prod mirrors the clientModulesDir handler, including its filename
allowlist, so island names cannot escape the output directory.

The bootstrap is inert without a data-wrn-island marker, so island-free
pages still download nothing.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
ClintchizandClaude Opus 5 committed 2026-08-18 15:28:10 +05:30
1 parent 06df9d66ae
commit a184f1a3be
10 files changed
+135 -12

No files matched your search

+2 -1
View File
@@ -4,7 +4,8 @@ import { Component, type ErrorInfo, type ReactNode } from "react";
export interface IslandErrorBoundaryProps {
name: string;
development: boolean;
children: ReactNode;
/** Optional so createElement(Boundary, props, child) typechecks. */
children?: ReactNode;
}
interface IslandErrorBoundaryState {
+40
View File
@@ -0,0 +1,40 @@
/**
* The island bootstrap served at `/__wrnexus/islands.js`.
*
* Mirrors the `@wrnexus/csr` pattern: this file is only ever fetched when a
* `data-wrn-island` marker is present, so island-free pages download nothing —
* including React.
*/
export function getIslandRuntime(development = false): string {
return `
(function () {
function loader(name) {
return import("/__wrnexus/island/" + encodeURIComponent(name) + ".js");
}
function boot() {
if (!document.querySelector("[data-wrn-island]")) return;
import("/__wrnexus/island/runtime.js").then(function (runtime) {
runtime.mountIslands(document, { loader: loader, development: ${development} });
window.__wrnexusUnmountIslands = function (root) {
runtime.unmountIslands(root || document);
};
window.__wrnexusRemountIslands = function (root) {
return runtime.remountIslands(root || document, {
loader: loader,
development: ${development}
});
};
}).catch(function (error) {
console.error("[wrnexus] failed to load the island runtime", error);
});
}
if (document.readyState === "loading") {
document.addEventListener("DOMContentLoaded", boot);
} else {
boot();
}
})();
`;
}