/** * 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} }); }; // HMR morphs the server placeholder back over the mounted island, which // discards the React tree. Remount once the DOM has settled. window.addEventListener("wrnexus:hmr-updated", function () { window.__wrnexusRemountIslands(); }); }).catch(function (error) { console.error("[wrnexus] failed to load the island runtime", error); }); } if (document.readyState === "loading") { document.addEventListener("DOMContentLoaded", boot); } else { boot(); } })(); `; }