{"version":3,"sources":["../src/core/patch-ops.ts","../src/core/fnode-pool.ts","../src/dom/batch-insert.ts","../src/dom/batch-remove.ts","../src/dom/render.ts"],"names":["encodeOp","buf","wordOffset","opType","nodeId","parentId","extra","decodeOp","PatchBuffer","initialCapacityWords","next","index","cb","i","createPatchBuffer","FNodePool","cap","type","node","fnodePool","batchInsertBefore","parent","nodes","beforeNode","len","frag","batchRemoveRange","n","contiguous","range","_patchBuffer","getPatchBuffer","resetPatchBuffer","_instanceKeyCounter","nextInstanceRegistryKey","instanceRegistry","currentRenderingInstance","resetRender","removeComponentInstance","instance","child","componentRegistry","stopComponentEffects","releaseComponentGlobals","getRegistry","removeInstanceByKey","registryParent","key","registry","mergeProps","props","renderComponent","fnode","effectiveRegistryParent","hasExplicitKey","parentRegistry","instanceCount","componentName","_","k","registryKey","isFirstRender","renderFn","currentFnode","currentProps","pushContext","previousRenderingInstance","fn","result","runWithComponent","newNodes","renderNode","nodeParent","marker","lastNode","tempContainer","newNodesArray","reconciledNodes","reconcile","unsafeEffect","flush","oldKeys","usedKeys","newKeys","dom","value","eventName","domWithHandlers","setAttribute","el","canReuse","oldNode","newNode","updateAttributes","oldEl","newEl","attr","oldHandlers","newHandlers","event","reconcileChildren","oldChildren","newChildren","maxLen","oldChild","newChild","patchNode","ownerInstance","idx","oldNodes","beforeMarker","resultNodes","oldLen","newLen","toRemove","old","overlap","toInsert","flushInsert","anchor","count","resultNode","render","app","container"],"mappings":"iKAoCO,SAASA,CAAAA,CACZC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACAC,CAAAA,CACI,CACJL,CAAAA,CAAIC,CAAU,CAAA,CAAIC,CAAAA,CAClBF,CAAAA,CAAIC,CAAAA,CAAa,CAAC,CAAA,CAAIE,CAAAA,CACtBH,CAAAA,CAAIC,CAAAA,CAAa,CAAC,CAAA,CAAIG,CAAAA,CACtBJ,CAAAA,CAAIC,CAAAA,CAAa,CAAC,CAAA,CAAII,E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AAA,CAAQpG,CAAAA,EAAAA,CAAK,CACnC,IAAM+E,CAAAA,CAAUtB,CAAAA,CAASzD,CAAC,CAAA,CACtB+E,CAAAA,GACAyB,CAAAA,CAAS,IAAA,CAAKzB,CAAO,CAAA,CACrBmB,CAAAA,CAAY,IAAA,CAAKnB,CAAO,CAAA,EAEhC,CACA,OAAA0B,CAAAA,CAAYR,CAAY,CAAA,CAEjBC,CACX,CAEO,SAASW,EAAAA,CAAOC,CAAAA,CAAsCC,CAAAA,CAAoC,CAC7F,OAAAA,CAAAA,CAAU,SAAA,CAAY,EAAA,CAMtBrD,CAAAA,CAJ0B,OAAOoD,CAAAA,EAAQ,UAAA,CACnC,CAAE,IAAA,CAAMA,CAAAA,CAAK,KAAA,CAAO,EAAC,CAAG,QAAA,CAAU,EAAC,CAAG,GAAA,CAAK,MAAU,CAAA,CACrDA,CAAAA,CAEYC,CAAS,CAAA,CAGpB,IAAM,CAET,GAAIzF,CAAAA,CAAiB,GAAA,CAAIyF,CAAS,CAAA,CAAG,CACjC,IAAM5E,CAAAA,CAAWb,CAAAA,CAAiB,GAAA,CAAIyF,CAAS,CAAA,CAC/C5E,CAAAA,CAAS,OAAA,CAAQT,CAAAA,EAAY,CACzBD,CAAAA,CAAwBC,CAAQ,EACpC,CAAC,CAAA,CACDS,CAAAA,CAAS,KAAA,EAAM,CACfb,CAAAA,CAAiB,MAAA,CAAOyF,CAAS,EACrC,CAEAA,CAAAA,CAAU,SAAA,CAAY,GAC1B,CACJ","file":"chunk-43UGKRX3.mjs","sourcesContent":["// Op type constants — 8-bit code stored in word 0 of each op slot.\nexport const OP_INSERT_TEXT = 0x01 as const\nexport const OP_INSERT_ELEMENT = 0x02 as const\nexport const OP_REMOVE = 0x03 as const\nexport const OP_SET_TEXT = 0x04 as const\nexport const OP_REPLACE = 0x05 as const\nexport const OP_MOVE = 0x06 as const\nexport const OP_SET_ATTR = 0x07 as const\nexport const OP_REMOVE_ATTR = 0x08 as const\n\nexport type OpType =\n    | typeof OP_INSERT_TEXT\n    | typeof OP_INSERT_ELEMENT\n    | typeof OP_REMOVE\n    | typeof OP_SET_TEXT\n    | typeof OP_REPLACE\n    | typeof OP_MOVE\n    | typeof OP_SET_ATTR\n    | typeof OP_REMOVE_ATTR\n\nexport interface PatchOp {\n    opType: OpType\n    nodeId: number\n    parentId: number\n    extra: number\n}\n\n// 4 × 32-bit words per op = 16 bytes / op.\nconst WORDS_PER_OP = 4\n\n// Initial capacity = 16 ops × 4 words.\nconst INITIAL_CAPACITY_WORDS = 64\n\n/**\n * Write one op into `buf` at word offset `wordOffset` (must be a multiple of 4).\n */\nexport function encodeOp(\n    buf: Uint32Array,\n    wordOffset: number,\n    opType: OpType,\n    nodeId: number,\n    parentId: number,\n    extra: number,\n): void {\n    buf[wordOffset] = opType\n    buf[wordOffset + 1] = nodeId\n    buf[wordOffset + 2] = parentId\n    buf[wordOffset + 3] = extra\n}\n\n/**\n * Read one op from `buf` at word offset `wordOffset`.\n */\nexport function decodeOp(buf: Uint32Array, wordOffset: number): PatchOp {\n    return {\n        opType: buf[wordOffset] as OpType,\n        nodeId: buf[wordOffset + 1],\n        parentId: buf[wordOffset + 2],\n        extra: buf[wordOffset + 3],\n    }\n}\n\n/**\n * Resizable typed-array-backed buffer for DOM patch ops.\n *\n * The buffer doubles on overflow so growth is amortised O(1). `reset()` keeps\n * the existing ArrayBuffer so repeated render cycles reuse the same allocation.\n */\nexport class PatchBuffer {\n    private _buf: Uint32Array\n    private _len = 0 // op count (not word count)\n\n    constructor(initialCapacityWords: number = INITIAL_CAPACITY_WORDS) {\n        this._buf = new Uint32Array(initialCapacityWords)\n    }\n\n    get length(): number {\n        return this._len\n    }\n\n    push(opType: OpType, nodeId: number, parentId: number, extra: number): void {\n        const wordOffset = this._len * WORDS_PER_OP\n        if (wordOffset + WORDS_PER_OP > this._buf.length) {\n            const next = new Uint32Array(this._buf.length * 2)\n            next.set(this._buf)\n            this._buf = next\n        }\n        encodeOp(this._buf, wordOffset, opType, nodeId, parentId, extra)\n        this._len++\n    }\n\n    get(index: number): PatchOp {\n        return decodeOp(this._buf, index * WORDS_PER_OP)\n    }\n\n    reset(): void {\n        this._len = 0\n    }\n\n    forEach(cb: (op: PatchOp, index: number) => void): void {\n        for (let i = 0; i < this._len; i++) {\n            cb(decodeOp(this._buf, i * WORDS_PER_OP), i)\n        }\n    }\n\n    /** Zero-copy view of the live op range. Caller must not mutate after reset. */\n    rawSlice(): Uint32Array {\n        return this._buf.subarray(0, this._len * WORDS_PER_OP)\n    }\n}\n\nexport function createPatchBuffer(initialCapacityWords?: number): PatchBuffer {\n    return new PatchBuffer(initialCapacityWords)\n}\n","import type { FNode } from '../dom/types'\n\n/**\n * Object pool for FNode instances.\n *\n * The renderer historically allocates a fresh FNode per `f()` call and per\n * render pass. Under list-heavy workloads (5k-10k rows) this produces tens of\n * thousands of short-lived allocations per update cycle, which makes the V8\n * minor GC fire frequently. The pool recycles released nodes so subsequent\n * `acquire()` calls hit a warm slot instead of allocating.\n *\n * Lifecycle:\n *   acquire(type)     populate fields → use in render\n *   release(node)     called by renderer on node removal → node returns to pool\n *\n * Bounded by `cap` (default 1000) to avoid the pool itself becoming a memory\n * leak. Over-cap releases are dropped on the floor.\n *\n * Stale-data prevention: every released node has all fields wiped before it\n * goes back on the stack so the next consumer cannot accidentally observe the\n * previous tenant's props/children.\n */\nexport class FNodePool {\n  private readonly _pool: FNode[] = []\n  private readonly _cap: number\n\n  constructor(cap = 1000) {\n    this._cap = cap\n  }\n\n  get size(): number {\n    return this._pool.length\n  }\n\n  /**\n   * Return a fresh or recycled FNode. The `type` field is set to the argument;\n   * all other fields are zeroed by the prior `release()` call.\n   */\n  acquire(type: FNode['type']): FNode {\n    if (this._pool.length > 0) {\n      const node = this._pool.pop()!\n      node.type = type\n      return node\n    }\n    return { type, props: {}, children: [], key: undefined }\n  }\n\n  /**\n   * Return `node` to the pool after zeroing its fields. Dropped silently when\n   * the pool is at cap. Idempotent — releasing the same node twice in a row\n   * leaves the pool size unchanged (only first release stores it).\n   */\n  release(node: FNode): void {\n    if (this._pool.length >= this._cap) return\n    // Idempotency: if the same object reference is already in the pool, skip.\n    // A linear scan is acceptable because the pool is small in practice.\n    for (let i = 0; i < this._pool.length; i++) {\n      if (this._pool[i] === node) return\n    }\n    // Zero every field before storing — prevents stale-data leakage.\n    node.type = ''\n    node.props = {}\n    node.children = []\n    node.key = undefined\n    this._pool.push(node)\n  }\n\n  /** Reset the pool — used by tests for deterministic state. */\n  clear(): void {\n    this._pool.length = 0\n  }\n}\n\n/**\n * Module-level singleton used by the renderer. Tests can call `clear()` to\n * reset between cases. Real consumers should not construct a second pool —\n * sharing one instance maximizes recycle hits.\n */\nexport const fnodePool = new FNodePool()\n","/**\n * Insert `nodes` into `parent` before `beforeNode` using a single\n * DocumentFragment, reducing browser layout to one reflow.\n *\n * @param parent      Target parent element.\n * @param nodes       Nodes to insert. The array is read-only — nodes are moved\n *                    into a DocumentFragment, which then becomes a child of\n *                    `parent`. The caller's array is left intact.\n * @param beforeNode  Insert before this node. Pass `null` to append at the end.\n */\nexport function batchInsertBefore(\n    parent: Node,\n    nodes: Node[],\n    beforeNode: Node | null,\n): void {\n    const len = nodes.length\n    if (len === 0) return\n\n    if (len === 1) {\n        // Avoid DocumentFragment overhead for the common single-node case.\n        parent.insertBefore(nodes[0], beforeNode)\n        return\n    }\n\n    const frag = document.createDocumentFragment()\n    for (let i = 0; i < len; i++) {\n        frag.appendChild(nodes[i])\n    }\n    parent.insertBefore(frag, beforeNode)\n}\n","/**\n * Remove a contiguous slice of sibling nodes from `parent` using the Range API,\n * which lets the browser batch the removal into a single layout pass.\n *\n * Falls back to individual `removeChild` calls when:\n * - Only one node is supplied (Range setup would be more work than the removal).\n * - The Range API is unavailable (SSR / non-browser environment).\n * - The supplied nodes are not contiguous siblings.\n *\n * @param parent  Common parent element.\n * @param nodes   Nodes to remove. Nodes whose `parentNode` is not `parent` are\n *                skipped silently.\n */\nexport function batchRemoveRange(parent: Node, nodes: Node[]): void {\n    const len = nodes.length\n    if (len === 0) return\n\n    // Single-node fast path.\n    if (len === 1) {\n        const n = nodes[0]\n        if (n.parentNode === parent) parent.removeChild(n)\n        return\n    }\n\n    // Range API availability — primarily for SSR / Node environments without\n    // a full DOM, but we still need to remove individually to honour the\n    // public contract.\n    if (typeof document === 'undefined' || typeof document.createRange !== 'function') {\n        for (let i = 0; i < len; i++) {\n            const n = nodes[i]\n            if (n.parentNode === parent) parent.removeChild(n)\n        }\n        return\n    }\n\n    // Range works correctly only for nodes that are (a) direct children of\n    // `parent` AND (b) consecutive siblings. Both must hold.\n    let contiguous = true\n    for (let i = 1; i < len; i++) {\n        if (nodes[i - 1].nextSibling !== nodes[i]) {\n            contiguous = false\n            break\n        }\n    }\n\n    if (contiguous && nodes[0].parentNode === parent) {\n        const range = document.createRange()\n        range.setStartBefore(nodes[0])\n        range.setEndAfter(nodes[len - 1])\n        range.deleteContents()\n        return\n    }\n\n    // Non-contiguous or attached to a different parent — fall back to\n    // individual removal, skipping nodes that aren't actually our children.\n    for (let i = 0; i < len; i++) {\n        const n = nodes[i]\n        if (n.parentNode === parent) parent.removeChild(n)\n    }\n}\n","import { pushContext } from '../core/context'\nimport { runWithComponent, stopComponentEffects, releaseComponentGlobals, type ComponentInstance } from '../core/hook'\nimport { unsafeEffect, flush } from '../core/lifecycle'\nimport {\n    PatchBuffer,\n    createPatchBuffer,\n    OP_INSERT_ELEMENT,\n    OP_REMOVE,\n} from '../core/patch-ops'\nimport { fnodePool } from '../core/fnode-pool'\nimport { componentRegistry } from '../core/component-registry'\nimport { batchInsertBefore } from './batch-insert'\nimport { batchRemoveRange } from './batch-remove'\nimport type { FNode, FNodeChild } from './types'\n\n// Module-level patch buffer — reset and replayed each flush.\n// Phase 2A wiring; Phase 2B batch helpers will consume this buffer.\nconst _patchBuffer: PatchBuffer = createPatchBuffer()\n\n/** Expose for testing / Phase B consumers. */\nexport function getPatchBuffer(): PatchBuffer {\n    return _patchBuffer\n}\n\nexport function resetPatchBuffer(): void {\n    _patchBuffer.reset()\n}\n\n// Extended ComponentInstance for DOM tracking.\n// Phase 5C: every property is pre-initialized in the constructor literal to\n// lock the V8 hidden class. Optional fields use `| null` as the unallocated\n// sentinel rather than relying on `undefined`/lazy creation.\ninterface DOMComponentInstance extends ComponentInstance {\n    nodes: Node[]\n    parent: HTMLElement\n    fnode: FNode\n    props: Record<string, unknown>\n    key: unknown\n    renderFn: (() => void) | null\n    children: Set<DOMComponentInstance>\n    parentInstance: DOMComponentInstance | null\n    disposed: boolean\n    /** Stable key under which this instance is registered with the componentRegistry. */\n    __registryKey: string | null\n    /** Guard: prevents the FinalizationRegistry cleanup from re-running our explicit teardown. */\n    __emergencyCleanupDone: boolean\n}\n\nlet _instanceKeyCounter = 0\nfunction nextInstanceRegistryKey(): string {\n    return `flex-inst-${++_instanceKeyCounter}`\n}\n\n// Registry to store component instances by parent and key\nconst instanceRegistry = new WeakMap<HTMLElement, Map<unknown, DOMComponentInstance>>()\n\n// Current rendering component instance (for tracking parent-child relationships)\nlet currentRenderingInstance: DOMComponentInstance | null = null\n\n// Reset render state - call before re-rendering the entire app (e.g., srcdoc update)\nexport function resetRender(): void {\n    currentRenderingInstance = null\n    // Note: WeakMap will automatically GC old entries when their keys are gone\n}\n\n// Recursively remove component instance and all its children\nfunction removeComponentInstance(instance: DOMComponentInstance): void {\n    if (instance.disposed) return\n    instance.disposed = true\n\n    // First, recursively remove all children\n    instance.children.forEach(child => {\n        removeComponentInstance(child)\n    })\n\n    // Mark emergency-cleanup as done BEFORE unregistering — the finalizer\n    // callback we registered checks this flag, so any later GC-triggered fire\n    // becomes a no-op. Explicit unregister also removes the FinalizationRegistry\n    // binding, so under normal flow the callback never runs.\n    instance.__emergencyCleanupDone = true\n    if (instance.__registryKey) {\n        componentRegistry.unregister(instance.__registryKey)\n    }\n\n    // Stop any reactive effects registered by unsafeEffect() inside this component's render.\n    // This prevents memory leaks from effects that track reactive state beyond the component's lifetime.\n    stopComponentEffects(instance)\n\n    // Decrement refcounts for any global registry keys held by this component and evict entries at zero.\n    releaseComponentGlobals(instance)\n\n    // Remove DOM nodes\n    instance.nodes.forEach(node => {\n        if (node.parentNode) {\n            node.parentNode.removeChild(node)\n        }\n    })\n\n    instance.nodes = []\n    instance.children.clear()\n\n    // Unlink from parent\n    if (instance.parentInstance) {\n        instance.parentInstance.children.delete(instance)\n    }\n\n    // Phase 4 — return the FNode descriptor that drove this component to the\n    // pool. The DOM nodes it referenced are gone; the descriptor itself is\n    // dead. Subsequent `f()` calls do not yet acquire from the pool, but the\n    // pool now warms up across the run so future passes (Phase 4 Task 4)\n    // can flip `f()` to pull from it.\n    fnodePool.release(instance.fnode)\n}\n\n// Get or create registry for parent element\nfunction getRegistry(parent: HTMLElement): Map<unknown, DOMComponentInstance> {\n    if (!instanceRegistry.has(parent)) {\n        instanceRegistry.set(parent, new Map())\n    }\n    return instanceRegistry.get(parent)!\n}\n\n// Remove instance from registry and DOM\nfunction removeInstanceByKey(registryParent: HTMLElement, key: unknown): void {\n    const registry = instanceRegistry.get(registryParent)\n    if (registry && registry.has(key)) {\n        const instance = registry.get(key)!\n        removeComponentInstance(instance)\n        registry.delete(key)\n    }\n}\n\n/**\n * Build a flat props object for a component invocation, lifting `children`\n * out of the FNode children array as a top-level prop the component can read.\n *\n * Phase 4 — module-scope static function. Previously this lived as an arrow\n * inside renderComponent and allocated a fresh closure per component mount.\n */\nfunction mergeProps(node: FNode): Record<string, unknown> {\n    const props: Record<string, unknown> = { ...node.props }\n    if (node.children && node.children.length > 0) {\n        props.children = node.children.length === 1\n            ? node.children[0]\n            : node.children\n    }\n    return props\n}\n\n// Render a function component with reactive re-rendering\nfunction renderComponent(fnode: FNode, parent: HTMLElement, registryParent?: HTMLElement): Node[] {\n    const effectiveRegistryParent = registryParent || parent\n\n    const hasExplicitKey = fnode.key !== undefined\n    const parentRegistry = getRegistry(effectiveRegistryParent)\n\n    let key: unknown\n    if (hasExplicitKey) {\n        key = fnode.key\n    } else {\n        let instanceCount = 0\n        const componentName = typeof fnode.type === 'function' ? (fnode.type.name || 'anonymous') : 'anonymous'\n        parentRegistry.forEach((_, k) => {\n            if (typeof k === 'string' && k.startsWith(`__auto_${componentName}_`)) {\n                instanceCount++\n            }\n        })\n        key = `__auto_${componentName}_${instanceCount}`\n    }\n\n    // Check if we have an existing instance with this key\n    if (parentRegistry.has(key)) {\n        const instance = parentRegistry.get(key)!\n\n        // If instance was marked for disposal, skip reuse\n        if (instance.disposed) {\n            parentRegistry.delete(key)\n        } else {\n            // Reuse existing instance - update props and re-render\n            instance.fnode = fnode\n            instance.props = mergeProps(fnode)\n\n            // Trigger re-render\n            if (instance.renderFn) {\n                instance.renderFn()\n            }\n\n            return instance.nodes\n        }\n    }\n\n    // Create new component instance.\n    // Phase 5C: every field is pre-initialized in this literal to lock the V8\n    // hidden class. Order matters — keep it stable across renders so all\n    // instances share one IC entry.\n    const registryKey = nextInstanceRegistryKey()\n    const instance: DOMComponentInstance = {\n        hooks: [],\n        hookIndex: 0,\n        componentName: typeof fnode.type === 'function' ? (fnode.type.name || 'Component') : 'Component',\n        hookSignatures: null,\n        prevHookSignatures: null,\n        effects: null,\n        globalKeys: null,\n        nodes: [],\n        parent,\n        fnode: fnode,\n        props: mergeProps(fnode),\n        key,\n        renderFn: null,\n        children: new Set(),\n        parentInstance: currentRenderingInstance ?? null,\n        disposed: false,\n        __registryKey: registryKey,\n        __emergencyCleanupDone: false,\n    }\n\n    if (currentRenderingInstance) {\n        currentRenderingInstance.children.add(instance)\n    }\n\n    parentRegistry.set(key, instance)\n\n    // Phase 4 — register the instance with ComponentWeakRegistry so a forgotten\n    // dispose path (or GC-only collection) still releases its effects + globals.\n    // The flag guard is closed-over per instance, so under normal unmount the\n    // cleanup runs exactly once via removeComponentInstance.\n    componentRegistry.register(instance, registryKey, () => {\n        if (instance.__emergencyCleanupDone) return\n        instance.__emergencyCleanupDone = true\n        stopComponentEffects(instance)\n        releaseComponentGlobals(instance)\n    })\n\n    let isFirstRender = true\n\n    const renderFn = () => {\n        if (instance.disposed) return\n\n        const currentFnode = instance.fnode\n        const currentProps = instance.props\n\n        // eslint-disable-next-line @typescript-eslint/no-explicit-any -- ._contextId is a dynamic property set by Context constructor on Provider functions\n        const isProvider = (currentFnode.type as any)._contextId !== undefined\n        if (isProvider) {\n            // eslint-disable-next-line @typescript-eslint/no-explicit-any -- see above\n            pushContext((currentFnode.type as any)._contextId as symbol, currentProps.value)\n        }\n\n        const previousRenderingInstance = currentRenderingInstance\n        currentRenderingInstance = instance\n\n        const fn = currentFnode.type as (props: Record<string, unknown>) => FNodeChild\n        const result = runWithComponent(instance, () => fn(currentProps))\n\n        if (isFirstRender) {\n            const newNodes = renderNode(result, parent)\n            instance.nodes = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\n            instance.nodes.forEach(node => {\n                if (!(node as Node & { __ownerInstance?: DOMComponentInstance }).__ownerInstance) {\n                    (node as Node & { __ownerInstance?: DOMComponentInstance }).__ownerInstance = instance\n                }\n            })\n            isFirstRender = false\n        } else {\n            if (instance.nodes.length === 0) {\n                const newNodes = renderNode(result, parent)\n                instance.nodes = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\n                currentRenderingInstance = previousRenderingInstance\n                return\n            }\n\n            const firstNode = instance.nodes[0]\n            let nodeParent = firstNode.parentNode as HTMLElement\n\n            if (!nodeParent) {\n                nodeParent = instance.parent\n            }\n\n            const marker = document.createComment('flexium-marker')\n            const lastNode = instance.nodes[instance.nodes.length - 1]\n            if (lastNode.nextSibling) {\n                nodeParent.insertBefore(marker, lastNode.nextSibling)\n            } else {\n                nodeParent.appendChild(marker)\n            }\n\n            instance.children.clear()\n\n            const tempContainer = document.createElement('div')\n            const newNodes = renderNode(result, tempContainer, nodeParent)\n            const newNodesArray = newNodes ? (Array.isArray(newNodes) ? newNodes : [newNodes]) : []\n\n            const reconciledNodes = reconcile(instance.nodes, newNodesArray, nodeParent, marker)\n\n            nodeParent.removeChild(marker)\n\n            instance.nodes = reconciledNodes\n        }\n\n        currentRenderingInstance = previousRenderingInstance\n    }\n\n    instance.renderFn = renderFn\n\n    // Framework-internal root effect: drives this component's reactive re-renders.\n    // Use .detached so it is NOT registered on the parent component — ownership is\n    // tracked via DOMComponentInstance itself and stopped in removeComponentInstance.\n    unsafeEffect.detached(renderFn)\n\n    // Flush to ensure synchronous rendering for proper node tracking\n    flush()\n\n    return instance.nodes\n}\n\nexport function renderNode(fnode: FNodeChild, parent: HTMLElement, registryParent?: HTMLElement): Node | Node[] | null {\n    const effectiveRegistryParent = registryParent || parent\n\n    if (fnode === null || fnode === undefined || typeof fnode === 'boolean') {\n        const node = document.createTextNode('')\n        parent.appendChild(node)\n        return node\n    }\n\n    if (typeof fnode === 'string' || typeof fnode === 'number') {\n        const node = document.createTextNode(String(fnode))\n        parent.appendChild(node)\n        return node\n    }\n\n    if (Array.isArray(fnode)) {\n        const registry = getRegistry(effectiveRegistryParent)\n\n        // Collect existing keys before render\n        const oldKeys = new Set<unknown>(registry.keys())\n\n        // Pre-collect explicit keys that will be rendered\n        const usedKeys = new Set<unknown>()\n        fnode.forEach(child => {\n            if (child && typeof child === 'object' && !Array.isArray(child) && 'type' in child && typeof (child as FNode).type === 'function' && (child as FNode).key !== undefined) {\n                usedKeys.add((child as FNode).key)\n            }\n        })\n\n        // KEY FIX: Remove instances with explicit keys that won't be rendered BEFORE rendering new ones\n        // This ensures old route components are removed before new ones are created\n        oldKeys.forEach(key => {\n            // Only handle explicit keys (not auto-generated ones)\n            if (typeof key !== 'string' || !key.startsWith('__auto_')) {\n                if (!usedKeys.has(key)) {\n                    removeInstanceByKey(effectiveRegistryParent, key)\n                }\n            }\n        })\n\n        // Now render children\n        const nodes: Node[] = []\n        fnode.forEach((child) => {\n            const result = renderNode(child, parent, registryParent)\n            if (result) {\n                if (Array.isArray(result)) {\n                    nodes.push(...result)\n                } else {\n                    nodes.push(result)\n                }\n            }\n        })\n\n        // Collect keys after render to handle auto-generated keys\n        const newKeys = new Set<unknown>(registry.keys())\n\n        // Remove auto-generated keys that are no longer present\n        oldKeys.forEach(key => {\n            if (!newKeys.has(key) && typeof key === 'string' && key.startsWith('__auto_')) {\n                const instance = registry.get(key)\n                if (instance) {\n                    removeComponentInstance(instance)\n                    registry.delete(key)\n                }\n            }\n        })\n\n        return nodes\n    }\n\n    if (typeof fnode === 'object') {\n        if (typeof fnode.type === 'string') {\n            const dom = document.createElement(fnode.type)\n\n            if (fnode.props) {\n                Object.entries(fnode.props).forEach(([key, value]) => {\n                    if (key === 'ref') {\n                        // Handle both callback refs and RefObject\n                        if (typeof value === 'function') {\n                            value(dom)\n                        } else if (value && typeof value === 'object' && 'current' in value) {\n                            value.current = dom\n                        }\n                    } else if (key.startsWith('on') && typeof value === 'function') {\n                        const eventName = key.slice(2).toLowerCase()\n                        dom.addEventListener(eventName, value as EventListener)\n\n                        const domWithHandlers = dom as Element & { __eventHandlers?: Record<string, EventListener> }\n                        if (!domWithHandlers.__eventHandlers) {\n                            domWithHandlers.__eventHandlers = {}\n                        }\n                        domWithHandlers.__eventHandlers[eventName] = value as EventListener\n                    } else if (key !== 'ref') {\n                        setAttribute(dom, key, value)\n                    }\n                })\n            }\n\n            if (fnode.children && fnode.children.length > 0) {\n                fnode.children.forEach((child: FNodeChild) => {\n                    renderNode(child, dom)\n                })\n            }\n\n            parent.appendChild(dom)\n            return dom\n        }\n\n        if (typeof fnode.type === 'function') {\n            return renderComponent(fnode, parent, registryParent)\n        }\n    }\n\n    return null\n}\n\nfunction setAttribute(el: Element, key: string, value: unknown) {\n    if (value === null || value === undefined) {\n        el.removeAttribute(key)\n    } else if (key === 'style' && typeof value === 'object') {\n        Object.assign((el as HTMLElement).style, value)\n    } else if (key === 'class') {\n        el.className = String(value)\n    } else if (key in el && typeof (el as unknown as Record<string, unknown>)[key] !== 'function') {\n        (el as unknown as Record<string, unknown>)[key] = value\n    } else {\n        el.setAttribute(key, String(value))\n    }\n}\n\n// Reconciliation helpers\nfunction canReuse(oldNode: Node, newNode: Node): boolean {\n    if (oldNode.nodeType !== newNode.nodeType) return false\n    if (oldNode.nodeType === Node.ELEMENT_NODE && newNode.nodeType === Node.ELEMENT_NODE) {\n        return (oldNode as Element).tagName === (newNode as Element).tagName\n    }\n    return true\n}\n\nfunction updateAttributes(oldEl: Element, newEl: Element): void {\n    const oldAttrs = Array.from(oldEl.attributes)\n    oldAttrs.forEach(attr => {\n        if (!newEl.hasAttribute(attr.name)) {\n            oldEl.removeAttribute(attr.name)\n        }\n    })\n\n    const newAttrs = Array.from(newEl.attributes)\n    newAttrs.forEach(attr => {\n        if (oldEl.getAttribute(attr.name) !== attr.value) {\n            if (attr.name === 'value' && 'value' in oldEl) {\n                (oldEl as HTMLInputElement).value = attr.value\n            } else if (attr.name === 'checked' && 'checked' in oldEl) {\n                (oldEl as HTMLInputElement).checked = attr.value === 'true' || attr.value === ''\n            } else {\n                oldEl.setAttribute(attr.name, attr.value)\n            }\n        }\n    })\n\n    type ElWithHandlers = Element & { __eventHandlers?: Record<string, EventListener> }\n    const oldHandlers = (oldEl as ElWithHandlers).__eventHandlers || {}\n    const newHandlers = (newEl as ElWithHandlers).__eventHandlers || {}\n\n    Object.keys(oldHandlers).forEach(event => {\n        if (!newHandlers[event]) {\n            oldEl.removeEventListener(event, oldHandlers[event])\n        }\n    })\n\n    Object.keys(newHandlers).forEach(event => {\n        if (oldHandlers[event] !== newHandlers[event]) {\n            if (oldHandlers[event]) {\n                oldEl.removeEventListener(event, oldHandlers[event])\n            }\n            oldEl.addEventListener(event, newHandlers[event])\n        }\n    })\n\n    if (Object.keys(newHandlers).length > 0) {\n        (oldEl as ElWithHandlers).__eventHandlers = newHandlers\n    } else {\n        delete (oldEl as ElWithHandlers).__eventHandlers\n    }\n\n    if (oldEl instanceof HTMLInputElement && newEl instanceof HTMLInputElement) {\n        if (oldEl.value !== newEl.value) {\n            oldEl.value = newEl.value\n        }\n        if (oldEl.checked !== newEl.checked) {\n            oldEl.checked = newEl.checked\n        }\n    }\n    if (oldEl instanceof HTMLTextAreaElement && newEl instanceof HTMLTextAreaElement) {\n        if (oldEl.value !== newEl.value) {\n            oldEl.value = newEl.value\n        }\n    }\n    if (oldEl instanceof HTMLSelectElement && newEl instanceof HTMLSelectElement) {\n        if (oldEl.value !== newEl.value) {\n            oldEl.value = newEl.value\n        }\n    }\n}\n\nfunction reconcileChildren(oldEl: Element, newEl: Element): void {\n    const oldChildren = Array.from(oldEl.childNodes)\n    const newChildren = Array.from(newEl.childNodes)\n    const maxLen = Math.max(oldChildren.length, newChildren.length)\n\n    for (let i = 0; i < maxLen; i++) {\n        const oldChild = oldChildren[i]\n        const newChild = newChildren[i]\n\n        if (!oldChild && newChild) {\n            oldEl.appendChild(newChild)\n        } else if (oldChild && !newChild) {\n            oldEl.removeChild(oldChild)\n        } else if (oldChild && newChild) {\n            // patchNode returns the node that's now in DOM\n            // For reconcileChildren, we just need the side effect\n            patchNode(oldChild, newChild, oldEl)\n        }\n    }\n}\n\ntype NodeWithOwner = Node & { __ownerInstance?: DOMComponentInstance }\n\nfunction patchNode(oldNode: Node, newNode: Node, parent: Element): Node {\n    if (canReuse(oldNode, newNode)) {\n        const ownerInstance = (newNode as NodeWithOwner).__ownerInstance\n        if (ownerInstance) {\n            const idx = ownerInstance.nodes.indexOf(newNode)\n            if (idx !== -1) {\n                ownerInstance.nodes[idx] = oldNode\n            }\n            ;(oldNode as NodeWithOwner).__ownerInstance = ownerInstance\n            delete (newNode as NodeWithOwner).__ownerInstance\n        }\n\n        if (oldNode.nodeType === Node.TEXT_NODE) {\n            if (oldNode.nodeValue !== newNode.nodeValue) {\n                oldNode.nodeValue = newNode.nodeValue\n            }\n        } else if (oldNode.nodeType === Node.ELEMENT_NODE) {\n            updateAttributes(oldNode as Element, newNode as Element)\n            reconcileChildren(oldNode as Element, newNode as Element)\n        }\n        return oldNode\n    } else {\n        // Ensure oldNode is actually a child of parent before replacing\n        if (oldNode.parentNode === parent) {\n            parent.replaceChild(newNode, oldNode)\n        } else if (oldNode.parentNode) {\n            // oldNode is attached to a different parent, remove it and insert newNode\n            oldNode.parentNode.removeChild(oldNode)\n            parent.insertBefore(newNode, null)\n        } else {\n            // oldNode is detached, just insert newNode\n            parent.insertBefore(newNode, null)\n        }\n        return newNode\n    }\n}\n\nexport function reconcile(oldNodes: Node[], newNodes: Node[], parent: Node, beforeMarker: Node): Node[] {\n    const resultNodes: Node[] = []\n    const oldLen = oldNodes.length\n    const newLen = newNodes.length\n\n    // 1. Remove trailing old nodes (those past the new length). Range-batched\n    //    when the tail is contiguous, which it almost always is.\n    if (newLen < oldLen) {\n        const toRemove: Node[] = []\n        for (let i = newLen; i < oldLen; i++) {\n            const old = oldNodes[i]\n            if (old && old.parentNode) toRemove.push(old)\n        }\n        if (toRemove.length > 0) {\n            batchRemoveRange(parent, toRemove)\n            for (let i = 0; i < toRemove.length; i++) {\n                _patchBuffer.push(OP_REMOVE, 0, 0, 0)\n            }\n        }\n    }\n\n    // 2. Walk overlap + the new-only suffix. Patch in-place where possible,\n    //    accumulate insertions and flush them as a DocumentFragment whenever\n    //    the run is broken (or at the end).\n    const overlap = Math.min(oldLen, newLen)\n    const toInsert: Node[] = []\n\n    const flushInsert = (anchor: Node | null) => {\n        if (toInsert.length === 0) return\n        const count = toInsert.length\n        batchInsertBefore(parent, toInsert, anchor)\n        for (let i = 0; i < count; i++) {\n            _patchBuffer.push(OP_INSERT_ELEMENT, 0, 0, 0)\n        }\n        toInsert.length = 0\n    }\n\n    // 2a. Overlapping range — patch in-place, no insertions to batch.\n    for (let i = 0; i < overlap; i++) {\n        const oldNode = oldNodes[i]\n        const newNode = newNodes[i]\n        const resultNode = patchNode(oldNode, newNode, parent as Element)\n        resultNodes.push(resultNode)\n    }\n\n    // 2b. Trailing inserts (newLen > oldLen). Stage all and flush once before\n    //     the beforeMarker.\n    for (let i = overlap; i < newLen; i++) {\n        const newNode = newNodes[i]\n        if (newNode) {\n            toInsert.push(newNode)\n            resultNodes.push(newNode)\n        }\n    }\n    flushInsert(beforeMarker)\n\n    return resultNodes\n}\n\nexport function render(app: FNodeChild | (() => FNodeChild), container: HTMLElement): () => void {\n    container.innerHTML = ''\n\n    const fnode: FNodeChild = typeof app === 'function'\n        ? { type: app, props: {}, children: [], key: undefined }\n        : app\n\n    renderNode(fnode, container)\n\n    // Return dispose function\n    return () => {\n        // Remove all component instances registered under this container\n        if (instanceRegistry.has(container)) {\n            const registry = instanceRegistry.get(container)!\n            registry.forEach(instance => {\n                removeComponentInstance(instance)\n            })\n            registry.clear()\n            instanceRegistry.delete(container)\n        }\n        // Clear container\n        container.innerHTML = ''\n    }\n}\n"]}