feat: implement full Root.unmount() with disposeFiber and instance cleanup

This commit is contained in:
2026-05-18 17:31:31 +00:00
parent 4fb70c3f0a
commit 47e0e490a2
2 changed files with 196 additions and 0 deletions

View File

@@ -2,6 +2,7 @@ import type { UNode, UElement, URoot, ComponentFn, UComponent } from "../core/sc
import { isURoot, isUPrimitive } from "../core/schema.js";
import { Context } from "../core/context.js";
import type { Fiber } from "./fiber.js";
import { disposeFiber } from "./fiber.js";
import { reconcileProps, reconcileChildren, commitMutations } from "./reconcile.js";
import type { CommitContext } from "./reconcile.js";
@@ -302,8 +303,18 @@ export function createRoot<TTag extends string, Instance, RootCtx>(
host.emit?.("root.render", `root_${Date.now()}`, { childCount: payloadChildren.length });
},
unmount() {
const rootFiber = this.rootFiber;
if (!rootFiber) return;
disposeFiber(rootFiber, host as import("./fiber.js").HostLike<Instance, RootCtx>, ctx);
for (const child of rootFiber.children) {
host.removeChild?.(rootFiber.instance as never, child.instance as never, ctx as never);
}
host.finalizeRoot?.(ctx);
host.emit?.("root.unmount", `root_${Date.now()}`, {});
this.rootFiber = null;
},
};
}