feat(react): remount islands on hot module replacement

Disposes and re-creates island roots after a source change. Island state
resets by design; Fast Refresh needs a Babel/SWC transform plus a
runtime and is out of scope for v1.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-18 15:34:36 +05:30
co-authored by Claude Opus 5
parent 5f66c8129c
commit 02fdfa3aee
3 changed files with 81 additions and 0 deletions
+1
View File
@@ -6,3 +6,4 @@ export { IslandErrorBoundary } from "./error-boundary.tsx";
export type { IslandErrorBoundaryProps } from "./error-boundary.tsx";
export { islandRootCount, mountIslands, unmountIslands } from "./island-runtime.ts";
export type { MountOptions } from "./island-runtime.ts";
export { remountIslands } from "./island-runtime.ts";
+13
View File
@@ -100,3 +100,16 @@ export function unmountIslands(root: ParentNode): void {
roots.delete(element);
}
}
/**
* Dev-only: dispose and re-create island roots after a source change.
*
* Island state resets by design — Fast Refresh needs a Babel/SWC transform plus
* a runtime and is out of scope. `unmountIslands` clears each element from the
* root registry, so the following `mountIslands` is not short-circuited by the
* already-mounted guard.
*/
export async function remountIslands(root: ParentNode, options: MountOptions): Promise<void> {
unmountIslands(root);
await mountIslands(root, options);
}