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:
@@ -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";
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user