| 284 | } |
| 285 | |
| 286 | export function commitVNodeTree( |
| 287 | prevRoot: RuntimeInstance | null, |
| 288 | nextRootVNode: VNode, |
| 289 | opts: Readonly<{ |
| 290 | allocator: InstanceIdAllocator; |
| 291 | localState?: RuntimeLocalStateStore; |
| 292 | collectLifecycleInstanceIds?: boolean; |
| 293 | interactiveIdIndex?: Map<string, string>; |
| 294 | composite?: CompositeCommitRuntime; |
| 295 | errorBoundary?: CommitErrorBoundaryController; |
| 296 | }>, |
| 297 | ): CommitResult { |
| 298 | const collectLifecycleInstanceIds = opts.collectLifecycleInstanceIds !== false; |
| 299 | const interactiveIdIndex = opts.interactiveIdIndex ?? new Map<string, string>(); |
| 300 | interactiveIdIndex.clear(); |
| 301 | const ctx: CommitCtx = { |
| 302 | allocator: opts.allocator, |
| 303 | localState: opts.localState, |
| 304 | seenInteractiveIds: interactiveIdIndex, |
| 305 | seenFocusContainerIds: new Map<string, FocusContainerKind>(), |
| 306 | prevNodeStack: [], |
| 307 | containerChildOverrides: new Map<InstanceId, readonly VNode[]>(), |
| 308 | layoutDepthRef: { value: 0 }, |
| 309 | layoutPathTail: [], |
| 310 | emittedWarnings: new Set<string>(), |
| 311 | lists: { mounted: [], reused: [], unmounted: [] }, |
| 312 | collectLifecycleInstanceIds, |
| 313 | composite: opts.composite ?? null, |
| 314 | compositeThemeStack: opts.composite?.theme ? [opts.composite.theme] : [], |
| 315 | compositeRenderStack: [], |
| 316 | pendingExitAnimations: [], |
| 317 | pendingCleanups: [], |
| 318 | pendingEffects: [], |
| 319 | errorBoundary: opts.errorBoundary ?? null, |
| 320 | }; |
| 321 | |
| 322 | const prevChildren = prevRoot ? [{ instanceId: prevRoot.instanceId, vnode: prevRoot.vnode }] : []; |
| 323 | const res = reconcileChildren(0, prevChildren, [nextRootVNode], opts.allocator, { |
| 324 | kind: "root", |
| 325 | }); |
| 326 | if (!res.ok) return { ok: false, fatal: res.fatal }; |
| 327 | |
| 328 | const rootPlan = res.value.nextChildren[0]; |
| 329 | if (!rootPlan) { |
| 330 | return { |
| 331 | ok: false, |
| 332 | fatal: { code: "ZRUI_INVALID_PROPS", detail: "commitVNodeTree: missing root vnode" }, |
| 333 | }; |
| 334 | } |
| 335 | |
| 336 | if (prevRoot && rootPlan.prevIndex === null) { |
| 337 | if (!tryScheduleExitAnimation(ctx, prevRoot, 0)) { |
| 338 | deleteLocalStateForSubtree(opts.localState, prevRoot); |
| 339 | collectSubtreeInstanceIds(prevRoot, ctx.lists.unmounted); |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | const prevMatch = rootPlan.prevIndex === 0 ? prevRoot : null; |