feat: implement full Root.unmount() with disposeFiber and instance cleanup
This commit is contained in:
@@ -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;
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user