@tanstack/redact 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dom/reconcile.js +5 -13
- package/dist/dom/reconcile.js.map +2 -2
- package/dist/dom/root.js +8 -0
- package/dist/dom/root.js.map +2 -2
- package/dist/vite/index.js +3 -6
- package/dist/vite/index.js.map +2 -2
- package/package.json +1 -1
- package/src/dom/reconcile.ts +12 -12
- package/src/dom/root.ts +10 -0
- package/src/vite/index.ts +15 -17
package/dist/dom/reconcile.js
CHANGED
|
@@ -692,14 +692,11 @@ function attachRef(fiber, value) {
|
|
|
692
692
|
const ref = fiber.ref ?? (fiber.pendingProps?.ref ?? null);
|
|
693
693
|
if (!ref) return;
|
|
694
694
|
if (typeof ref === "function") {
|
|
695
|
-
|
|
696
|
-
|
|
695
|
+
scheduleLifecycle(fiber, () => {
|
|
696
|
+
const cleanup = ref(value);
|
|
697
697
|
fiber.cleanups ||= [];
|
|
698
|
-
fiber.cleanups.push(cleanup);
|
|
699
|
-
}
|
|
700
|
-
fiber.cleanups ||= [];
|
|
701
|
-
fiber.cleanups.push(() => ref(null));
|
|
702
|
-
}
|
|
698
|
+
fiber.cleanups.push(typeof cleanup === "function" ? cleanup : () => ref(null));
|
|
699
|
+
});
|
|
703
700
|
} else {
|
|
704
701
|
ref.current = value;
|
|
705
702
|
}
|
|
@@ -710,12 +707,7 @@ function syncRefIfChanged(fiber, value) {
|
|
|
710
707
|
if (typeof ref === "object" && ref.current !== value) ref.current = value;
|
|
711
708
|
}
|
|
712
709
|
function detachRef(ref) {
|
|
713
|
-
if (typeof ref === "
|
|
714
|
-
try {
|
|
715
|
-
ref(null);
|
|
716
|
-
} catch {
|
|
717
|
-
}
|
|
718
|
-
} else if (ref && typeof ref === "object") {
|
|
710
|
+
if (ref && typeof ref === "object") {
|
|
719
711
|
ref.current = null;
|
|
720
712
|
}
|
|
721
713
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dom/reconcile.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n FiberTag,\n FiberFlag,\n createFiber,\n REACT_ELEMENT_TYPE,\n REACT_LEGACY_ELEMENT_TYPE,\n REACT_FRAGMENT_TYPE,\n type Fiber,\n type FiberRoot,\n type ReactElement,\n type ReactNode,\n type Hook,\n type Effect,\n} from '../core'\nimport {\n ReactSharedInternals,\n REACT_LAZY_TYPE,\n REACT_STRICT_MODE_TYPE,\n REACT_PROFILER_TYPE,\n} from '../react'\nimport { createHostNode, setProp } from './dom'\nimport { makeDispatcher } from './dispatcher'\nimport {\n adoptHostDom,\n adoptTextDom,\n tryConsumeBoundary,\n advanceCursorPast,\n setHydrationCursor,\n getHydrationCursor,\n clearHydrationCursor,\n HydrationCursor,\n findHostParent as findHydrationHost,\n} from './features/hydration'\n\n// ---------------------------------------------------------------------------\n// Render scheduling\n// ---------------------------------------------------------------------------\n\nlet currentRoot: FiberRoot | null = null\nlet flushing = false\nlet isBatching = false\nconst pendingRoots = new Set<FiberRoot>()\n\n// Set by rerenderFiber to identify the exact memo-tagged fiber whose INTERNAL\n// state (hook update, useSyncExternalStore notification) triggered this render\n// pass. renderMemo checks this to bypass its prop-equality gate for that fiber.\n// Without the bypass, a memo bail would swallow state changes: React's memo is\n// only a parent-triggered gate \u2014 state-driven rerenders must always run the\n// inner function. Router-adjacent components (Outlet, Match, MatchInner) are\n// all memo-wrapped and subscribe to stores; missing this bypass breaks nav\n// content updates even though the URL changes.\nlet forceRerenderingFiber: Fiber | null = null\n\nexport function scheduleUpdate(fiber: Fiber): void {\n // Drop updates scheduled on already-unmounted fibers. Subscribers (router,\n // query, any external store) can fire after unmount if their cleanup was\n // missed, and letting those reach rerenderFiber mounts zombie DOM into the\n // old .parent's DOM (which stays reachable via the stale pointer).\n if (fiber.unmounted) return\n const root = findRoot(fiber)\n if (!root) return\n root.pending.add(fiber)\n fiber.dirty = true\n pendingRoots.add(root)\n if (isBatching) return\n if (!root.scheduled) {\n root.scheduled = true\n queueMicrotask(flushPending)\n }\n}\n\nexport function flushSyncWork(fn: () => void): void {\n const wasBatching = isBatching\n isBatching = true\n try {\n fn()\n } finally {\n isBatching = wasBatching\n }\n flushPending()\n}\n\nexport function batchedUpdates<T>(fn: () => T): T {\n const wasBatching = isBatching\n isBatching = true\n try {\n return fn()\n } finally {\n isBatching = wasBatching\n if (!wasBatching) flushPending()\n }\n}\n\nfunction flushPending(): void {\n if (flushing) return\n flushing = true\n try {\n let guard = 0\n while (pendingRoots.size > 0) {\n if (++guard > 50) {\n throw new Error('flushPending exceeded 50 iterations \u2014 suspected infinite update loop.')\n }\n const roots = [...pendingRoots]\n pendingRoots.clear()\n for (const root of roots) {\n root.scheduled = false\n // Render each pending fiber from shallowest first so an ancestor's\n // cascade reaches descendants before we try to render them directly.\n // Descendants rendered via cascade still have `dirty=true` (only\n // rerenderFiber clears it); when we later reach them in this loop,\n // rerenderFiber's own `if (!dirty) return` is our short-circuit. We\n // previously filtered descendants of dirty ancestors here, but that\n // loses updates whenever an ancestor's render doesn't actually reach\n // the descendant \u2014 e.g. React.memo bailing on equal props. Keep all\n // dirty fibers and let rerenderFiber de-dupe via its dirty check.\n const pending = [...root.pending]\n root.pending.clear()\n pending.sort((a, b) => fiberDepth(a) - fiberDepth(b))\n for (const fiber of pending) {\n rerenderFiber(fiber, root)\n }\n runEffects(root)\n }\n }\n } finally {\n flushing = false\n }\n}\n\nfunction fiberDepth(fiber: Fiber): number {\n let d = 0\n let p: Fiber | null = fiber.parent\n while (p) {\n d++\n p = p.parent\n }\n return d\n}\n\nexport function findRoot(fiber: Fiber): FiberRoot | null {\n let f: Fiber | null = fiber\n while (f) {\n if (f.root) return f.root\n f = f.parent\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Entry points (called by createRoot)\n// ---------------------------------------------------------------------------\n\nexport function renderRoot(root: FiberRoot, children: ReactNode): void {\n const rootFiber = root.current\n rootFiber.pendingProps = { children }\n currentRoot = root\n try {\n reconcileChildren(rootFiber, childrenToArray(children), root.container as Node, null)\n rootFiber.memoizedProps = rootFiber.pendingProps\n rootFiber.dirty = false\n } finally {\n currentRoot = null\n }\n runEffects(root)\n}\n\nfunction rerenderFiber(fiber: Fiber, root: FiberRoot): void {\n if (!fiber.dirty) return\n // Skip fibers that were unmounted between scheduling and flush. Without this,\n // the flush loop re-enters a zombie fiber whose .parent is still set; its\n // render mounts fresh DOM into the old parent's still-attached DOM (since\n // unmountFiber only clears fiber.child, not fiber.parent). Visible as route\n // content from a previous location staying on screen after nav, because a\n // pending rerender on the old route's LibraryLandingPage (unmounted during\n // Outlet's shallow-first render) still fires from root.pending.\n if (fiber.unmounted) return\n // Clear BEFORE rendering so a scheduleUpdate() triggered mid-render (e.g.\n // error boundary catching a descendant throw) marks us dirty for the next\n // flush iteration instead of being wiped out when render() completes.\n fiber.dirty = false\n currentRoot = root\n // If this rerender is resuming a hydration that was deferred by a suspension,\n // re-activate hydration mode for its duration so descendants adopt DOM\n // instead of re-creating it.\n const resumeHydration =\n fiber.memoizedState && (fiber.memoizedState as any)._pendingHydration === true\n const prevHydrating = root.hydrating\n if (resumeHydration) {\n delete (fiber.memoizedState as any)._pendingHydration\n root.hydrating = true\n }\n const prevForcing = forceRerenderingFiber\n forceRerenderingFiber = fiber\n try {\n renderFiber(fiber, getHostParent(fiber), getAnchor(fiber))\n } finally {\n forceRerenderingFiber = prevForcing\n if (resumeHydration) {\n root.hydrating = prevHydrating\n // Deferred hydration completed \u2014 detach the preserved cursor so future\n // updates (post-hydration state changes) don't try to adopt stale DOM.\n clearHydrationCursor(fiber)\n }\n currentRoot = null\n }\n}\n\n// ---------------------------------------------------------------------------\n// Element \u2192 children normalization\n// ---------------------------------------------------------------------------\n\ntype TextChild = { _text: string }\ntype NormalizedChild = ReactElement | TextChild | null\n\n// NEVER use `'_text' in child` to distinguish text wrappers from elements.\n// TanStack's RSC renderable proxies (createRscProxy with renderable: true) are\n// Proxy wrappers around real React elements whose `has` trap returns `true`\n// for ANY string key \u2014 so `'_text' in rscProxy` is TRUE even though the proxy\n// is an element. That misidentification set a Text fiber's `pendingProps` to\n// `child._text` (another chained RSC proxy), which then rendered as\n// `[object Object]` when createTextNode stringified the element. React\n// elements always carry `$$typeof`; our text wrapper never does \u2014 so the\n// presence of `$$typeof` is the invariant we rely on.\nfunction isTextChild(child: Exclude<NormalizedChild, null>): child is TextChild {\n return (child as any).$$typeof === undefined\n}\n\nexport function childrenToArray(children: ReactNode): NormalizedChild[] {\n const out: NormalizedChild[] = []\n pushChildren(children, out)\n return out\n}\n\nfunction pushChildren(node: ReactNode, out: NormalizedChild[]): void {\n if (node == null || typeof node === 'boolean') return\n if (typeof node === 'string' || typeof node === 'number') {\n // Empty strings render no text node (matches React + the `<!-- -->`\n // separator elision on the SSR side so server/client agree).\n if (node === '') return\n out.push({ _text: '' + node })\n return\n }\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) pushChildren(node[i], out)\n return\n }\n if (isIterable(node)) {\n for (const item of node as Iterable<ReactNode>) pushChildren(item, out)\n return\n }\n if (typeof node === 'object') {\n const t = (node as any).$$typeof\n if (ACCEPTED_ELEMENT_MARKERS.has(t)) {\n out.push(node as ReactElement)\n return\n }\n // Raw React.lazy as a child. RSC Flight encodes 'use client' components\n // (CodeBlock, CodeExplorer, etc.) as bare Lazy objects in the tree, not\n // wrapped in REACT_ELEMENT_TYPE. Dropping them made code snippets\n // disappear from docs pages. The RSC decoder pre-awaits payloads via\n // `awaitLazyElements`, so by render time the status is 'fulfilled' and\n // `_init()` returns the resolved element synchronously.\n if (t === REACT_LAZY_TYPE) {\n const lazy = node as any\n const resolved = lazy._init(lazy._payload)\n pushChildren(resolved, out)\n return\n }\n }\n}\n\nfunction isIterable(obj: any): boolean {\n return obj != null && typeof obj !== 'string' && typeof obj[Symbol.iterator] === 'function'\n}\n\nfunction getKeyOf(child: NormalizedChild, index: number): string {\n if (!child) return 'n' + index\n if (isTextChild(child)) return '$t' + index\n if (child.key != null) return 'k' + child.key\n return 'i' + index\n}\n\nfunction sameType(fiber: Fiber, child: NormalizedChild): boolean {\n if (!child) return false\n if (isTextChild(child)) return fiber.tag === FiberTag.Text\n return fiber.type === child.type && sameKey(fiber.key, child.key)\n}\n\nfunction sameKey(a: string | null, b: string | null | undefined): boolean {\n return (a ?? null) === (b ?? null)\n}\n\n// ---------------------------------------------------------------------------\n// Fiber creation\n// ---------------------------------------------------------------------------\n\nfunction fiberFromChild(child: NormalizedChild, parent: Fiber): Fiber {\n if (!child) return createFiber(FiberTag.Fragment, null, null)\n if (isTextChild(child)) {\n const f = createFiber(FiberTag.Text, null, null)\n f.pendingProps = child._text\n f.parent = parent\n return f\n }\n const type = child.type\n let tag: FiberTag = FiberTag.Host\n const marker = type && (type as any).$$typeof\n if (typeof type === 'string') tag = FiberTag.Host\n else if (type === REACT_FRAGMENT_TYPE) tag = FiberTag.Fragment\n else if (type === REACT_STRICT_MODE_TYPE || type === REACT_PROFILER_TYPE) tag = FiberTag.Fragment\n else {\n // Feature-registered type matchers (Portal, future extractions). Features\n // that carry the symbol as element.type directly (rather than wrapping in\n // REACT_ELEMENT_TYPE) match here by type identity.\n let matched: FiberTag | null = null\n for (const m of TYPE_MATCHERS) {\n matched = m(type, marker)\n if (matched !== null) break\n }\n if (matched !== null) tag = matched\n else if (typeof type === 'function') {\n tag = type.prototype && type.prototype.isReactComponent ? FiberTag.Class : FiberTag.Function\n }\n }\n const f = createFiber(tag, type, child.key ?? null)\n f.ref = (child as any).ref ?? null\n f.pendingProps = child.props\n f.parent = parent\n return f\n}\n\n// ---------------------------------------------------------------------------\n// Reconciliation\n// ---------------------------------------------------------------------------\n\n/**\n * Reconcile a parent fiber's child list against new normalized children.\n * Mutates parent.child and the sibling chain.\n * Mounts new host DOM into `domParent` before `anchor` (or appends if anchor === null).\n */\nexport function reconcileChildren(\n parent: Fiber,\n newChildren: NormalizedChild[],\n domParent: Node,\n anchor: Node | null,\n): void {\n const existing = collectChildren(parent)\n const keyed = new Map<string, Fiber>()\n for (const f of existing) {\n if (f.key != null) keyed.set('k' + f.key, f)\n }\n\n let prevNewFiber: Fiber | null = null\n const claimed = new Set<Fiber>()\n let structurallyChanged = false\n // Budget-guided positional matching. We walk `existing` (unkeyed only) with a\n // single cursor `existingIdx` and, on a type mismatch, choose insert vs delete\n // based on the remaining length delta (`budget`):\n // budget > 0: more new than old remain \u2192 treat slot as an INSERTION: keep\n // the old cursor and create a fresh fiber for new[i].\n // budget < 0: more old than new remain \u2192 treat slot as a DELETION: advance\n // the old cursor past the mismatched fiber (it'll be unmounted\n // in the unclaimed pass) and retry.\n // budget == 0: equal remaining \u2192 treat as REPLACE by preferring delete\n // until budget flips positive or we hit a match.\n // This avoids greedy forward scans that steal a later same-type fiber for a\n // newly inserted leading sibling (e.g. smallMenu flipping null \u2192 <div>\n // stealing the content <div>'s fiber and tearing down the drawer fragment).\n let existingIdx = 0\n let unkeyedOld = 0\n for (const f of existing) if (f.key == null) unkeyedOld++\n let unkeyedNew = 0\n for (const c of newChildren) if (c != null) unkeyedNew++\n let budget = unkeyedNew - unkeyedOld\n\n for (let i = 0; i < newChildren.length; i++) {\n const child = newChildren[i]\n if (child == null) continue\n\n let match: Fiber | null = null\n\n // key-based match\n if (child && typeof child === 'object' && !isTextChild(child) && (child as ReactElement).key != null) {\n const k = 'k' + (child as ReactElement).key\n const m = keyed.get(k)\n if (m && m.type === (child as ReactElement).type) {\n match = m\n keyed.delete(k)\n }\n }\n\n if (!match) {\n while (existingIdx < existing.length) {\n const cand = existing[existingIdx]!\n if (claimed.has(cand) || cand.key != null) {\n existingIdx++\n continue\n }\n if (sameType(cand, child)) {\n match = cand\n existingIdx++\n break\n }\n // Type mismatch at the cursor. Resolve via budget.\n if (budget > 0) {\n // Insertion: leave cand in place, create new for child.\n break\n }\n // Deletion (or replace-as-delete-first): advance past cand. It remains\n // unclaimed and will be unmounted at the end.\n existingIdx++\n budget++\n }\n }\n\n // Detect reorder: matched fiber is not at its original position\n if (match && existing[i] !== match) structurallyChanged = true\n\n let fiber: Fiber\n if (match) {\n claimed.add(match)\n fiber = match\n if (isTextChild(child!)) {\n fiber.pendingProps = child._text\n } else {\n fiber.type = (child as ReactElement).type\n fiber.pendingProps = (child as ReactElement).props\n fiber.ref = (child as any).ref ?? null\n }\n } else {\n fiber = fiberFromChild(child, parent)\n structurallyChanged = true\n if (budget > 0) budget--\n }\n\n fiber.parent = parent\n fiber.sibling = null\n if (prevNewFiber) prevNewFiber.sibling = fiber\n else parent.child = fiber\n prevNewFiber = fiber\n\n // Render this fiber (mount or update)\n renderFiber(fiber, domParent, anchor)\n }\n\n if (!prevNewFiber) parent.child = null\n else prevNewFiber.sibling = null\n\n // Head content is additive \u2014 server may inject metadata/stylesheets (Vite\n // dev styles, Sentry, analytics) that aren't in the React tree. Unmounting\n // them on every reconcile thrashes styles and causes flash of unstyled\n // content. Keep existing head children that weren't matched this pass.\n const parentIsHeadHost =\n parent.tag === FiberTag.Host &&\n typeof parent.type === 'string' &&\n (parent.type as string).toLowerCase() === 'head'\n\n if (!parentIsHeadHost) {\n // Unmount unclaimed\n for (const f of existing) {\n if (!claimed.has(f)) {\n unmountFiber(f, domParent)\n structurallyChanged = true\n }\n }\n // Leftover keyed\n for (const f of keyed.values()) {\n if (!claimed.has(f)) {\n unmountFiber(f, domParent)\n structurallyChanged = true\n }\n }\n }\n\n // During hydration, DOM is already in document order from the cursor-driven\n // adoption walk. Running placeChildrenInOrder here would reappend nodes to\n // the end of domParent when the true anchor (often an end marker comment)\n // isn't reflected in `anchor`. Skip it in hydration mode.\n //\n // For <head>, skip always \u2014 HeadContent re-renders routinely (route match\n // changes, providers updating), and reordering every <link>/<style>/<meta>\n // on each re-render causes stylesheet flash and re-download. Head element\n // ordering is semantically fluid; the browser doesn't care about exact\n // order within <head>.\n const parentIsHead =\n (domParent as Element).nodeType === 1 &&\n (domParent as Element).tagName.toLowerCase() === 'head'\n if (structurallyChanged && !currentRoot?.hydrating && !parentIsHead) {\n placeChildrenInOrder(parent, domParent, anchor)\n }\n}\n\nfunction placeChildrenInOrder(parent: Fiber, domParent: Node, anchor: Node | null): void {\n const doms: Node[] = []\n let c = parent.child\n while (c) {\n collectHostDoms(c, doms)\n c = c.sibling\n }\n\n // Pre-check: if our fiber-owned DOM is already in document order within\n // domParent AND the end anchor matches, no reorder is needed. This is the\n // common case on stable re-renders, and avoids detaching/re-attaching\n // subtrees (which cancels CSS animations and triggers layout).\n if (doms.length > 0) {\n let current: Node | null = doms[0]!\n let inOrder = current.parentNode === domParent\n for (let i = 1; inOrder && i < doms.length; i++) {\n current = current!.nextSibling\n // Skip foreign nodes (SSR-injected scripts, dev-styles) between owned\n // fiber DOMs \u2014 they should stay where they are.\n while (current && !doms.includes(current as Node)) {\n current = current.nextSibling\n }\n if (current !== doms[i]) inOrder = false\n }\n if (inOrder) return\n }\n\n // Reverse-iterate, anchoring each node before the one that should follow it.\n // This works because by the time we're placing doms[i], doms[i+1] is already\n // in its final slot. Forward iteration is buggy: insertBefore(doms[i],\n // doms[i+1]) pulls doms[i] forward past any nodes that SHOULD move behind\n // it, leaving those nodes mis-anchored (app-starter Analyze/Lucky swap, npm\n // stats library dropdown reorder \u2014 both reported by users).\n //\n // Concrete example: start=[A, R, L], target=[A, L, R]. Forward pass gives\n // [L, A, R] (wrong). Reverse pass moves R to end, then L and A are already\n // correct \u2014 1 move, matches target.\n //\n // Skip nodes already in their target position so CSS transitions on stable\n // siblings aren't cancelled (e.g. drawer slide animation).\n for (let i = doms.length - 1; i >= 0; i--) {\n const d = doms[i]!\n const targetNext: Node | null = i + 1 < doms.length ? doms[i + 1]! : anchor\n if (d.parentNode !== domParent || d.nextSibling !== targetNext) {\n domParent.insertBefore(d, targetNext)\n }\n }\n}\n\nfunction collectHostDoms(fiber: Fiber, out: Node[]): void {\n if (fiber.tag === FiberTag.Host || fiber.tag === FiberTag.Text) {\n if (fiber.dom) out.push(fiber.dom)\n return\n }\n if (fiber.tag === FiberTag.Portal) return\n let c = fiber.child\n while (c) {\n collectHostDoms(c, out)\n c = c.sibling\n }\n}\n\nfunction collectChildren(parent: Fiber): Fiber[] {\n const out: Fiber[] = []\n let c = parent.child\n while (c) {\n out.push(c)\n c = c.sibling\n }\n return out\n}\n\n// ---------------------------------------------------------------------------\n// Rendering per fiber tag\n// ---------------------------------------------------------------------------\n\nexport type RenderFn = (fiber: Fiber, domParent: Node, anchor: Node | null) => void\nexport type TypeMatcher = (type: any, marker: any) => FiberTag | null\n\n// Mutable renderer registry indexed by FiberTag. Feature modules install their\n// renderer via registerRenderer(); unregistered features render as no-ops. The\n// initial registrations below rely on function-declaration hoisting \u2014 every\n// render* function is declared with `function` later in this file.\nconst RENDERERS: Array<RenderFn | undefined> = new Array(13)\n\n// Element-marker allowlist for child normalization (pushChildren). Core-always\n// markers are seeded here; features add their own via registerElementMarker.\nconst ACCEPTED_ELEMENT_MARKERS = new Set<symbol>([\n REACT_ELEMENT_TYPE as symbol,\n REACT_LEGACY_ELEMENT_TYPE as symbol,\n])\n\n// Type-to-tag matchers tried in registration order from fiberFromChild's\n// fallback branch. Features register here for element types that aren't\n// marker-based (e.g. Portal, where element.type IS the symbol).\nconst TYPE_MATCHERS: TypeMatcher[] = []\n\nexport function registerRenderer(tag: FiberTag, fn: RenderFn): void {\n RENDERERS[tag] = fn\n}\n\nexport function registerTypeMatcher(m: TypeMatcher): void {\n TYPE_MATCHERS.push(m)\n}\n\nexport function registerElementMarker(sym: symbol): void {\n ACCEPTED_ELEMENT_MARKERS.add(sym)\n}\n\n// Accessor + scoped setter for the module-level `currentRoot`. Feature modules\n// need these to participate in the render loop (e.g. Suspense re-hydration\n// must temporarily set the root while rebuilding a boundary subtree).\nexport function getCurrentRoot(): FiberRoot | null {\n return currentRoot\n}\n\nexport function withCurrentRoot<T>(root: FiberRoot | null, fn: () => T): T {\n const prev = currentRoot\n currentRoot = root\n try {\n return fn()\n } finally {\n currentRoot = prev\n }\n}\n\n// The memo feature uses this to bypass its prop-equality gate on state-driven\n// rerenders of the memoized fiber itself (hook update / subscribed store),\n// where props haven't changed by definition.\nexport function getForceRerenderingFiber(): Fiber | null {\n return forceRerenderingFiber\n}\n\nregisterRenderer(FiberTag.Text, renderText)\nregisterRenderer(FiberTag.Host, renderHost)\nregisterRenderer(FiberTag.Function, renderFunction)\nregisterRenderer(FiberTag.Fragment, renderFragment)\n\nexport function renderFiber(fiber: Fiber, domParent: Node, anchor: Node | null): void {\n const fn = RENDERERS[fiber.tag]\n if (fn) fn(fiber, domParent, anchor)\n}\n\nfunction renderText(fiber: Fiber, domParent: Node, anchor: Node | null): void {\n const text = fiber.pendingProps as string\n if (!fiber.dom) {\n const hydrated = currentRoot?.hydrating ? adoptTextDom(fiber, fiber.parent!, text) : false\n if (!hydrated) {\n fiber.dom = document.createTextNode(text)\n insertInto(domParent, fiber.dom, anchor)\n }\n } else if ((fiber.dom as Text).data !== text) {\n ;(fiber.dom as Text).data = text\n }\n fiber.memoizedProps = text\n // dirty cleared at rerender start; leaving true lets mid-render schedule persist\n}\n\nfunction renderHost(fiber: Fiber, domParent: Node, anchor: Node | null): void {\n const props = fiber.pendingProps ?? {}\n const prev = fiber.memoizedProps ?? {}\n const type = fiber.type as string\n const isSvg = type === 'svg' || (domParent as Element).namespaceURI === 'http://www.w3.org/2000/svg'\n\n // <select value> must be applied AFTER children mount \u2014 setting `.value`\n // on a `<select>` with no matching `<option>` yet resets it to empty. Same\n // for `defaultValue` on first mount. Stash and replay.\n const isSelect = type === 'select'\n const deferredSelectValue =\n isSelect && (props.value !== undefined || props.defaultValue !== undefined)\n ? props.value !== undefined ? props.value : props.defaultValue\n : undefined\n\n if (!fiber.dom) {\n const hydrated = currentRoot?.hydrating ? adoptHostDom(fiber, fiber.parent!) : false\n if (!hydrated) {\n fiber.dom = createHostNode(type, isSvg)\n // Two passes so form-control attributes (notably <input type>) are in\n // place before event handlers attach. setEventHandler reads the\n // element's runtime state to decide the DOM event name (e.g. onChange\n // \u2192 `input` vs `change`); binding before `type` is applied would\n // attach to the wrong event for checkbox/radio/file inputs.\n for (const k in props) {\n if (isSelect && (k === 'value' || k === 'defaultValue')) continue\n if (isEventProp(k)) continue\n setProp(fiber.dom as Element, k, props[k], undefined, isSvg)\n }\n for (const k in props) {\n if (!isEventProp(k)) continue\n setProp(fiber.dom as Element, k, props[k], undefined, isSvg)\n }\n insertInto(domParent, fiber.dom, anchor)\n }\n attachRef(fiber, fiber.dom)\n } else {\n const el = fiber.dom as Element\n for (const k in prev) {\n if (!(k in props)) setProp(el, k, undefined, prev[k], isSvg)\n }\n // Non-event props first for the same reason as above: a `type` change\n // must land before we ask setEventHandler to resolve the DOM event for\n // `onChange`.\n for (const k in props) {\n if (isSelect && (k === 'value' || k === 'defaultValue')) continue\n if (isEventProp(k)) continue\n if (prev[k] !== props[k]) setProp(el, k, props[k], prev[k], isSvg)\n }\n for (const k in props) {\n if (!isEventProp(k)) continue\n if (prev[k] !== props[k]) setProp(el, k, props[k], prev[k], isSvg)\n }\n if (prev !== props) syncRefIfChanged(fiber, fiber.dom)\n }\n\n // Children go into this DOM node\n reconcileChildren(fiber, childrenToArray(props.children), fiber.dom!, null)\n\n // During hydration, if after reconciling all client-expected children we\n // still have server DOM left in the cursor for this host, that's a\n // structural mismatch (server produced more than client wants). Report.\n // <head>/<html> are position-insensitive \u2014 leftover here is normal\n // (Vite dev-style injections, SSR-only scripts, etc.).\n if (currentRoot?.hydrating) {\n const parentTag = (fiber.type as string).toLowerCase()\n if (parentTag !== 'head' && parentTag !== 'html') {\n const cursor = getHydrationCursor(fiber)\n if (cursor) {\n const leftover = cursor.remaining().filter(\n (n) => n.nodeType === 1 || n.nodeType === 3,\n )\n if (leftover.length > 0 && currentRoot.onRecoverableError) {\n currentRoot.onRecoverableError(\n new Error(\n `Hydration mismatch: server rendered ${leftover.length} extra ` +\n `${leftover.length === 1 ? 'node' : 'nodes'} inside <${parentTag}> ` +\n `that the client tree did not.`,\n ),\n )\n for (const n of leftover) n.parentNode?.removeChild(n)\n }\n }\n }\n }\n\n // Apply <select> value after options are mounted.\n if (isSelect && deferredSelectValue !== undefined) {\n const select = fiber.dom as HTMLSelectElement\n if (Array.isArray(deferredSelectValue)) {\n const asStrings = deferredSelectValue.map((v) => '' + v)\n for (const opt of Array.from(select.options)) {\n opt.selected = asStrings.includes(opt.value)\n }\n } else {\n select.value = '' + deferredSelectValue\n }\n }\n\n fiber.memoizedProps = props\n // dirty cleared at rerender start; leaving true lets mid-render schedule persist\n}\n\nfunction renderFunction(fiber: Fiber, domParent: Node, anchor: Node | null): void {\n const prevDispatcher = ReactSharedInternals.H\n const prevFiber = ReactSharedInternals.currentFiber\n const prevHook = ReactSharedInternals.currentHook\n const prevIndex = ReactSharedInternals.hookIndex\n\n ReactSharedInternals.H = makeDispatcher()\n ReactSharedInternals.currentFiber = fiber\n ReactSharedInternals.currentHook = null\n ReactSharedInternals.hookIndex = 0\n\n let rendered: ReactNode\n let deferredForHydration = false\n try {\n rendered = (fiber.type as Function)(fiber.pendingProps ?? {})\n } catch (e: any) {\n if (isThenable(e)) {\n if (currentRoot?.hydrating) {\n // Suspension during initial hydration. Leave the existing DOM alone\n // and preserve the in-scope hydration cursor on THIS fiber so it\n // survives the synchronous endHydration() that fires when the initial\n // hydrateRoot() call returns. When the promise settles, the fiber\n // re-renders (see rerenderFiber) with hydration re-activated and its\n // descendants adopt DOM instead of creating new nodes.\n const hostParent = findHydrationHost(fiber)\n const inheritedCursor = getHydrationCursor(hostParent)\n if (inheritedCursor) {\n setHydrationCursor(fiber, inheritedCursor)\n }\n fiber.memoizedState = {\n ...(fiber.memoizedState ?? {}),\n _pendingHydration: true,\n }\n // Mirror renderLazy's guard: mark the nearest Suspense ancestor as\n // awaiting hydration-resume, so any re-render of that Suspense (e.g.\n // rehydrateBoundary fired by $RC, or an unrelated state update from a\n // sibling) doesn't re-enter `tryChildren`, re-throw, and flip Suspense\n // into its suspended+pending path \u2014 which would unmount our deferred\n // subtree and remount a fallback on top of the SSR content. By\n // pinning the Suspense to a \"hydration-suspended\" no-op until our\n // resume fires, the deferred re-render owns the adoption pass.\n let sus: Fiber | null = fiber.parent\n while (sus && sus.tag !== FiberTag.Suspense) sus = sus.parent\n if (sus && sus.memoizedState) {\n ;(sus.memoizedState as any)._awaitingLazyHydration = true\n }\n const clearAwait = () => {\n if (sus && sus.memoizedState) {\n ;(sus.memoizedState as any)._awaitingLazyHydration = false\n }\n scheduleUpdate(fiber)\n }\n e.then(clearAwait, clearAwait)\n deferredForHydration = true\n } else {\n CAPABILITIES.handleSuspended(fiber, e)\n rendered = null\n }\n } else {\n handleErrorInRender(fiber, e)\n return\n }\n } finally {\n ReactSharedInternals.H = prevDispatcher\n ReactSharedInternals.currentFiber = prevFiber\n ReactSharedInternals.currentHook = prevHook\n ReactSharedInternals.hookIndex = prevIndex\n }\n\n if (deferredForHydration) return\n\n reconcileChildren(fiber, childrenToArray(rendered), domParent, anchor)\n fiber.memoizedProps = fiber.pendingProps\n // dirty cleared at rerender start; leaving true lets mid-render schedule persist\n}\n\nfunction hasAncestorHydrationCursor(_fiber: Fiber): boolean {\n // Reserved for future per-Suspense-boundary hydration deferral. For now the\n // top-level hydration path is all we need to special-case.\n return false\n}\n\nfunction renderFragment(fiber: Fiber, domParent: Node, anchor: Node | null): void {\n const props = fiber.pendingProps ?? {}\n reconcileChildren(fiber, childrenToArray(props.children), domParent, anchor)\n fiber.memoizedProps = props\n // dirty cleared at rerender start; leaving true lets mid-render schedule persist\n}\n\n// ---------------------------------------------------------------------------\n// Error handling + default Suspense capability\n// ---------------------------------------------------------------------------\n\n// Default handler when the Suspense feature isn't installed: just schedule\n// a re-render when the thrown thenable settles. No boundary walk, no\n// fallback swap \u2014 children render empty during the pending window.\nfunction defaultHandleSuspended(fiber: Fiber, thenable: Promise<any>): void {\n thenable.then(\n () => scheduleUpdate(fiber),\n () => scheduleUpdate(fiber),\n )\n}\n\n// ---------------------------------------------------------------------------\n// Capability hooks \u2014 cross-cutting behaviors that features override.\n// Defaults here preserve today's behavior so the indirection is transparent\n// when all features are loaded. A feature's full-module can install its own\n// implementation via installCapability(); stubs leave the default in place,\n// where the default may intentionally degrade (e.g. a no-Context build's\n// readContext never walks the tree because no Provider fibers exist).\n// ---------------------------------------------------------------------------\n\nexport interface Capabilities {\n handleSuspended: (fiber: Fiber, thenable: Promise<any>) => void\n readContext: (fiber: Fiber, ctx: any) => any\n}\n\nconst CAPABILITIES: Capabilities = {\n handleSuspended: defaultHandleSuspended,\n readContext: defaultReadContext,\n}\n\nexport function installCapability<K extends keyof Capabilities>(\n name: K,\n fn: Capabilities[K],\n): void {\n CAPABILITIES[name] = fn\n}\n\n// Wrapper for features that catch thrown thenables inside their render\n// functions. Delegates to the installed Suspense capability.\nexport function handleSuspended(fiber: Fiber, thenable: Promise<any>): void {\n CAPABILITIES.handleSuspended(fiber, thenable)\n}\n\nexport function handleErrorInRender(fiber: Fiber, err: any): void {\n // Bubble to nearest class boundary with getDerivedStateFromError / componentDidCatch\n let f: Fiber | null = fiber.parent\n while (f) {\n if (f.tag === FiberTag.Class) {\n const Ctor = f.type as any\n const instance = f.stateNode\n if (Ctor.getDerivedStateFromError) {\n const update = Ctor.getDerivedStateFromError(err)\n instance.state = { ...instance.state, ...update }\n }\n if (instance.componentDidCatch) {\n try {\n instance.componentDidCatch(err, { componentStack: '' })\n } catch {}\n }\n scheduleUpdate(f)\n return\n }\n f = f.parent\n }\n // No boundary \u2014 report to root\n if (currentRoot?.onUncaughtError) currentRoot.onUncaughtError(err)\n else throw err\n}\n\nexport function isThenable(x: any): x is Promise<any> {\n return x != null && typeof x.then === 'function'\n}\n\n// ---------------------------------------------------------------------------\n// Unmount\n// ---------------------------------------------------------------------------\n\nfunction unmountFiber(fiber: Fiber, domParent: Node): void {\n fiber.unmounted = true\n // Recurse first\n let c = fiber.child\n while (c) {\n const next = c.sibling\n unmountFiber(c, fiber.tag === FiberTag.Host ? fiber.dom! : domParent)\n c = next\n }\n fiber.child = null\n\n // Run cleanups (effects + layout effects)\n if (fiber.cleanups) {\n for (const cleanup of fiber.cleanups) {\n try {\n cleanup()\n } catch (e) {\n if (currentRoot?.onRecoverableError) currentRoot.onRecoverableError(e)\n }\n }\n fiber.cleanups = null\n }\n\n if (fiber.tag === FiberTag.Class && fiber.stateNode?.componentWillUnmount) {\n try {\n fiber.stateNode.componentWillUnmount()\n } catch (e) {\n if (currentRoot?.onRecoverableError) currentRoot.onRecoverableError(e)\n }\n fiber.stateNode._fiber = null\n fiber.stateNode._enqueueUpdate = null\n fiber.stateNode._forceUpdate = null\n }\n\n // Detach ref\n if (fiber.ref) detachRef(fiber.ref)\n\n // Remove DOM if host\n if (fiber.tag === FiberTag.Host && fiber.dom && fiber.dom.parentNode) {\n fiber.dom.parentNode.removeChild(fiber.dom)\n } else if (fiber.tag === FiberTag.Text && fiber.dom && fiber.dom.parentNode) {\n fiber.dom.parentNode.removeChild(fiber.dom)\n }\n}\n\nexport function unmountAllChildren(parent: Fiber, domParent: Node): void {\n let c = parent.child\n while (c) {\n const next = c.sibling\n unmountFiber(c, domParent)\n c = next\n }\n parent.child = null\n}\n\n// ---------------------------------------------------------------------------\n// DOM navigation helpers\n// ---------------------------------------------------------------------------\n\nfunction insertInto(parent: Node, node: Node, anchor: Node | null): void {\n // Anchor may have been removed or moved since it was computed (mutations\n // from unmount, boundary reveal, user code, HMR). If it's no longer a child\n // of `parent`, fall back to append \u2014 trying to insertBefore a non-child\n // throws NotFoundError and dev-loops the reconciler.\n if (anchor && anchor.parentNode === parent) {\n parent.insertBefore(node, anchor)\n } else {\n parent.appendChild(node)\n }\n}\n\nfunction getHostParent(fiber: Fiber): Node {\n let p = fiber.parent\n while (p) {\n if (p.tag === FiberTag.Host) return p.dom!\n if (p.tag === FiberTag.Root)\n return (p.stateNode as Node) || (p.dom as Node) || (p.root?.container as Node)\n if (p.tag === FiberTag.Portal) {\n // Portal renders its children into the `container` prop, not into any\n // DOM element the portal fiber \"owns\". Read the container from the\n // portal's own props so a rerenderFiber triggered on a descendant\n // (e.g. a Floating-UI-positioned popper in a Radix Portal) finds its\n // host parent \u2014 otherwise getHostParent returns undefined and the\n // next renderHost crashes reading `.namespaceURI` on undefined.\n const props = (p.pendingProps ?? p.memoizedProps) as { container?: Element } | null\n return (props?.container as Node) || (p.stateNode as Node) || (p.dom as Node) || (p.root?.container as Node)\n }\n p = p.parent\n }\n throw new Error('No host parent found.')\n}\n\nfunction getAnchor(fiber: Fiber): Node | null {\n // Return the first DOM node that comes after this fiber within the host parent\n let f: Fiber | null = fiber.sibling\n while (f) {\n const d = firstDomNode(f)\n if (d) return d\n f = f.sibling\n }\n // Ascend\n let p = fiber.parent\n while (p && p.tag !== FiberTag.Host && p.tag !== FiberTag.Root && p.tag !== FiberTag.Portal) {\n if (p.sibling) {\n const d = firstDomNode(p.sibling)\n if (d) return d\n }\n p = p.parent\n }\n return null\n}\n\nfunction firstDomNode(fiber: Fiber): Node | null {\n if (fiber.tag === FiberTag.Host || fiber.tag === FiberTag.Text) return fiber.dom\n let c = fiber.child\n while (c) {\n const d = firstDomNode(c)\n if (d) return d\n c = c.sibling\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Context read \u2014 exported for dispatcher.ts (useContext, use()). Delegates to\n// the installed capability so the Context feature can override with a walking\n// implementation that finds the nearest Provider fiber. When the feature is\n// stubbed, the default here returns ctx._currentValue \u2014 correct because no\n// Provider fibers exist in the tree (Provider element \u2192 Fragment via the\n// stub's type matcher).\n// ---------------------------------------------------------------------------\n\nexport function readContext(fiber: Fiber, ctx: any): any {\n return CAPABILITIES.readContext(fiber, ctx)\n}\n\nfunction defaultReadContext(_fiber: Fiber, ctx: any): any {\n return ctx._currentValue\n}\n\n// ---------------------------------------------------------------------------\n// Refs\n// ---------------------------------------------------------------------------\n\nfunction attachRef(fiber: Fiber, value: any): void {\n const ref = fiber.ref ?? (fiber.pendingProps?.ref ?? null)\n if (!ref) return\n if (typeof ref === 'function') {\n const cleanup = ref(value)\n if (typeof cleanup === 'function') {\n fiber.cleanups ||= []\n fiber.cleanups.push(cleanup)\n } else {\n fiber.cleanups ||= []\n fiber.cleanups.push(() => ref(null))\n }\n } else {\n ref.current = value\n }\n}\n\nfunction syncRefIfChanged(fiber: Fiber, value: any): void {\n const ref = fiber.ref ?? (fiber.pendingProps?.ref ?? null)\n if (!ref) return\n if (typeof ref === 'object' && ref.current !== value) ref.current = value\n}\n\nfunction detachRef(ref: any): void {\n if (typeof ref === 'function') {\n try {\n ref(null)\n } catch {}\n } else if (ref && typeof ref === 'object') {\n ref.current = null\n }\n}\n\n// ---------------------------------------------------------------------------\n// Effects\n// ---------------------------------------------------------------------------\n\nconst pendingEffects: Array<{ fiber: Fiber; effect: Effect }> = []\nconst pendingLayoutEffects: Array<{ fiber: Fiber; effect: Effect }> = []\nconst pendingLifecycles: Array<{ fiber: Fiber; fn: () => void }> = []\n\nexport function enqueueEffect(fiber: Fiber, effect: Effect): void {\n if (effect.tag === 'layout' || effect.tag === 'insertion') {\n pendingLayoutEffects.push({ fiber, effect })\n } else {\n pendingEffects.push({ fiber, effect })\n }\n}\n\nexport function scheduleLifecycle(fiber: Fiber, fn: () => void): void {\n pendingLifecycles.push({ fiber, fn })\n}\n\nexport function runEffects(root: FiberRoot): void {\n // Layout effects synchronously\n while (pendingLayoutEffects.length) {\n const { fiber, effect } = pendingLayoutEffects.shift()!\n runEffect(fiber, effect, root)\n }\n // Then lifecycles\n while (pendingLifecycles.length) {\n const { fn } = pendingLifecycles.shift()!\n try {\n fn()\n } catch (e) {\n if (root.onCaughtError) root.onCaughtError(e)\n }\n }\n // Passive effects on microtask\n if (pendingEffects.length) {\n const batch = pendingEffects.splice(0)\n queueMicrotask(() => {\n for (const { fiber, effect } of batch) runEffect(fiber, effect, root)\n })\n }\n}\n\nfunction runEffect(fiber: Fiber, effect: Effect, root: FiberRoot): void {\n try {\n const cleanup = effect.create()\n effect.destroy = typeof cleanup === 'function' ? cleanup : undefined\n if (effect.destroy) {\n fiber.cleanups ||= []\n fiber.cleanups.push(effect.destroy)\n }\n } catch (e) {\n if (root.onCaughtError) root.onCaughtError(e)\n }\n}\n\n// ---------------------------------------------------------------------------\n// Utilities\n// ---------------------------------------------------------------------------\n\nfunction isEventProp(name: string): boolean {\n return (\n name.length > 2 &&\n name.charCodeAt(0) === 111 /* o */ &&\n name.charCodeAt(1) === 110 /* n */ &&\n name.charCodeAt(2) >= 65 /* 'A'-ish: any uppercase start (onClick, onChange, \u2026) */\n )\n}\n\n"],
|
|
5
|
-
"mappings": ";AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAOK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,gBAAgB,eAAe;AACxC,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,kBAAkB;AAAA,OACb;AAMP,IAAI,cAAgC;AACpC,IAAI,WAAW;AACf,IAAI,aAAa;AACjB,IAAM,eAAe,oBAAI,IAAe;AAUxC,IAAI,wBAAsC;AAEnC,SAAS,eAAe,OAAoB;AAKjD,MAAI,MAAM,UAAW;AACrB,QAAM,OAAO,SAAS,KAAK;AAC3B,MAAI,CAAC,KAAM;AACX,OAAK,QAAQ,IAAI,KAAK;AACtB,QAAM,QAAQ;AACd,eAAa,IAAI,IAAI;AACrB,MAAI,WAAY;AAChB,MAAI,CAAC,KAAK,WAAW;AACnB,SAAK,YAAY;AACjB,mBAAe,YAAY;AAAA,EAC7B;AACF;AAEO,SAAS,cAAc,IAAsB;AAClD,QAAM,cAAc;AACpB,eAAa;AACb,MAAI;AACF,OAAG;AAAA,EACL,UAAE;AACA,iBAAa;AAAA,EACf;AACA,eAAa;AACf;AAEO,SAAS,eAAkB,IAAgB;AAChD,QAAM,cAAc;AACpB,eAAa;AACb,MAAI;AACF,WAAO,GAAG;AAAA,EACZ,UAA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AG,IAAI,kBAAkB,MAAM;AACvC,QAAI;AACF,SAAG;AAAA,IACL,SAAS,GAAG;AACV,UAAI,KAAK,cAAe,MAAK,cAAc,CAAC;AAAA,IAC9C;AAAA,EACF;AAEA,MAAI,eAAe,QAAQ;AACzB,UAAM,QAAQ,eAAe,OAAO,CAAC;AACrC,mBAAe,MAAM;AACnB,iBAAW,EAAE,OAAO,OAAO,KAAK,MAAO,WAAU,OAAO,QAAQ,IAAI;AAAA,IACtE,CAAC;AAAA,EACH;AACF;AAEA,SAAS,UAAU,OAAc,QAAgB,MAAuB;AACtE,MAAI;AACF,UAAM,UAAU,OAAO,OAAO;AAC9B,WAAO,UAAU,OAAO,YAAY,aAAa,UAAU;AAC3D,QAAI,OAAO,SAAS;AAClB,YAAM,aAAa,CAAC;AACpB,YAAM,SAAS,KAAK,OAAO,OAAO;AAAA,IACpC;AAAA,EACF,SAAS,GAAG;AACV,QAAI,KAAK,cAAe,MAAK,cAAc,CAAC;AAAA,EAC9C;AACF;AAMA,SAAS,YAAY,MAAuB;AAC1C,SACE,KAAK,SAAS,KACd,KAAK,WAAW,CAAC,MAAM,OACvB,KAAK,WAAW,CAAC,MAAM,OACvB,KAAK,WAAW,CAAC,KAAK;AAE1B;",
|
|
4
|
+
"sourcesContent": ["import {\n FiberTag,\n FiberFlag,\n createFiber,\n REACT_ELEMENT_TYPE,\n REACT_LEGACY_ELEMENT_TYPE,\n REACT_FRAGMENT_TYPE,\n type Fiber,\n type FiberRoot,\n type ReactElement,\n type ReactNode,\n type Hook,\n type Effect,\n} from '../core'\nimport {\n ReactSharedInternals,\n REACT_LAZY_TYPE,\n REACT_STRICT_MODE_TYPE,\n REACT_PROFILER_TYPE,\n} from '../react'\nimport { createHostNode, setProp } from './dom'\nimport { makeDispatcher } from './dispatcher'\nimport {\n adoptHostDom,\n adoptTextDom,\n tryConsumeBoundary,\n advanceCursorPast,\n setHydrationCursor,\n getHydrationCursor,\n clearHydrationCursor,\n HydrationCursor,\n findHostParent as findHydrationHost,\n} from './features/hydration'\n\n// ---------------------------------------------------------------------------\n// Render scheduling\n// ---------------------------------------------------------------------------\n\nlet currentRoot: FiberRoot | null = null\nlet flushing = false\nlet isBatching = false\nconst pendingRoots = new Set<FiberRoot>()\n\n// Set by rerenderFiber to identify the exact memo-tagged fiber whose INTERNAL\n// state (hook update, useSyncExternalStore notification) triggered this render\n// pass. renderMemo checks this to bypass its prop-equality gate for that fiber.\n// Without the bypass, a memo bail would swallow state changes: React's memo is\n// only a parent-triggered gate \u2014 state-driven rerenders must always run the\n// inner function. Router-adjacent components (Outlet, Match, MatchInner) are\n// all memo-wrapped and subscribe to stores; missing this bypass breaks nav\n// content updates even though the URL changes.\nlet forceRerenderingFiber: Fiber | null = null\n\nexport function scheduleUpdate(fiber: Fiber): void {\n // Drop updates scheduled on already-unmounted fibers. Subscribers (router,\n // query, any external store) can fire after unmount if their cleanup was\n // missed, and letting those reach rerenderFiber mounts zombie DOM into the\n // old .parent's DOM (which stays reachable via the stale pointer).\n if (fiber.unmounted) return\n const root = findRoot(fiber)\n if (!root) return\n root.pending.add(fiber)\n fiber.dirty = true\n pendingRoots.add(root)\n if (isBatching) return\n if (!root.scheduled) {\n root.scheduled = true\n queueMicrotask(flushPending)\n }\n}\n\nexport function flushSyncWork(fn: () => void): void {\n const wasBatching = isBatching\n isBatching = true\n try {\n fn()\n } finally {\n isBatching = wasBatching\n }\n flushPending()\n}\n\nexport function batchedUpdates<T>(fn: () => T): T {\n const wasBatching = isBatching\n isBatching = true\n try {\n return fn()\n } finally {\n isBatching = wasBatching\n if (!wasBatching) flushPending()\n }\n}\n\nfunction flushPending(): void {\n if (flushing) return\n flushing = true\n try {\n let guard = 0\n while (pendingRoots.size > 0) {\n if (++guard > 50) {\n throw new Error('flushPending exceeded 50 iterations \u2014 suspected infinite update loop.')\n }\n const roots = [...pendingRoots]\n pendingRoots.clear()\n for (const root of roots) {\n root.scheduled = false\n // Render each pending fiber from shallowest first so an ancestor's\n // cascade reaches descendants before we try to render them directly.\n // Descendants rendered via cascade still have `dirty=true` (only\n // rerenderFiber clears it); when we later reach them in this loop,\n // rerenderFiber's own `if (!dirty) return` is our short-circuit. We\n // previously filtered descendants of dirty ancestors here, but that\n // loses updates whenever an ancestor's render doesn't actually reach\n // the descendant \u2014 e.g. React.memo bailing on equal props. Keep all\n // dirty fibers and let rerenderFiber de-dupe via its dirty check.\n const pending = [...root.pending]\n root.pending.clear()\n pending.sort((a, b) => fiberDepth(a) - fiberDepth(b))\n for (const fiber of pending) {\n rerenderFiber(fiber, root)\n }\n runEffects(root)\n }\n }\n } finally {\n flushing = false\n }\n}\n\nfunction fiberDepth(fiber: Fiber): number {\n let d = 0\n let p: Fiber | null = fiber.parent\n while (p) {\n d++\n p = p.parent\n }\n return d\n}\n\nexport function findRoot(fiber: Fiber): FiberRoot | null {\n let f: Fiber | null = fiber\n while (f) {\n if (f.root) return f.root\n f = f.parent\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Entry points (called by createRoot)\n// ---------------------------------------------------------------------------\n\nexport function renderRoot(root: FiberRoot, children: ReactNode): void {\n const rootFiber = root.current\n rootFiber.pendingProps = { children }\n currentRoot = root\n try {\n reconcileChildren(rootFiber, childrenToArray(children), root.container as Node, null)\n rootFiber.memoizedProps = rootFiber.pendingProps\n rootFiber.dirty = false\n } finally {\n currentRoot = null\n }\n runEffects(root)\n}\n\nfunction rerenderFiber(fiber: Fiber, root: FiberRoot): void {\n if (!fiber.dirty) return\n // Skip fibers that were unmounted between scheduling and flush. Without this,\n // the flush loop re-enters a zombie fiber whose .parent is still set; its\n // render mounts fresh DOM into the old parent's still-attached DOM (since\n // unmountFiber only clears fiber.child, not fiber.parent). Visible as route\n // content from a previous location staying on screen after nav, because a\n // pending rerender on the old route's LibraryLandingPage (unmounted during\n // Outlet's shallow-first render) still fires from root.pending.\n if (fiber.unmounted) return\n // Clear BEFORE rendering so a scheduleUpdate() triggered mid-render (e.g.\n // error boundary catching a descendant throw) marks us dirty for the next\n // flush iteration instead of being wiped out when render() completes.\n fiber.dirty = false\n currentRoot = root\n // If this rerender is resuming a hydration that was deferred by a suspension,\n // re-activate hydration mode for its duration so descendants adopt DOM\n // instead of re-creating it.\n const resumeHydration =\n fiber.memoizedState && (fiber.memoizedState as any)._pendingHydration === true\n const prevHydrating = root.hydrating\n if (resumeHydration) {\n delete (fiber.memoizedState as any)._pendingHydration\n root.hydrating = true\n }\n const prevForcing = forceRerenderingFiber\n forceRerenderingFiber = fiber\n try {\n renderFiber(fiber, getHostParent(fiber), getAnchor(fiber))\n } finally {\n forceRerenderingFiber = prevForcing\n if (resumeHydration) {\n root.hydrating = prevHydrating\n // Deferred hydration completed \u2014 detach the preserved cursor so future\n // updates (post-hydration state changes) don't try to adopt stale DOM.\n clearHydrationCursor(fiber)\n }\n currentRoot = null\n }\n}\n\n// ---------------------------------------------------------------------------\n// Element \u2192 children normalization\n// ---------------------------------------------------------------------------\n\ntype TextChild = { _text: string }\ntype NormalizedChild = ReactElement | TextChild | null\n\n// NEVER use `'_text' in child` to distinguish text wrappers from elements.\n// TanStack's RSC renderable proxies (createRscProxy with renderable: true) are\n// Proxy wrappers around real React elements whose `has` trap returns `true`\n// for ANY string key \u2014 so `'_text' in rscProxy` is TRUE even though the proxy\n// is an element. That misidentification set a Text fiber's `pendingProps` to\n// `child._text` (another chained RSC proxy), which then rendered as\n// `[object Object]` when createTextNode stringified the element. React\n// elements always carry `$$typeof`; our text wrapper never does \u2014 so the\n// presence of `$$typeof` is the invariant we rely on.\nfunction isTextChild(child: Exclude<NormalizedChild, null>): child is TextChild {\n return (child as any).$$typeof === undefined\n}\n\nexport function childrenToArray(children: ReactNode): NormalizedChild[] {\n const out: NormalizedChild[] = []\n pushChildren(children, out)\n return out\n}\n\nfunction pushChildren(node: ReactNode, out: NormalizedChild[]): void {\n if (node == null || typeof node === 'boolean') return\n if (typeof node === 'string' || typeof node === 'number') {\n // Empty strings render no text node (matches React + the `<!-- -->`\n // separator elision on the SSR side so server/client agree).\n if (node === '') return\n out.push({ _text: '' + node })\n return\n }\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) pushChildren(node[i], out)\n return\n }\n if (isIterable(node)) {\n for (const item of node as Iterable<ReactNode>) pushChildren(item, out)\n return\n }\n if (typeof node === 'object') {\n const t = (node as any).$$typeof\n if (ACCEPTED_ELEMENT_MARKERS.has(t)) {\n out.push(node as ReactElement)\n return\n }\n // Raw React.lazy as a child. RSC Flight encodes 'use client' components\n // (CodeBlock, CodeExplorer, etc.) as bare Lazy objects in the tree, not\n // wrapped in REACT_ELEMENT_TYPE. Dropping them made code snippets\n // disappear from docs pages. The RSC decoder pre-awaits payloads via\n // `awaitLazyElements`, so by render time the status is 'fulfilled' and\n // `_init()` returns the resolved element synchronously.\n if (t === REACT_LAZY_TYPE) {\n const lazy = node as any\n const resolved = lazy._init(lazy._payload)\n pushChildren(resolved, out)\n return\n }\n }\n}\n\nfunction isIterable(obj: any): boolean {\n return obj != null && typeof obj !== 'string' && typeof obj[Symbol.iterator] === 'function'\n}\n\nfunction getKeyOf(child: NormalizedChild, index: number): string {\n if (!child) return 'n' + index\n if (isTextChild(child)) return '$t' + index\n if (child.key != null) return 'k' + child.key\n return 'i' + index\n}\n\nfunction sameType(fiber: Fiber, child: NormalizedChild): boolean {\n if (!child) return false\n if (isTextChild(child)) return fiber.tag === FiberTag.Text\n return fiber.type === child.type && sameKey(fiber.key, child.key)\n}\n\nfunction sameKey(a: string | null, b: string | null | undefined): boolean {\n return (a ?? null) === (b ?? null)\n}\n\n// ---------------------------------------------------------------------------\n// Fiber creation\n// ---------------------------------------------------------------------------\n\nfunction fiberFromChild(child: NormalizedChild, parent: Fiber): Fiber {\n if (!child) return createFiber(FiberTag.Fragment, null, null)\n if (isTextChild(child)) {\n const f = createFiber(FiberTag.Text, null, null)\n f.pendingProps = child._text\n f.parent = parent\n return f\n }\n const type = child.type\n let tag: FiberTag = FiberTag.Host\n const marker = type && (type as any).$$typeof\n if (typeof type === 'string') tag = FiberTag.Host\n else if (type === REACT_FRAGMENT_TYPE) tag = FiberTag.Fragment\n else if (type === REACT_STRICT_MODE_TYPE || type === REACT_PROFILER_TYPE) tag = FiberTag.Fragment\n else {\n // Feature-registered type matchers (Portal, future extractions). Features\n // that carry the symbol as element.type directly (rather than wrapping in\n // REACT_ELEMENT_TYPE) match here by type identity.\n let matched: FiberTag | null = null\n for (const m of TYPE_MATCHERS) {\n matched = m(type, marker)\n if (matched !== null) break\n }\n if (matched !== null) tag = matched\n else if (typeof type === 'function') {\n tag = type.prototype && type.prototype.isReactComponent ? FiberTag.Class : FiberTag.Function\n }\n }\n const f = createFiber(tag, type, child.key ?? null)\n f.ref = (child as any).ref ?? null\n f.pendingProps = child.props\n f.parent = parent\n return f\n}\n\n// ---------------------------------------------------------------------------\n// Reconciliation\n// ---------------------------------------------------------------------------\n\n/**\n * Reconcile a parent fiber's child list against new normalized children.\n * Mutates parent.child and the sibling chain.\n * Mounts new host DOM into `domParent` before `anchor` (or appends if anchor === null).\n */\nexport function reconcileChildren(\n parent: Fiber,\n newChildren: NormalizedChild[],\n domParent: Node,\n anchor: Node | null,\n): void {\n const existing = collectChildren(parent)\n const keyed = new Map<string, Fiber>()\n for (const f of existing) {\n if (f.key != null) keyed.set('k' + f.key, f)\n }\n\n let prevNewFiber: Fiber | null = null\n const claimed = new Set<Fiber>()\n let structurallyChanged = false\n // Budget-guided positional matching. We walk `existing` (unkeyed only) with a\n // single cursor `existingIdx` and, on a type mismatch, choose insert vs delete\n // based on the remaining length delta (`budget`):\n // budget > 0: more new than old remain \u2192 treat slot as an INSERTION: keep\n // the old cursor and create a fresh fiber for new[i].\n // budget < 0: more old than new remain \u2192 treat slot as a DELETION: advance\n // the old cursor past the mismatched fiber (it'll be unmounted\n // in the unclaimed pass) and retry.\n // budget == 0: equal remaining \u2192 treat as REPLACE by preferring delete\n // until budget flips positive or we hit a match.\n // This avoids greedy forward scans that steal a later same-type fiber for a\n // newly inserted leading sibling (e.g. smallMenu flipping null \u2192 <div>\n // stealing the content <div>'s fiber and tearing down the drawer fragment).\n let existingIdx = 0\n let unkeyedOld = 0\n for (const f of existing) if (f.key == null) unkeyedOld++\n let unkeyedNew = 0\n for (const c of newChildren) if (c != null) unkeyedNew++\n let budget = unkeyedNew - unkeyedOld\n\n for (let i = 0; i < newChildren.length; i++) {\n const child = newChildren[i]\n if (child == null) continue\n\n let match: Fiber | null = null\n\n // key-based match\n if (child && typeof child === 'object' && !isTextChild(child) && (child as ReactElement).key != null) {\n const k = 'k' + (child as ReactElement).key\n const m = keyed.get(k)\n if (m && m.type === (child as ReactElement).type) {\n match = m\n keyed.delete(k)\n }\n }\n\n if (!match) {\n while (existingIdx < existing.length) {\n const cand = existing[existingIdx]!\n if (claimed.has(cand) || cand.key != null) {\n existingIdx++\n continue\n }\n if (sameType(cand, child)) {\n match = cand\n existingIdx++\n break\n }\n // Type mismatch at the cursor. Resolve via budget.\n if (budget > 0) {\n // Insertion: leave cand in place, create new for child.\n break\n }\n // Deletion (or replace-as-delete-first): advance past cand. It remains\n // unclaimed and will be unmounted at the end.\n existingIdx++\n budget++\n }\n }\n\n // Detect reorder: matched fiber is not at its original position\n if (match && existing[i] !== match) structurallyChanged = true\n\n let fiber: Fiber\n if (match) {\n claimed.add(match)\n fiber = match\n if (isTextChild(child!)) {\n fiber.pendingProps = child._text\n } else {\n fiber.type = (child as ReactElement).type\n fiber.pendingProps = (child as ReactElement).props\n fiber.ref = (child as any).ref ?? null\n }\n } else {\n fiber = fiberFromChild(child, parent)\n structurallyChanged = true\n if (budget > 0) budget--\n }\n\n fiber.parent = parent\n fiber.sibling = null\n if (prevNewFiber) prevNewFiber.sibling = fiber\n else parent.child = fiber\n prevNewFiber = fiber\n\n // Render this fiber (mount or update)\n renderFiber(fiber, domParent, anchor)\n }\n\n if (!prevNewFiber) parent.child = null\n else prevNewFiber.sibling = null\n\n // Head content is additive \u2014 server may inject metadata/stylesheets (Vite\n // dev styles, Sentry, analytics) that aren't in the React tree. Unmounting\n // them on every reconcile thrashes styles and causes flash of unstyled\n // content. Keep existing head children that weren't matched this pass.\n const parentIsHeadHost =\n parent.tag === FiberTag.Host &&\n typeof parent.type === 'string' &&\n (parent.type as string).toLowerCase() === 'head'\n\n if (!parentIsHeadHost) {\n // Unmount unclaimed\n for (const f of existing) {\n if (!claimed.has(f)) {\n unmountFiber(f, domParent)\n structurallyChanged = true\n }\n }\n // Leftover keyed\n for (const f of keyed.values()) {\n if (!claimed.has(f)) {\n unmountFiber(f, domParent)\n structurallyChanged = true\n }\n }\n }\n\n // During hydration, DOM is already in document order from the cursor-driven\n // adoption walk. Running placeChildrenInOrder here would reappend nodes to\n // the end of domParent when the true anchor (often an end marker comment)\n // isn't reflected in `anchor`. Skip it in hydration mode.\n //\n // For <head>, skip always \u2014 HeadContent re-renders routinely (route match\n // changes, providers updating), and reordering every <link>/<style>/<meta>\n // on each re-render causes stylesheet flash and re-download. Head element\n // ordering is semantically fluid; the browser doesn't care about exact\n // order within <head>.\n const parentIsHead =\n (domParent as Element).nodeType === 1 &&\n (domParent as Element).tagName.toLowerCase() === 'head'\n if (structurallyChanged && !currentRoot?.hydrating && !parentIsHead) {\n placeChildrenInOrder(parent, domParent, anchor)\n }\n}\n\nfunction placeChildrenInOrder(parent: Fiber, domParent: Node, anchor: Node | null): void {\n const doms: Node[] = []\n let c = parent.child\n while (c) {\n collectHostDoms(c, doms)\n c = c.sibling\n }\n\n // Pre-check: if our fiber-owned DOM is already in document order within\n // domParent AND the end anchor matches, no reorder is needed. This is the\n // common case on stable re-renders, and avoids detaching/re-attaching\n // subtrees (which cancels CSS animations and triggers layout).\n if (doms.length > 0) {\n let current: Node | null = doms[0]!\n let inOrder = current.parentNode === domParent\n for (let i = 1; inOrder && i < doms.length; i++) {\n current = current!.nextSibling\n // Skip foreign nodes (SSR-injected scripts, dev-styles) between owned\n // fiber DOMs \u2014 they should stay where they are.\n while (current && !doms.includes(current as Node)) {\n current = current.nextSibling\n }\n if (current !== doms[i]) inOrder = false\n }\n if (inOrder) return\n }\n\n // Reverse-iterate, anchoring each node before the one that should follow it.\n // This works because by the time we're placing doms[i], doms[i+1] is already\n // in its final slot. Forward iteration is buggy: insertBefore(doms[i],\n // doms[i+1]) pulls doms[i] forward past any nodes that SHOULD move behind\n // it, leaving those nodes mis-anchored (app-starter Analyze/Lucky swap, npm\n // stats library dropdown reorder \u2014 both reported by users).\n //\n // Concrete example: start=[A, R, L], target=[A, L, R]. Forward pass gives\n // [L, A, R] (wrong). Reverse pass moves R to end, then L and A are already\n // correct \u2014 1 move, matches target.\n //\n // Skip nodes already in their target position so CSS transitions on stable\n // siblings aren't cancelled (e.g. drawer slide animation).\n for (let i = doms.length - 1; i >= 0; i--) {\n const d = doms[i]!\n const targetNext: Node | null = i + 1 < doms.length ? doms[i + 1]! : anchor\n if (d.parentNode !== domParent || d.nextSibling !== targetNext) {\n domParent.insertBefore(d, targetNext)\n }\n }\n}\n\nfunction collectHostDoms(fiber: Fiber, out: Node[]): void {\n if (fiber.tag === FiberTag.Host || fiber.tag === FiberTag.Text) {\n if (fiber.dom) out.push(fiber.dom)\n return\n }\n if (fiber.tag === FiberTag.Portal) return\n let c = fiber.child\n while (c) {\n collectHostDoms(c, out)\n c = c.sibling\n }\n}\n\nfunction collectChildren(parent: Fiber): Fiber[] {\n const out: Fiber[] = []\n let c = parent.child\n while (c) {\n out.push(c)\n c = c.sibling\n }\n return out\n}\n\n// ---------------------------------------------------------------------------\n// Rendering per fiber tag\n// ---------------------------------------------------------------------------\n\nexport type RenderFn = (fiber: Fiber, domParent: Node, anchor: Node | null) => void\nexport type TypeMatcher = (type: any, marker: any) => FiberTag | null\n\n// Mutable renderer registry indexed by FiberTag. Feature modules install their\n// renderer via registerRenderer(); unregistered features render as no-ops. The\n// initial registrations below rely on function-declaration hoisting \u2014 every\n// render* function is declared with `function` later in this file.\nconst RENDERERS: Array<RenderFn | undefined> = new Array(13)\n\n// Element-marker allowlist for child normalization (pushChildren). Core-always\n// markers are seeded here; features add their own via registerElementMarker.\nconst ACCEPTED_ELEMENT_MARKERS = new Set<symbol>([\n REACT_ELEMENT_TYPE as symbol,\n REACT_LEGACY_ELEMENT_TYPE as symbol,\n])\n\n// Type-to-tag matchers tried in registration order from fiberFromChild's\n// fallback branch. Features register here for element types that aren't\n// marker-based (e.g. Portal, where element.type IS the symbol).\nconst TYPE_MATCHERS: TypeMatcher[] = []\n\nexport function registerRenderer(tag: FiberTag, fn: RenderFn): void {\n RENDERERS[tag] = fn\n}\n\nexport function registerTypeMatcher(m: TypeMatcher): void {\n TYPE_MATCHERS.push(m)\n}\n\nexport function registerElementMarker(sym: symbol): void {\n ACCEPTED_ELEMENT_MARKERS.add(sym)\n}\n\n// Accessor + scoped setter for the module-level `currentRoot`. Feature modules\n// need these to participate in the render loop (e.g. Suspense re-hydration\n// must temporarily set the root while rebuilding a boundary subtree).\nexport function getCurrentRoot(): FiberRoot | null {\n return currentRoot\n}\n\nexport function withCurrentRoot<T>(root: FiberRoot | null, fn: () => T): T {\n const prev = currentRoot\n currentRoot = root\n try {\n return fn()\n } finally {\n currentRoot = prev\n }\n}\n\n// The memo feature uses this to bypass its prop-equality gate on state-driven\n// rerenders of the memoized fiber itself (hook update / subscribed store),\n// where props haven't changed by definition.\nexport function getForceRerenderingFiber(): Fiber | null {\n return forceRerenderingFiber\n}\n\nregisterRenderer(FiberTag.Text, renderText)\nregisterRenderer(FiberTag.Host, renderHost)\nregisterRenderer(FiberTag.Function, renderFunction)\nregisterRenderer(FiberTag.Fragment, renderFragment)\n\nexport function renderFiber(fiber: Fiber, domParent: Node, anchor: Node | null): void {\n const fn = RENDERERS[fiber.tag]\n if (fn) fn(fiber, domParent, anchor)\n}\n\nfunction renderText(fiber: Fiber, domParent: Node, anchor: Node | null): void {\n const text = fiber.pendingProps as string\n if (!fiber.dom) {\n const hydrated = currentRoot?.hydrating ? adoptTextDom(fiber, fiber.parent!, text) : false\n if (!hydrated) {\n fiber.dom = document.createTextNode(text)\n insertInto(domParent, fiber.dom, anchor)\n }\n } else if ((fiber.dom as Text).data !== text) {\n ;(fiber.dom as Text).data = text\n }\n fiber.memoizedProps = text\n // dirty cleared at rerender start; leaving true lets mid-render schedule persist\n}\n\nfunction renderHost(fiber: Fiber, domParent: Node, anchor: Node | null): void {\n const props = fiber.pendingProps ?? {}\n const prev = fiber.memoizedProps ?? {}\n const type = fiber.type as string\n const isSvg = type === 'svg' || (domParent as Element).namespaceURI === 'http://www.w3.org/2000/svg'\n\n // <select value> must be applied AFTER children mount \u2014 setting `.value`\n // on a `<select>` with no matching `<option>` yet resets it to empty. Same\n // for `defaultValue` on first mount. Stash and replay.\n const isSelect = type === 'select'\n const deferredSelectValue =\n isSelect && (props.value !== undefined || props.defaultValue !== undefined)\n ? props.value !== undefined ? props.value : props.defaultValue\n : undefined\n\n if (!fiber.dom) {\n const hydrated = currentRoot?.hydrating ? adoptHostDom(fiber, fiber.parent!) : false\n if (!hydrated) {\n fiber.dom = createHostNode(type, isSvg)\n // Two passes so form-control attributes (notably <input type>) are in\n // place before event handlers attach. setEventHandler reads the\n // element's runtime state to decide the DOM event name (e.g. onChange\n // \u2192 `input` vs `change`); binding before `type` is applied would\n // attach to the wrong event for checkbox/radio/file inputs.\n for (const k in props) {\n if (isSelect && (k === 'value' || k === 'defaultValue')) continue\n if (isEventProp(k)) continue\n setProp(fiber.dom as Element, k, props[k], undefined, isSvg)\n }\n for (const k in props) {\n if (!isEventProp(k)) continue\n setProp(fiber.dom as Element, k, props[k], undefined, isSvg)\n }\n insertInto(domParent, fiber.dom, anchor)\n }\n attachRef(fiber, fiber.dom)\n } else {\n const el = fiber.dom as Element\n for (const k in prev) {\n if (!(k in props)) setProp(el, k, undefined, prev[k], isSvg)\n }\n // Non-event props first for the same reason as above: a `type` change\n // must land before we ask setEventHandler to resolve the DOM event for\n // `onChange`.\n for (const k in props) {\n if (isSelect && (k === 'value' || k === 'defaultValue')) continue\n if (isEventProp(k)) continue\n if (prev[k] !== props[k]) setProp(el, k, props[k], prev[k], isSvg)\n }\n for (const k in props) {\n if (!isEventProp(k)) continue\n if (prev[k] !== props[k]) setProp(el, k, props[k], prev[k], isSvg)\n }\n if (prev !== props) syncRefIfChanged(fiber, fiber.dom)\n }\n\n // Children go into this DOM node\n reconcileChildren(fiber, childrenToArray(props.children), fiber.dom!, null)\n\n // During hydration, if after reconciling all client-expected children we\n // still have server DOM left in the cursor for this host, that's a\n // structural mismatch (server produced more than client wants). Report.\n // <head>/<html> are position-insensitive \u2014 leftover here is normal\n // (Vite dev-style injections, SSR-only scripts, etc.).\n if (currentRoot?.hydrating) {\n const parentTag = (fiber.type as string).toLowerCase()\n if (parentTag !== 'head' && parentTag !== 'html') {\n const cursor = getHydrationCursor(fiber)\n if (cursor) {\n const leftover = cursor.remaining().filter(\n (n) => n.nodeType === 1 || n.nodeType === 3,\n )\n if (leftover.length > 0 && currentRoot.onRecoverableError) {\n currentRoot.onRecoverableError(\n new Error(\n `Hydration mismatch: server rendered ${leftover.length} extra ` +\n `${leftover.length === 1 ? 'node' : 'nodes'} inside <${parentTag}> ` +\n `that the client tree did not.`,\n ),\n )\n for (const n of leftover) n.parentNode?.removeChild(n)\n }\n }\n }\n }\n\n // Apply <select> value after options are mounted.\n if (isSelect && deferredSelectValue !== undefined) {\n const select = fiber.dom as HTMLSelectElement\n if (Array.isArray(deferredSelectValue)) {\n const asStrings = deferredSelectValue.map((v) => '' + v)\n for (const opt of Array.from(select.options)) {\n opt.selected = asStrings.includes(opt.value)\n }\n } else {\n select.value = '' + deferredSelectValue\n }\n }\n\n fiber.memoizedProps = props\n // dirty cleared at rerender start; leaving true lets mid-render schedule persist\n}\n\nfunction renderFunction(fiber: Fiber, domParent: Node, anchor: Node | null): void {\n const prevDispatcher = ReactSharedInternals.H\n const prevFiber = ReactSharedInternals.currentFiber\n const prevHook = ReactSharedInternals.currentHook\n const prevIndex = ReactSharedInternals.hookIndex\n\n ReactSharedInternals.H = makeDispatcher()\n ReactSharedInternals.currentFiber = fiber\n ReactSharedInternals.currentHook = null\n ReactSharedInternals.hookIndex = 0\n\n let rendered: ReactNode\n let deferredForHydration = false\n try {\n rendered = (fiber.type as Function)(fiber.pendingProps ?? {})\n } catch (e: any) {\n if (isThenable(e)) {\n if (currentRoot?.hydrating) {\n // Suspension during initial hydration. Leave the existing DOM alone\n // and preserve the in-scope hydration cursor on THIS fiber so it\n // survives the synchronous endHydration() that fires when the initial\n // hydrateRoot() call returns. When the promise settles, the fiber\n // re-renders (see rerenderFiber) with hydration re-activated and its\n // descendants adopt DOM instead of creating new nodes.\n const hostParent = findHydrationHost(fiber)\n const inheritedCursor = getHydrationCursor(hostParent)\n if (inheritedCursor) {\n setHydrationCursor(fiber, inheritedCursor)\n }\n fiber.memoizedState = {\n ...(fiber.memoizedState ?? {}),\n _pendingHydration: true,\n }\n // Mirror renderLazy's guard: mark the nearest Suspense ancestor as\n // awaiting hydration-resume, so any re-render of that Suspense (e.g.\n // rehydrateBoundary fired by $RC, or an unrelated state update from a\n // sibling) doesn't re-enter `tryChildren`, re-throw, and flip Suspense\n // into its suspended+pending path \u2014 which would unmount our deferred\n // subtree and remount a fallback on top of the SSR content. By\n // pinning the Suspense to a \"hydration-suspended\" no-op until our\n // resume fires, the deferred re-render owns the adoption pass.\n let sus: Fiber | null = fiber.parent\n while (sus && sus.tag !== FiberTag.Suspense) sus = sus.parent\n if (sus && sus.memoizedState) {\n ;(sus.memoizedState as any)._awaitingLazyHydration = true\n }\n const clearAwait = () => {\n if (sus && sus.memoizedState) {\n ;(sus.memoizedState as any)._awaitingLazyHydration = false\n }\n scheduleUpdate(fiber)\n }\n e.then(clearAwait, clearAwait)\n deferredForHydration = true\n } else {\n CAPABILITIES.handleSuspended(fiber, e)\n rendered = null\n }\n } else {\n handleErrorInRender(fiber, e)\n return\n }\n } finally {\n ReactSharedInternals.H = prevDispatcher\n ReactSharedInternals.currentFiber = prevFiber\n ReactSharedInternals.currentHook = prevHook\n ReactSharedInternals.hookIndex = prevIndex\n }\n\n if (deferredForHydration) return\n\n reconcileChildren(fiber, childrenToArray(rendered), domParent, anchor)\n fiber.memoizedProps = fiber.pendingProps\n // dirty cleared at rerender start; leaving true lets mid-render schedule persist\n}\n\nfunction hasAncestorHydrationCursor(_fiber: Fiber): boolean {\n // Reserved for future per-Suspense-boundary hydration deferral. For now the\n // top-level hydration path is all we need to special-case.\n return false\n}\n\nfunction renderFragment(fiber: Fiber, domParent: Node, anchor: Node | null): void {\n const props = fiber.pendingProps ?? {}\n reconcileChildren(fiber, childrenToArray(props.children), domParent, anchor)\n fiber.memoizedProps = props\n // dirty cleared at rerender start; leaving true lets mid-render schedule persist\n}\n\n// ---------------------------------------------------------------------------\n// Error handling + default Suspense capability\n// ---------------------------------------------------------------------------\n\n// Default handler when the Suspense feature isn't installed: just schedule\n// a re-render when the thrown thenable settles. No boundary walk, no\n// fallback swap \u2014 children render empty during the pending window.\nfunction defaultHandleSuspended(fiber: Fiber, thenable: Promise<any>): void {\n thenable.then(\n () => scheduleUpdate(fiber),\n () => scheduleUpdate(fiber),\n )\n}\n\n// ---------------------------------------------------------------------------\n// Capability hooks \u2014 cross-cutting behaviors that features override.\n// Defaults here preserve today's behavior so the indirection is transparent\n// when all features are loaded. A feature's full-module can install its own\n// implementation via installCapability(); stubs leave the default in place,\n// where the default may intentionally degrade (e.g. a no-Context build's\n// readContext never walks the tree because no Provider fibers exist).\n// ---------------------------------------------------------------------------\n\nexport interface Capabilities {\n handleSuspended: (fiber: Fiber, thenable: Promise<any>) => void\n readContext: (fiber: Fiber, ctx: any) => any\n}\n\nconst CAPABILITIES: Capabilities = {\n handleSuspended: defaultHandleSuspended,\n readContext: defaultReadContext,\n}\n\nexport function installCapability<K extends keyof Capabilities>(\n name: K,\n fn: Capabilities[K],\n): void {\n CAPABILITIES[name] = fn\n}\n\n// Wrapper for features that catch thrown thenables inside their render\n// functions. Delegates to the installed Suspense capability.\nexport function handleSuspended(fiber: Fiber, thenable: Promise<any>): void {\n CAPABILITIES.handleSuspended(fiber, thenable)\n}\n\nexport function handleErrorInRender(fiber: Fiber, err: any): void {\n // Bubble to nearest class boundary with getDerivedStateFromError / componentDidCatch\n let f: Fiber | null = fiber.parent\n while (f) {\n if (f.tag === FiberTag.Class) {\n const Ctor = f.type as any\n const instance = f.stateNode\n if (Ctor.getDerivedStateFromError) {\n const update = Ctor.getDerivedStateFromError(err)\n instance.state = { ...instance.state, ...update }\n }\n if (instance.componentDidCatch) {\n try {\n instance.componentDidCatch(err, { componentStack: '' })\n } catch {}\n }\n scheduleUpdate(f)\n return\n }\n f = f.parent\n }\n // No boundary \u2014 report to root\n if (currentRoot?.onUncaughtError) currentRoot.onUncaughtError(err)\n else throw err\n}\n\nexport function isThenable(x: any): x is Promise<any> {\n return x != null && typeof x.then === 'function'\n}\n\n// ---------------------------------------------------------------------------\n// Unmount\n// ---------------------------------------------------------------------------\n\nfunction unmountFiber(fiber: Fiber, domParent: Node): void {\n fiber.unmounted = true\n // Recurse first\n let c = fiber.child\n while (c) {\n const next = c.sibling\n unmountFiber(c, fiber.tag === FiberTag.Host ? fiber.dom! : domParent)\n c = next\n }\n fiber.child = null\n\n // Run cleanups (effects + layout effects)\n if (fiber.cleanups) {\n for (const cleanup of fiber.cleanups) {\n try {\n cleanup()\n } catch (e) {\n if (currentRoot?.onRecoverableError) currentRoot.onRecoverableError(e)\n }\n }\n fiber.cleanups = null\n }\n\n if (fiber.tag === FiberTag.Class && fiber.stateNode?.componentWillUnmount) {\n try {\n fiber.stateNode.componentWillUnmount()\n } catch (e) {\n if (currentRoot?.onRecoverableError) currentRoot.onRecoverableError(e)\n }\n fiber.stateNode._fiber = null\n fiber.stateNode._enqueueUpdate = null\n fiber.stateNode._forceUpdate = null\n }\n\n // Detach ref\n if (fiber.ref) detachRef(fiber.ref)\n\n // Remove DOM if host\n if (fiber.tag === FiberTag.Host && fiber.dom && fiber.dom.parentNode) {\n fiber.dom.parentNode.removeChild(fiber.dom)\n } else if (fiber.tag === FiberTag.Text && fiber.dom && fiber.dom.parentNode) {\n fiber.dom.parentNode.removeChild(fiber.dom)\n }\n}\n\nexport function unmountAllChildren(parent: Fiber, domParent: Node): void {\n let c = parent.child\n while (c) {\n const next = c.sibling\n unmountFiber(c, domParent)\n c = next\n }\n parent.child = null\n}\n\n// ---------------------------------------------------------------------------\n// DOM navigation helpers\n// ---------------------------------------------------------------------------\n\nfunction insertInto(parent: Node, node: Node, anchor: Node | null): void {\n // Anchor may have been removed or moved since it was computed (mutations\n // from unmount, boundary reveal, user code, HMR). If it's no longer a child\n // of `parent`, fall back to append \u2014 trying to insertBefore a non-child\n // throws NotFoundError and dev-loops the reconciler.\n if (anchor && anchor.parentNode === parent) {\n parent.insertBefore(node, anchor)\n } else {\n parent.appendChild(node)\n }\n}\n\nfunction getHostParent(fiber: Fiber): Node {\n let p = fiber.parent\n while (p) {\n if (p.tag === FiberTag.Host) return p.dom!\n if (p.tag === FiberTag.Root)\n return (p.stateNode as Node) || (p.dom as Node) || (p.root?.container as Node)\n if (p.tag === FiberTag.Portal) {\n // Portal renders its children into the `container` prop, not into any\n // DOM element the portal fiber \"owns\". Read the container from the\n // portal's own props so a rerenderFiber triggered on a descendant\n // (e.g. a Floating-UI-positioned popper in a Radix Portal) finds its\n // host parent \u2014 otherwise getHostParent returns undefined and the\n // next renderHost crashes reading `.namespaceURI` on undefined.\n const props = (p.pendingProps ?? p.memoizedProps) as { container?: Element } | null\n return (props?.container as Node) || (p.stateNode as Node) || (p.dom as Node) || (p.root?.container as Node)\n }\n p = p.parent\n }\n throw new Error('No host parent found.')\n}\n\nfunction getAnchor(fiber: Fiber): Node | null {\n // Return the first DOM node that comes after this fiber within the host parent\n let f: Fiber | null = fiber.sibling\n while (f) {\n const d = firstDomNode(f)\n if (d) return d\n f = f.sibling\n }\n // Ascend\n let p = fiber.parent\n while (p && p.tag !== FiberTag.Host && p.tag !== FiberTag.Root && p.tag !== FiberTag.Portal) {\n if (p.sibling) {\n const d = firstDomNode(p.sibling)\n if (d) return d\n }\n p = p.parent\n }\n return null\n}\n\nfunction firstDomNode(fiber: Fiber): Node | null {\n if (fiber.tag === FiberTag.Host || fiber.tag === FiberTag.Text) return fiber.dom\n let c = fiber.child\n while (c) {\n const d = firstDomNode(c)\n if (d) return d\n c = c.sibling\n }\n return null\n}\n\n// ---------------------------------------------------------------------------\n// Context read \u2014 exported for dispatcher.ts (useContext, use()). Delegates to\n// the installed capability so the Context feature can override with a walking\n// implementation that finds the nearest Provider fiber. When the feature is\n// stubbed, the default here returns ctx._currentValue \u2014 correct because no\n// Provider fibers exist in the tree (Provider element \u2192 Fragment via the\n// stub's type matcher).\n// ---------------------------------------------------------------------------\n\nexport function readContext(fiber: Fiber, ctx: any): any {\n return CAPABILITIES.readContext(fiber, ctx)\n}\n\nfunction defaultReadContext(_fiber: Fiber, ctx: any): any {\n return ctx._currentValue\n}\n\n// ---------------------------------------------------------------------------\n// Refs\n// ---------------------------------------------------------------------------\n\nfunction attachRef(fiber: Fiber, value: any): void {\n const ref = fiber.ref ?? (fiber.pendingProps?.ref ?? null)\n if (!ref) return\n if (typeof ref === 'function') {\n // Match React's commit-phase semantics: callback refs run after render\n // (during the layout/commit phase), not during render. Calling them\n // synchronously here breaks libraries that assert no event handlers run\n // during render (e.g. base-ui's useStableCallback trampoline).\n scheduleLifecycle(fiber, () => {\n const cleanup = ref(value)\n fiber.cleanups ||= []\n fiber.cleanups.push(typeof cleanup === 'function' ? cleanup : () => ref(null))\n })\n } else {\n ref.current = value\n }\n}\n\nfunction syncRefIfChanged(fiber: Fiber, value: any): void {\n const ref = fiber.ref ?? (fiber.pendingProps?.ref ?? null)\n if (!ref) return\n if (typeof ref === 'object' && ref.current !== value) ref.current = value\n}\n\nfunction detachRef(ref: any): void {\n // Function refs are handled via fiber.cleanups (queued in attachRef during\n // the commit phase): the cleanup either invokes the user-returned cleanup\n // fn or calls ref(null). Calling ref(null) here would double-fire it.\n if (ref && typeof ref === 'object') {\n ref.current = null\n }\n}\n\n// ---------------------------------------------------------------------------\n// Effects\n// ---------------------------------------------------------------------------\n\nconst pendingEffects: Array<{ fiber: Fiber; effect: Effect }> = []\nconst pendingLayoutEffects: Array<{ fiber: Fiber; effect: Effect }> = []\nconst pendingLifecycles: Array<{ fiber: Fiber; fn: () => void }> = []\n\nexport function enqueueEffect(fiber: Fiber, effect: Effect): void {\n if (effect.tag === 'layout' || effect.tag === 'insertion') {\n pendingLayoutEffects.push({ fiber, effect })\n } else {\n pendingEffects.push({ fiber, effect })\n }\n}\n\nexport function scheduleLifecycle(fiber: Fiber, fn: () => void): void {\n pendingLifecycles.push({ fiber, fn })\n}\n\nexport function runEffects(root: FiberRoot): void {\n // Layout effects synchronously\n while (pendingLayoutEffects.length) {\n const { fiber, effect } = pendingLayoutEffects.shift()!\n runEffect(fiber, effect, root)\n }\n // Then lifecycles\n while (pendingLifecycles.length) {\n const { fn } = pendingLifecycles.shift()!\n try {\n fn()\n } catch (e) {\n if (root.onCaughtError) root.onCaughtError(e)\n }\n }\n // Passive effects on microtask\n if (pendingEffects.length) {\n const batch = pendingEffects.splice(0)\n queueMicrotask(() => {\n for (const { fiber, effect } of batch) runEffect(fiber, effect, root)\n })\n }\n}\n\nfunction runEffect(fiber: Fiber, effect: Effect, root: FiberRoot): void {\n try {\n const cleanup = effect.create()\n effect.destroy = typeof cleanup === 'function' ? cleanup : undefined\n if (effect.destroy) {\n fiber.cleanups ||= []\n fiber.cleanups.push(effect.destroy)\n }\n } catch (e) {\n if (root.onCaughtError) root.onCaughtError(e)\n }\n}\n\n// ---------------------------------------------------------------------------\n// Utilities\n// ---------------------------------------------------------------------------\n\nfunction isEventProp(name: string): boolean {\n return (\n name.length > 2 &&\n name.charCodeAt(0) === 111 /* o */ &&\n name.charCodeAt(1) === 110 /* n */ &&\n name.charCodeAt(2) >= 65 /* 'A'-ish: any uppercase start (onClick, onChange, \u2026) */\n )\n}\n\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA,EACE;AAAA,EAEA;AAAA,EACA;AAAA,EACA;A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AAA,IACpC;AAAA,EACF,SAAS,GAAG;AACV,QAAI,KAAK,cAAe,MAAK,cAAc,CAAC;AAAA,EAC9C;AACF;AAMA,SAAS,YAAY,MAAuB;AAC1C,SACE,KAAK,SAAS,KACd,KAAK,WAAW,CAAC,MAAM,OACvB,KAAK,WAAW,CAAC,MAAM,OACvB,KAAK,WAAW,CAAC,KAAK;AAE1B;",
|
|
6
6
|
"names": ["f"]
|
|
7
7
|
}
|
package/dist/dom/root.js
CHANGED
|
@@ -23,8 +23,16 @@ function createRoot(container, options = {}) {
|
|
|
23
23
|
};
|
|
24
24
|
rootFiber.root = root;
|
|
25
25
|
rootFiber.stateNode = container;
|
|
26
|
+
let firstRender = true;
|
|
26
27
|
return {
|
|
27
28
|
render(children) {
|
|
29
|
+
if (firstRender) {
|
|
30
|
+
firstRender = false;
|
|
31
|
+
if (container.nodeType === 1) {
|
|
32
|
+
;
|
|
33
|
+
container.textContent = "";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
28
36
|
flushSyncWork(() => {
|
|
29
37
|
renderRoot(root, children);
|
|
30
38
|
});
|
package/dist/dom/root.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dom/root.ts"],
|
|
4
|
-
"sourcesContent": ["import { FiberTag, createFiber, type FiberRoot, type ReactNode } from '../core'\nimport { renderRoot, flushSyncWork, batchedUpdates } from './reconcile'\nimport {\n beginHydration,\n endHydration,\n drainReplayQueue,\n installHydrationScrollGuard,\n} from './features/hydration'\n\nexport interface RootOptions {\n identifierPrefix?: string\n onRecoverableError?: (error: unknown) => void\n onCaughtError?: (error: unknown) => void\n onUncaughtError?: (error: unknown) => void\n}\n\nexport interface Root {\n render(children: ReactNode): void\n unmount(): void\n}\n\nexport function createRoot(container: Element | DocumentFragment, options: RootOptions = {}): Root {\n const rootFiber = createFiber(FiberTag.Root, null, null)\n rootFiber.dom = container\n const root: FiberRoot = {\n container,\n current: rootFiber,\n pending: new Set(),\n scheduled: false,\n onRecoverableError: options.onRecoverableError,\n onCaughtError: options.onCaughtError,\n onUncaughtError: options.onUncaughtError,\n identifierPrefix: options.identifierPrefix ?? ':r',\n hydrating: false,\n }\n rootFiber.root = root\n rootFiber.stateNode = container\n\n return {\n render(children) {\n flushSyncWork(() => {\n renderRoot(root, children)\n })\n },\n unmount() {\n flushSyncWork(() => {\n renderRoot(root, null)\n })\n },\n }\n}\n\nexport function hydrateRoot(\n container: Element | Document,\n initialChildren: ReactNode,\n options: RootOptions = {},\n): Root {\n // `container` may be the Document when the React tree renders <html>...</html>\n // (e.g. TanStack Start's default client entry). In that case we adopt\n // documentElement as a CHILD of the root, not as the root itself \u2014 otherwise\n // we'd try to render <html> inside <html>.\n const target = container as any as Element | Document\n const rootFiber = createFiber(FiberTag.Root, null, null)\n rootFiber.dom = target as unknown as Node\n const root: FiberRoot = {\n container: target as any,\n current: rootFiber,\n pending: new Set(),\n scheduled: false,\n onRecoverableError: options.onRecoverableError,\n onCaughtError: options.onCaughtError,\n onUncaughtError: options.onUncaughtError,\n identifierPrefix: options.identifierPrefix ?? ':r',\n hydrating: false,\n }\n rootFiber.root = root\n rootFiber.stateNode = target\n\n // Preserve the user's scroll position across hydration (see feature impl\n // for the details). No-op in SSR; no-op in the stub.\n installHydrationScrollGuard()\n\n beginHydration(root)\n try {\n flushSyncWork(() => {\n renderRoot(root, initialChildren)\n })\n } finally {\n endHydration(root)\n }\n drainReplayQueue()\n\n return {\n render(children) {\n flushSyncWork(() => {\n renderRoot(root, children)\n })\n },\n unmount() {\n flushSyncWork(() => {\n renderRoot(root, null)\n })\n },\n }\n}\n\nexport { flushSyncWork as flushSync, batchedUpdates }\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,UAAU,mBAAmD;AACtE,SAAS,YAAY,eAAe,sBAAsB;AAC1D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcA,SAAS,WAAW,WAA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MAAM,QAAQ;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,IACA,UAAU;AACR,oBAAc,MAAM;AAClB,mBAAW,MAAM,IAAI;AAAA,MACvB,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
|
|
4
|
+
"sourcesContent": ["import { FiberTag, createFiber, type FiberRoot, type ReactNode } from '../core'\nimport { renderRoot, flushSyncWork, batchedUpdates } from './reconcile'\nimport {\n beginHydration,\n endHydration,\n drainReplayQueue,\n installHydrationScrollGuard,\n} from './features/hydration'\n\nexport interface RootOptions {\n identifierPrefix?: string\n onRecoverableError?: (error: unknown) => void\n onCaughtError?: (error: unknown) => void\n onUncaughtError?: (error: unknown) => void\n}\n\nexport interface Root {\n render(children: ReactNode): void\n unmount(): void\n}\n\nexport function createRoot(container: Element | DocumentFragment, options: RootOptions = {}): Root {\n const rootFiber = createFiber(FiberTag.Root, null, null)\n rootFiber.dom = container\n const root: FiberRoot = {\n container,\n current: rootFiber,\n pending: new Set(),\n scheduled: false,\n onRecoverableError: options.onRecoverableError,\n onCaughtError: options.onCaughtError,\n onUncaughtError: options.onUncaughtError,\n identifierPrefix: options.identifierPrefix ?? ':r',\n hydrating: false,\n }\n rootFiber.root = root\n rootFiber.stateNode = container\n\n let firstRender = true\n return {\n render(children) {\n if (firstRender) {\n firstRender = false\n // Match real React's `clearContainer` semantics: blow away any pre-render\n // markup (server-rendered placeholder, splash shells, etc.) on the\n // initial commit so it doesn't stack with the React tree.\n if ((container as Node).nodeType === 1 /* ELEMENT_NODE */) {\n ;(container as Element).textContent = ''\n }\n }\n flushSyncWork(() => {\n renderRoot(root, children)\n })\n },\n unmount() {\n flushSyncWork(() => {\n renderRoot(root, null)\n })\n },\n }\n}\n\nexport function hydrateRoot(\n container: Element | Document,\n initialChildren: ReactNode,\n options: RootOptions = {},\n): Root {\n // `container` may be the Document when the React tree renders <html>...</html>\n // (e.g. TanStack Start's default client entry). In that case we adopt\n // documentElement as a CHILD of the root, not as the root itself \u2014 otherwise\n // we'd try to render <html> inside <html>.\n const target = container as any as Element | Document\n const rootFiber = createFiber(FiberTag.Root, null, null)\n rootFiber.dom = target as unknown as Node\n const root: FiberRoot = {\n container: target as any,\n current: rootFiber,\n pending: new Set(),\n scheduled: false,\n onRecoverableError: options.onRecoverableError,\n onCaughtError: options.onCaughtError,\n onUncaughtError: options.onUncaughtError,\n identifierPrefix: options.identifierPrefix ?? ':r',\n hydrating: false,\n }\n rootFiber.root = root\n rootFiber.stateNode = target\n\n // Preserve the user's scroll position across hydration (see feature impl\n // for the details). No-op in SSR; no-op in the stub.\n installHydrationScrollGuard()\n\n beginHydration(root)\n try {\n flushSyncWork(() => {\n renderRoot(root, initialChildren)\n })\n } finally {\n endHydration(root)\n }\n drainReplayQueue()\n\n return {\n render(children) {\n flushSyncWork(() => {\n renderRoot(root, children)\n })\n },\n unmount() {\n flushSyncWork(() => {\n renderRoot(root, null)\n })\n },\n }\n}\n\nexport { flushSyncWork as flushSync, batchedUpdates }\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,UAAU,mBAAmD;AACtE,SAAS,YAAY,eAAe,sBAAsB;AAC1D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAcA,SAAS,WAAW,WAAuC,UAAuB,CAAC,GAAS;AACjG,QAAM,YAAY,YAAY,SAAS,MAAM,MAAM,IAAI;AACvD,YAAU,MAAM;AAChB,QAAM,OAAkB;AAAA,IACtB;AAAA,IACA,SAAS;AAAA,IACT,SAAS,oBAAI,IAAI;AAAA,IACjB,WAAW;AAAA,IACX,oBAAoB,QAAQ;AAAA,IAC5B,eAAe,QAAQ;AAAA,IACvB,iBAAiB,QAAQ;AAAA,IACzB,kBAAkB,QAAQ,oBAAoB;AAAA,IAC9C,WAAW;AAAA,EACb;AACA,YAAU,OAAO;AACjB,YAAU,YAAY;AAEtB,MAAI,cAAc;AAClB,SAAO;AAAA,IACL,OAAO,UAAU;AACf,UAAI,aAAa;AACf,sBAAc;AAId,YAAK,UAAmB,aAAa,GAAsB;AACzD;AAAC,UAAC,UAAsB,cAAc;AAAA,QACxC;AAAA,MACF;AACA,oBAAc,MAAM;AAClB,mBAAW,MAAM,QAAQ;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,IACA,UAAU;AACR,oBAAc,MAAM;AAClB,mBAAW,MAAM,IAAI;AAAA,MACvB,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAEO,SAAS,YACd,WACA,iBACA,UAAuB,CAAC,GAClB;AAKN,QAAM,SAAS;AACf,QAAM,YAAY,YAAY,SAAS,MAAM,MAAM,IAAI;AACvD,YAAU,MAAM;AAChB,QAAM,OAAkB;AAAA,IACtB,WAAW;AAAA,IACX,SAAS;AAAA,IACT,SAAS,oBAAI,IAAI;AAAA,IACjB,WAAW;AAAA,IACX,oBAAoB,QAAQ;AAAA,IAC5B,eAAe,QAAQ;AAAA,IACvB,iBAAiB,QAAQ;AAAA,IACzB,kBAAkB,QAAQ,oBAAoB;AAAA,IAC9C,WAAW;AAAA,EACb;AACA,YAAU,OAAO;AACjB,YAAU,YAAY;AAItB,8BAA4B;AAE5B,iBAAe,IAAI;AACnB,MAAI;AACF,kBAAc,MAAM;AAClB,iBAAW,MAAM,eAAe;AAAA,IAClC,CAAC;AAAA,EACH,UAAE;AACA,iBAAa,IAAI;AAAA,EACnB;AACA,mBAAiB;AAEjB,SAAO;AAAA,IACL,OAAO,UAAU;AACf,oBAAc,MAAM;AAClB,mBAAW,MAAM,QAAQ;AAAA,MAC3B,CAAC;AAAA,IACH;AAAA,IACA,UAAU;AACR,oBAAc,MAAM;AAClB,mBAAW,MAAM,IAAI;AAAA,MACvB,CAAC;AAAA,IACH;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/vite/index.js
CHANGED
|
@@ -156,17 +156,14 @@ function redact(options = {}) {
|
|
|
156
156
|
const aliasMap = Object.fromEntries(entries.filter(([from, to]) => from !== to));
|
|
157
157
|
const dedupe = noExt;
|
|
158
158
|
return {
|
|
159
|
-
resolve: {
|
|
160
|
-
alias: aliasMap,
|
|
161
|
-
dedupe
|
|
162
|
-
},
|
|
163
159
|
environments: {
|
|
164
160
|
client: {
|
|
165
|
-
optimizeDeps: { exclude: excludeList }
|
|
161
|
+
optimizeDeps: { exclude: excludeList },
|
|
162
|
+
resolve: { alias: aliasMap, dedupe }
|
|
166
163
|
},
|
|
167
164
|
ssr: {
|
|
168
165
|
optimizeDeps: { exclude: excludeList },
|
|
169
|
-
resolve: { noExternal: noExt }
|
|
166
|
+
resolve: { alias: aliasMap, dedupe, noExternal: noExt }
|
|
170
167
|
}
|
|
171
168
|
},
|
|
172
169
|
ssr: { noExternal: noExt }
|
package/dist/vite/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/vite/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { existsSync, readFileSync, realpathSync } from 'node:fs'\nimport { dirname, resolve as resolvePath } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport type RedactPreset = 'nano' | 'full'\n\n/**\n * Opt-in feature set. Each flag toggles whether the feature's real\n * implementation ships (`true`) or is swapped with a stub module that\n * degrades gracefully (`false`). Missing keys fall back to the preset's\n * default. Adding a feature to this interface propagates to consumer\n * configs as autocompleted options.\n */\nexport interface RedactFeatures {\n /**\n * `createPortal`. When `false`, portal elements render in place as a\n * Fragment (the `container` prop is ignored). `renderPortal` and its\n * deps are stripped from the bundle.\n */\n portal?: boolean\n /**\n * `createContext` / `useContext` / `<Provider>` / `<Consumer>`. When\n * `false`, Providers render as Fragments (value never propagates),\n * Consumers invoke their function-children with the context's default\n * value, and `useContext` returns the default. Provider-walk logic and\n * `renderProvider` are stripped.\n */\n context?: boolean\n /**\n * `<Suspense>` boundaries + streaming hydration. When `false`, Suspense\n * elements render as Fragments (children mount inline, `fallback` is\n * ignored). Thrown thenables still schedule a re-render on settle, so\n * eventual consistency works \u2014 just no fallback UI during the pending\n * window. Boundary-handler stack and hydration integration are stripped.\n */\n suspense?: boolean\n /**\n * `React.memo`. When `false`, memoized components still render but without\n * the prop-equality gate \u2014 every parent rerender passes through.\n * `shallowEqual` and the force-rerender bypass are stripped.\n */\n memo?: boolean\n /**\n * `React.forwardRef`. When `false`, forwardRef components still render but\n * the ref prop isn't forwarded to the inner function. React 19+ treats\n * refs as normal props on function components anyway, so most apps can\n * drop this. The dispatcher save/restore machinery is stripped.\n */\n forwardRef?: boolean\n /**\n * `React.lazy`. When `false`, lazy elements still resolve if their payload\n * is already available synchronously (e.g. pre-awaited RSC Flight); async\n * resolution throws a clear error. The hydration-deferred-reveal path and\n * Suspense coordination are stripped.\n */\n lazy?: boolean\n /**\n * Class components (`extends Component`). When `false`, class components\n * still render but only honor the core contract: constructor + `render()`\n * + `setState`. Dropped: `contextType`, `getDerivedStateFromProps`,\n * `shouldComponentUpdate`, `componentDidMount`/`Update`/`WillUnmount`,\n * `getDerivedStateFromError`/`componentDidCatch` (error boundaries).\n */\n classComponents?: boolean\n /**\n * SSR hydration (`hydrateRoot`). When `false`, `hydrateRoot` throws\n * (use `createRoot` for SPAs). The HydrationCursor / DOM adoption /\n * streaming-boundary coordination / event-replay / scroll-guard\n * machinery is stripped \u2014 the biggest single chunk of reducible code.\n */\n hydration?: boolean\n}\n\ninterface ResolvedFeatures {\n portal: boolean\n context: boolean\n suspense: boolean\n memo: boolean\n forwardRef: boolean\n lazy: boolean\n classComponents: boolean\n hydration: boolean\n}\n\nconst PRESET_DEFAULTS: Record<RedactPreset, ResolvedFeatures> = {\n // Opt-in: everything off. Turn individual features on via `features`.\n nano: {\n portal: false, context: false, suspense: false, memo: false,\n forwardRef: false, lazy: false, classComponents: false, hydration: false,\n },\n // Opt-out: everything on (drop-in React parity). Turn features off via `features`.\n full: {\n portal: true, context: true, suspense: true, memo: true,\n forwardRef: true, lazy: true, classComponents: true, hydration: true,\n },\n}\n\nfunction resolveFeatures(\n preset: RedactPreset,\n overrides: RedactFeatures,\n): ResolvedFeatures {\n const p = PRESET_DEFAULTS[preset]\n return {\n portal: overrides.portal ?? p.portal,\n context: overrides.context ?? p.context,\n suspense: overrides.suspense ?? p.suspense,\n memo: overrides.memo ?? p.memo,\n forwardRef: overrides.forwardRef ?? p.forwardRef,\n lazy: overrides.lazy ?? p.lazy,\n classComponents: overrides.classComponents ?? p.classComponents,\n hydration: overrides.hydration ?? p.hydration,\n }\n}\n\nexport interface RedactOptions {\n /** Skip aliasing specific specifiers, e.g. if a consumer wants real React somewhere. */\n skip?: ReadonlyArray<string>\n /**\n * Override package resolution root. Defaults to the Vite config root. Useful\n * for monorepos where the plugin lives in a different workspace than the\n * consumer app.\n */\n resolveFrom?: string\n /**\n * Explicit package roots, bypassing node_modules lookup. Keys are package\n * names (e.g. `@tanstack/redact`), values are absolute paths to the package\n * directory. Handy for cross-workspace testing / bring-your-own-build setups.\n */\n packageRoots?: Record<string, string>\n /**\n * Starting point for feature selection. `'full'` (default) turns every\n * feature on \u2014 drop-in React parity, opt-out individual features via\n * `features`. `'nano'` turns everything off \u2014 opt in to what you need.\n */\n preset?: RedactPreset\n /**\n * Per-feature overrides merged on top of the preset's defaults. Enables\n * fine-grained \"preset minus X\" or \"preset plus Y\" configurations.\n */\n features?: RedactFeatures\n}\n\n// Alias map. ORDER MATTERS \u2014 Vite's alias matcher uses first-match against\n// prefix, so more-specific specifiers MUST come before less-specific ones.\n// Without this, `react-dom/server` would prefix-match `react-dom` first and\n// resolve to `@tanstack/redact/dom/server` (wrong) instead of\n// `@tanstack/redact/server`.\n//\n// `use-sync-external-store` aliases are here because its CJS-only React 17\n// compat shim does `var React = require('react')`. That survives Vite's\n// pre-bundling intact and explodes in Cloudflare Workers (no `require`).\n// Modern React has `useSyncExternalStore` built-in, and `@tanstack/redact`\n// additionally exports `useSyncExternalStoreWithSelector` so this alias\n// is safe everywhere.\nconst ALIASES: Record<string, string> = {\n // ---- most-specific first ----\n 'use-sync-external-store/shim/with-selector': '@tanstack/redact',\n 'use-sync-external-store/shim/with-selector.js': '@tanstack/redact',\n 'use-sync-external-store/with-selector': '@tanstack/redact',\n 'use-sync-external-store/with-selector.js': '@tanstack/redact',\n 'use-sync-external-store/shim': '@tanstack/redact',\n 'use-sync-external-store': '@tanstack/redact',\n\n // React drop-in shim targets. Subpaths first.\n 'react/jsx-runtime': '@tanstack/redact/jsx-runtime',\n 'react/jsx-dev-runtime': '@tanstack/redact/jsx-dev-runtime',\n 'react-dom/client': '@tanstack/redact/dom-client',\n 'react-dom/server': '@tanstack/redact/server',\n 'react-dom/test-utils': '@tanstack/redact/dom-test-utils',\n 'react-dom': '@tanstack/redact/dom',\n react: '@tanstack/redact',\n scheduler: '@tanstack/redact/scheduler',\n\n // Self-aliases so Vite resolves `@tanstack/redact/*` imports to the same\n // canonical file path no matter where they originate (worker bundle vs\n // deps_ssr pre-bundle vs source). Without these, Cloudflare's\n // `noExternal: true` worker config inlines one copy while Vite's\n // optimizeDeps pre-bundles another, ending up with two separate\n // ReactSharedInternals instances and a null dispatcher in user hooks.\n // Subpaths first here too.\n '@tanstack/redact/jsx-runtime': '@tanstack/redact/jsx-runtime',\n '@tanstack/redact/jsx-dev-runtime': '@tanstack/redact/jsx-dev-runtime',\n '@tanstack/redact/dom-client': '@tanstack/redact/dom-client',\n '@tanstack/redact/dom-test-utils': '@tanstack/redact/dom-test-utils',\n '@tanstack/redact/server': '@tanstack/redact/server',\n '@tanstack/redact/scheduler': '@tanstack/redact/scheduler',\n '@tanstack/redact/dom': '@tanstack/redact/dom',\n '@tanstack/redact': '@tanstack/redact',\n}\n\nfunction splitSpecifier(specifier: string): { pkg: string; sub: string } {\n if (specifier.startsWith('@')) {\n const slash1 = specifier.indexOf('/')\n const slash2 = specifier.indexOf('/', slash1 + 1)\n if (slash2 < 0) return { pkg: specifier, sub: '' }\n return { pkg: specifier.slice(0, slash2), sub: specifier.slice(slash2 + 1) }\n }\n const slash = specifier.indexOf('/')\n if (slash < 0) return { pkg: specifier, sub: '' }\n return { pkg: specifier.slice(0, slash), sub: specifier.slice(slash + 1) }\n}\n\nfunction findPackageDir(pkg: string, fromDir: string): string | null {\n let dir = fromDir\n while (true) {\n const candidate = resolvePath(dir, 'node_modules', pkg)\n if (existsSync(resolvePath(candidate, 'package.json'))) return candidate\n const parent = dirname(dir)\n if (parent === dir) return null\n dir = parent\n }\n}\n\nfunction resolveExport(packageDir: string, sub: string): string | null {\n const pkgJsonPath = resolvePath(packageDir, 'package.json')\n let pkg: any\n try {\n pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8'))\n } catch {\n return null\n }\n const key = sub ? './' + sub : '.'\n const exp = pkg.exports?.[key]\n // Prefer published `import` (dist/.js) over `source` \u2014 dist is a single\n // transformed bundle so Vite's dep optimizer doesn't thrash on dozens of\n // individual source files. The package keeps cross-subpath imports\n // external, so there's still only one runtime instance.\n const pick = (v: any): string | null => {\n if (typeof v === 'string') return v\n if (v && typeof v === 'object') {\n return pick(v.import ?? v.module ?? v.source ?? v.default ?? null)\n }\n return null\n }\n const target = pick(exp)\n if (target) return resolvePath(packageDir, target)\n if (!sub) {\n const main = pkg.module ?? pkg.main\n if (typeof main === 'string') return resolvePath(packageDir, main)\n }\n return null\n}\n\n// When installed from npm, `@tanstack/redact` is declared as a `dependency`\n// of consumer apps. Under pnpm's strict mode it ends up nested under the\n// plugin's own `.pnpm/@tanstack+redact@.../node_modules/` rather than\n// hoisted to the consumer's root, so a `findPackageDir` walk starting at\n// the Vite project root won't always find it. Search from the plugin's own\n// directory first (which walks into its nested node_modules), then fall\n// back to the consumer root for hoisted installs.\nconst pluginDir = dirname(fileURLToPath(import.meta.url))\n\nfunction resolveSpecifier(\n specifier: string,\n fromDir: string,\n packageRoots: Record<string, string>,\n): string | null {\n const { pkg, sub } = splitSpecifier(specifier)\n const packageDir =\n packageRoots[pkg] ??\n findPackageDir(pkg, pluginDir) ??\n findPackageDir(pkg, fromDir)\n if (!packageDir) return null\n const target = resolveExport(packageDir, sub)\n if (!target) return null\n // Canonicalize through pnpm symlinks. Under strict pnpm, the package may\n // live nested under `.pnpm/@tanstack+redact@.../node_modules/*`, but each\n // of those is itself a symlink to the flat `.pnpm/@tanstack+redact@.../`\n // entry. Vite's `fetchModule` (used by TanStack Start's server-fn\n // compiler) follows the realpath, so the id seen by the capture-transform\n // differs from the nested id we'd return. That leaves the compiler's\n // moduleCache keyed on the realpath while `getModuleInfo` looks up the\n // nested path \u2192 miss \u2192 \"could not load module info\". Returning the\n // canonical realpath here keeps the two sides in agreement.\n try {\n return realpathSync(target)\n } catch {\n return target\n }\n}\n\nexport function redact(options: RedactOptions = {}): any {\n const skip = new Set(options.skip ?? [])\n const entries = Object.entries(ALIASES).filter(([k]) => !skip.has(k))\n const features = resolveFeatures(options.preset ?? 'full', options.features ?? {})\n\n const resolvedMap: Record<string, string> = {}\n let done = false\n\n function resolveAll(root: string): void {\n if (done) return\n const fromDir = options.resolveFrom ?? root\n const packageRoots = options.packageRoots ?? {}\n for (const [from, to] of entries) {\n const resolved = resolveSpecifier(to, fromDir, packageRoots)\n if (resolved) resolvedMap[from] = resolved\n }\n done = true\n }\n\n return {\n name: 'redact',\n enforce: 'pre',\n\n config() {\n const excludeList = entries.map(([k]) => k)\n // Single package \u2014 only one name to dedupe / no-external.\n const noExt = ['@tanstack/redact']\n // Top-level resolve.alias so `react` \u2192 `@tanstack/redact` happens\n // BEFORE any plugin-based resolveId hook fires. The Cloudflare\n // vite-plugin's rolldown worker-runner pre-scans the worker entry's\n // exports and resolves bare specifiers via Vite's alias map directly\n // (not via plugin hooks), so without this it would resolve `react` to\n // the real npm package and try to `require()` it in a Worker (no CJS\n // support). Object form is required \u2014 array form is silently ignored\n // by rolldown's worker-runner.\n const aliasMap = Object.fromEntries(entries.filter(([from, to]) => from !== to))\n // Scope optimizeDeps to client + ssr environments ONLY. Do NOT set a\n // top-level optimizeDeps \u2014 in Vite 6+ that's effectively the client\n // env's default but also seeps into the rsc env's `'use client'`\n // analysis, causing flood warnings like \"inconsistently optimized\".\n // Dedupe `@tanstack/redact` so Vite resolves it to a single instance\n // even when multiple packages (e.g. @tanstack/react-router and user\n // code) drag it into different parts of the module graph.\n const dedupe = noExt\n return {\n resolve: {\n alias: aliasMap,\n dedupe,\n },\n environments: {\n client: {\n optimizeDeps: { exclude: excludeList },\n },\n ssr: {\n optimizeDeps: { exclude: excludeList },\n resolve: { noExternal: noExt },\n },\n },\n ssr: { noExternal: noExt },\n }\n },\n\n configResolved(config: any) {\n resolveAll(config.root)\n // With `packageRoots`, package sources live outside the consumer's Vite\n // project root, so the default server.fs.allow list blocks them. Append\n // to the resolved allow list rather than replacing via `config()`, so we\n // keep Vite's defaults (root + node_modules + client runtime).\n const fsAllow = Object.values(options.packageRoots ?? {})\n if (fsAllow.length && config.server?.fs?.allow) {\n for (const p of fsAllow) {\n if (!config.server.fs.allow.includes(p)) {\n config.server.fs.allow.push(p)\n }\n }\n }\n },\n\n async resolveId(this: any, id: string, importer?: string, opts?: any) {\n // Skip the RSC environment \u2014 it relies on real React internals via\n // @vitejs/plugin-rsc's vendored react-server-dom. Substituting our\n // shim there breaks Flight serialization. Client + SSR envs still swap.\n const envName = this?.environment?.name\n if (envName === 'rsc') return null\n\n // Feature-flag swap: when the reconciler's `features/index` module\n // imports a feature by relative path, redirect to that feature's stub\n // if the flag is off. The stub registers a graceful-degradation\n // matcher (e.g. Portal \u2192 Fragment) so user code keeps working.\n if (importer && /[\\\\/]features[\\\\/]index\\.[jt]sx?$/.test(importer)) {\n const m = id.match(/^\\.\\/([a-z-]+)$/)\n if (m) {\n const name = m[1] as keyof ResolvedFeatures\n if (name in features && !features[name]) {\n const r = await this.resolve(`./${name}/stub`, importer, {\n ...opts,\n skipSelf: true,\n })\n if (r) return r.id\n }\n }\n }\n\n // Hydration swap: hydration isn't self-registering, so it's imported\n // from reconcile.ts, root.ts, and the Suspense/Lazy feature modules.\n // Any specifier ending in `/hydration` that resolves to our feature\n // module gets redirected to the stub when the flag is off.\n if (!features.hydration && importer && /[\\\\/]hydration$/.test(id)) {\n const r = await this.resolve(id, importer, { ...opts, skipSelf: true })\n if (r && /features[\\\\/]hydration[\\\\/]index\\.(ts|js)$/.test(r.id)) {\n return r.id.replace(/index\\.(ts|js)$/, 'stub.$1')\n }\n }\n\n return resolvedMap[id] ?? null\n },\n }\n}\n\nexport default redact\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,YAAY,cAAc,oBAAoB;AACvD,SAAS,SAAS,WAAW,mBAAmB;AAChD,SAAS,qBAAqB;AAkF9B,IAAM,kBAA0D;AAAA;AAAA,EAE9D,MAAM;AAAA,IACJ,QAAQ;AAAA,IAAO,SAAS;AAAA,IAAO,UAAU;AAAA,IAAO,MAAM;AAAA,IACtD,YAAY;AAAA,IAAO,MAAM;AAAA,IAAO,iBAAiB;AAAA,IAAO,WAAW;AAAA,EACrE;AAAA;AAAA,EAEA,MAAM;AAAA,IACJ,QAAQ;AAAA,IAAM,SAAS;AAAA,IAAM,UAAU;AAAA,IAAM,MAAM;AAAA,IACnD,YAAY;AAAA,IAAM,MAAM;AAAA,IAAM,iBAAiB;AAAA,IAAM,WAAW;AAAA,EAClE;AACF;AAEA,SAAS,gBACP,QACA,WACkB;AAClB,QAAM,IAAI,gBAAgB,MAAM;AAChC,SAAO;AAAA,IACL,QAAQ,UAAU,UAAU,EAAE;AAAA,IAC9B,SAAS,UAAU,WAAW,EAAE;AAAA,IAChC,UAAU,UAAU,YAAY,EAAE;AAAA,IAClC,MAAM,UAAU,QAAQ,EAAE;AAAA,IAC1B,YAAY,UAAU,cAAc,EAAE;AAAA,IACtC,MAAM,UAAU,QAAQ,EAAE;AAAA,IAC1B,iBAAiB,UAAU,mBAAmB,EAAE;AAAA,IAChD,WAAW,UAAU,aAAa,EAAE;AAAA,EACtC;AACF;AA0CA,IAAM,UAAkC;AAAA;AAAA,EAEtC,8CAA8C;AAAA,EAC9C,iDAAiD;AAAA,EACjD,yCAAyC;AAAA,EACzC,4CAA4C;AAA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AW,gBAAgB,QAAQ,UAAU,QAAQ,QAAQ,YAAY,CAAC,CAAC;AAEjF,QAAM,cAAsC,CAAC;AAC7C,MAAI,OAAO;AAEX,WAAS,WAAW,MAAoB;AACtC,QAAI,KAAM;AACV,UAAM,UAAU,QAAQ,eAAe;AACvC,UAAM,eAAe,QAAQ,gBAAgB,CAAC;AAC9C,eAAW,CAAC,MAAM,EAAE,KAAK,SAAS;AAChC,YAAM,WAAW,iBAAiB,IAAI,SAAS,YAAY;AAC3D,UAAI,SAAU,aAAY,IAAI,IAAI;AAAA,IACpC;AACA,WAAO;AAAA,EACT;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IAET,SAAS;AACP,YAAM,cAAc,QAAQ,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AAE1C,YAAM,QAAQ,CAAC,kBAAkB;
|
|
4
|
+
"sourcesContent": ["import { existsSync, readFileSync, realpathSync } from 'node:fs'\nimport { dirname, resolve as resolvePath } from 'node:path'\nimport { fileURLToPath } from 'node:url'\n\nexport type RedactPreset = 'nano' | 'full'\n\n/**\n * Opt-in feature set. Each flag toggles whether the feature's real\n * implementation ships (`true`) or is swapped with a stub module that\n * degrades gracefully (`false`). Missing keys fall back to the preset's\n * default. Adding a feature to this interface propagates to consumer\n * configs as autocompleted options.\n */\nexport interface RedactFeatures {\n /**\n * `createPortal`. When `false`, portal elements render in place as a\n * Fragment (the `container` prop is ignored). `renderPortal` and its\n * deps are stripped from the bundle.\n */\n portal?: boolean\n /**\n * `createContext` / `useContext` / `<Provider>` / `<Consumer>`. When\n * `false`, Providers render as Fragments (value never propagates),\n * Consumers invoke their function-children with the context's default\n * value, and `useContext` returns the default. Provider-walk logic and\n * `renderProvider` are stripped.\n */\n context?: boolean\n /**\n * `<Suspense>` boundaries + streaming hydration. When `false`, Suspense\n * elements render as Fragments (children mount inline, `fallback` is\n * ignored). Thrown thenables still schedule a re-render on settle, so\n * eventual consistency works \u2014 just no fallback UI during the pending\n * window. Boundary-handler stack and hydration integration are stripped.\n */\n suspense?: boolean\n /**\n * `React.memo`. When `false`, memoized components still render but without\n * the prop-equality gate \u2014 every parent rerender passes through.\n * `shallowEqual` and the force-rerender bypass are stripped.\n */\n memo?: boolean\n /**\n * `React.forwardRef`. When `false`, forwardRef components still render but\n * the ref prop isn't forwarded to the inner function. React 19+ treats\n * refs as normal props on function components anyway, so most apps can\n * drop this. The dispatcher save/restore machinery is stripped.\n */\n forwardRef?: boolean\n /**\n * `React.lazy`. When `false`, lazy elements still resolve if their payload\n * is already available synchronously (e.g. pre-awaited RSC Flight); async\n * resolution throws a clear error. The hydration-deferred-reveal path and\n * Suspense coordination are stripped.\n */\n lazy?: boolean\n /**\n * Class components (`extends Component`). When `false`, class components\n * still render but only honor the core contract: constructor + `render()`\n * + `setState`. Dropped: `contextType`, `getDerivedStateFromProps`,\n * `shouldComponentUpdate`, `componentDidMount`/`Update`/`WillUnmount`,\n * `getDerivedStateFromError`/`componentDidCatch` (error boundaries).\n */\n classComponents?: boolean\n /**\n * SSR hydration (`hydrateRoot`). When `false`, `hydrateRoot` throws\n * (use `createRoot` for SPAs). The HydrationCursor / DOM adoption /\n * streaming-boundary coordination / event-replay / scroll-guard\n * machinery is stripped \u2014 the biggest single chunk of reducible code.\n */\n hydration?: boolean\n}\n\ninterface ResolvedFeatures {\n portal: boolean\n context: boolean\n suspense: boolean\n memo: boolean\n forwardRef: boolean\n lazy: boolean\n classComponents: boolean\n hydration: boolean\n}\n\nconst PRESET_DEFAULTS: Record<RedactPreset, ResolvedFeatures> = {\n // Opt-in: everything off. Turn individual features on via `features`.\n nano: {\n portal: false, context: false, suspense: false, memo: false,\n forwardRef: false, lazy: false, classComponents: false, hydration: false,\n },\n // Opt-out: everything on (drop-in React parity). Turn features off via `features`.\n full: {\n portal: true, context: true, suspense: true, memo: true,\n forwardRef: true, lazy: true, classComponents: true, hydration: true,\n },\n}\n\nfunction resolveFeatures(\n preset: RedactPreset,\n overrides: RedactFeatures,\n): ResolvedFeatures {\n const p = PRESET_DEFAULTS[preset]\n return {\n portal: overrides.portal ?? p.portal,\n context: overrides.context ?? p.context,\n suspense: overrides.suspense ?? p.suspense,\n memo: overrides.memo ?? p.memo,\n forwardRef: overrides.forwardRef ?? p.forwardRef,\n lazy: overrides.lazy ?? p.lazy,\n classComponents: overrides.classComponents ?? p.classComponents,\n hydration: overrides.hydration ?? p.hydration,\n }\n}\n\nexport interface RedactOptions {\n /** Skip aliasing specific specifiers, e.g. if a consumer wants real React somewhere. */\n skip?: ReadonlyArray<string>\n /**\n * Override package resolution root. Defaults to the Vite config root. Useful\n * for monorepos where the plugin lives in a different workspace than the\n * consumer app.\n */\n resolveFrom?: string\n /**\n * Explicit package roots, bypassing node_modules lookup. Keys are package\n * names (e.g. `@tanstack/redact`), values are absolute paths to the package\n * directory. Handy for cross-workspace testing / bring-your-own-build setups.\n */\n packageRoots?: Record<string, string>\n /**\n * Starting point for feature selection. `'full'` (default) turns every\n * feature on \u2014 drop-in React parity, opt-out individual features via\n * `features`. `'nano'` turns everything off \u2014 opt in to what you need.\n */\n preset?: RedactPreset\n /**\n * Per-feature overrides merged on top of the preset's defaults. Enables\n * fine-grained \"preset minus X\" or \"preset plus Y\" configurations.\n */\n features?: RedactFeatures\n}\n\n// Alias map. ORDER MATTERS \u2014 Vite's alias matcher uses first-match against\n// prefix, so more-specific specifiers MUST come before less-specific ones.\n// Without this, `react-dom/server` would prefix-match `react-dom` first and\n// resolve to `@tanstack/redact/dom/server` (wrong) instead of\n// `@tanstack/redact/server`.\n//\n// `use-sync-external-store` aliases are here because its CJS-only React 17\n// compat shim does `var React = require('react')`. That survives Vite's\n// pre-bundling intact and explodes in Cloudflare Workers (no `require`).\n// Modern React has `useSyncExternalStore` built-in, and `@tanstack/redact`\n// additionally exports `useSyncExternalStoreWithSelector` so this alias\n// is safe everywhere.\nconst ALIASES: Record<string, string> = {\n // ---- most-specific first ----\n 'use-sync-external-store/shim/with-selector': '@tanstack/redact',\n 'use-sync-external-store/shim/with-selector.js': '@tanstack/redact',\n 'use-sync-external-store/with-selector': '@tanstack/redact',\n 'use-sync-external-store/with-selector.js': '@tanstack/redact',\n 'use-sync-external-store/shim': '@tanstack/redact',\n 'use-sync-external-store': '@tanstack/redact',\n\n // React drop-in shim targets. Subpaths first.\n 'react/jsx-runtime': '@tanstack/redact/jsx-runtime',\n 'react/jsx-dev-runtime': '@tanstack/redact/jsx-dev-runtime',\n 'react-dom/client': '@tanstack/redact/dom-client',\n 'react-dom/server': '@tanstack/redact/server',\n 'react-dom/test-utils': '@tanstack/redact/dom-test-utils',\n 'react-dom': '@tanstack/redact/dom',\n react: '@tanstack/redact',\n scheduler: '@tanstack/redact/scheduler',\n\n // Self-aliases so Vite resolves `@tanstack/redact/*` imports to the same\n // canonical file path no matter where they originate (worker bundle vs\n // deps_ssr pre-bundle vs source). Without these, Cloudflare's\n // `noExternal: true` worker config inlines one copy while Vite's\n // optimizeDeps pre-bundles another, ending up with two separate\n // ReactSharedInternals instances and a null dispatcher in user hooks.\n // Subpaths first here too.\n '@tanstack/redact/jsx-runtime': '@tanstack/redact/jsx-runtime',\n '@tanstack/redact/jsx-dev-runtime': '@tanstack/redact/jsx-dev-runtime',\n '@tanstack/redact/dom-client': '@tanstack/redact/dom-client',\n '@tanstack/redact/dom-test-utils': '@tanstack/redact/dom-test-utils',\n '@tanstack/redact/server': '@tanstack/redact/server',\n '@tanstack/redact/scheduler': '@tanstack/redact/scheduler',\n '@tanstack/redact/dom': '@tanstack/redact/dom',\n '@tanstack/redact': '@tanstack/redact',\n}\n\nfunction splitSpecifier(specifier: string): { pkg: string; sub: string } {\n if (specifier.startsWith('@')) {\n const slash1 = specifier.indexOf('/')\n const slash2 = specifier.indexOf('/', slash1 + 1)\n if (slash2 < 0) return { pkg: specifier, sub: '' }\n return { pkg: specifier.slice(0, slash2), sub: specifier.slice(slash2 + 1) }\n }\n const slash = specifier.indexOf('/')\n if (slash < 0) return { pkg: specifier, sub: '' }\n return { pkg: specifier.slice(0, slash), sub: specifier.slice(slash + 1) }\n}\n\nfunction findPackageDir(pkg: string, fromDir: string): string | null {\n let dir = fromDir\n while (true) {\n const candidate = resolvePath(dir, 'node_modules', pkg)\n if (existsSync(resolvePath(candidate, 'package.json'))) return candidate\n const parent = dirname(dir)\n if (parent === dir) return null\n dir = parent\n }\n}\n\nfunction resolveExport(packageDir: string, sub: string): string | null {\n const pkgJsonPath = resolvePath(packageDir, 'package.json')\n let pkg: any\n try {\n pkg = JSON.parse(readFileSync(pkgJsonPath, 'utf8'))\n } catch {\n return null\n }\n const key = sub ? './' + sub : '.'\n const exp = pkg.exports?.[key]\n // Prefer published `import` (dist/.js) over `source` \u2014 dist is a single\n // transformed bundle so Vite's dep optimizer doesn't thrash on dozens of\n // individual source files. The package keeps cross-subpath imports\n // external, so there's still only one runtime instance.\n const pick = (v: any): string | null => {\n if (typeof v === 'string') return v\n if (v && typeof v === 'object') {\n return pick(v.import ?? v.module ?? v.source ?? v.default ?? null)\n }\n return null\n }\n const target = pick(exp)\n if (target) return resolvePath(packageDir, target)\n if (!sub) {\n const main = pkg.module ?? pkg.main\n if (typeof main === 'string') return resolvePath(packageDir, main)\n }\n return null\n}\n\n// When installed from npm, `@tanstack/redact` is declared as a `dependency`\n// of consumer apps. Under pnpm's strict mode it ends up nested under the\n// plugin's own `.pnpm/@tanstack+redact@.../node_modules/` rather than\n// hoisted to the consumer's root, so a `findPackageDir` walk starting at\n// the Vite project root won't always find it. Search from the plugin's own\n// directory first (which walks into its nested node_modules), then fall\n// back to the consumer root for hoisted installs.\nconst pluginDir = dirname(fileURLToPath(import.meta.url))\n\nfunction resolveSpecifier(\n specifier: string,\n fromDir: string,\n packageRoots: Record<string, string>,\n): string | null {\n const { pkg, sub } = splitSpecifier(specifier)\n const packageDir =\n packageRoots[pkg] ??\n findPackageDir(pkg, pluginDir) ??\n findPackageDir(pkg, fromDir)\n if (!packageDir) return null\n const target = resolveExport(packageDir, sub)\n if (!target) return null\n // Canonicalize through pnpm symlinks. Under strict pnpm, the package may\n // live nested under `.pnpm/@tanstack+redact@.../node_modules/*`, but each\n // of those is itself a symlink to the flat `.pnpm/@tanstack+redact@.../`\n // entry. Vite's `fetchModule` (used by TanStack Start's server-fn\n // compiler) follows the realpath, so the id seen by the capture-transform\n // differs from the nested id we'd return. That leaves the compiler's\n // moduleCache keyed on the realpath while `getModuleInfo` looks up the\n // nested path \u2192 miss \u2192 \"could not load module info\". Returning the\n // canonical realpath here keeps the two sides in agreement.\n try {\n return realpathSync(target)\n } catch {\n return target\n }\n}\n\nexport function redact(options: RedactOptions = {}): any {\n const skip = new Set(options.skip ?? [])\n const entries = Object.entries(ALIASES).filter(([k]) => !skip.has(k))\n const features = resolveFeatures(options.preset ?? 'full', options.features ?? {})\n\n const resolvedMap: Record<string, string> = {}\n let done = false\n\n function resolveAll(root: string): void {\n if (done) return\n const fromDir = options.resolveFrom ?? root\n const packageRoots = options.packageRoots ?? {}\n for (const [from, to] of entries) {\n const resolved = resolveSpecifier(to, fromDir, packageRoots)\n if (resolved) resolvedMap[from] = resolved\n }\n done = true\n }\n\n return {\n name: 'redact',\n enforce: 'pre',\n\n config() {\n const excludeList = entries.map(([k]) => k)\n // Single package \u2014 only one name to dedupe / no-external.\n const noExt = ['@tanstack/redact']\n const aliasMap = Object.fromEntries(entries.filter(([from, to]) => from !== to))\n // Dedupe `@tanstack/redact` so Vite resolves it to a single instance\n // even when multiple packages (e.g. @tanstack/react-router and user\n // code) drag it into different parts of the module graph.\n const dedupe = noExt\n // Scope `resolve.alias` to client + ssr environments ONLY. Do NOT set\n // a top-level alias: it would apply to the `rsc` environment too,\n // where `@vitejs/plugin-rsc`'s vendored `react-server-dom-server`\n // imports `react` and needs the *real* React (with the `.d` field on\n // ReactSharedInternals that our shim deliberately doesn't have).\n // Aliasing `react` \u2192 `@tanstack/redact` in the RSC env crashes Flight\n // serialization. The Cloudflare vite-plugin's rolldown worker-runner\n // also pre-scans bare specifiers via Vite's alias map (not plugin\n // hooks), but it scans within the *ssr* environment specifically \u2014\n // so per-env `environments.ssr.resolve.alias` covers it. The\n // `enforce: 'pre'` resolveId hook below already skips RSC, so the\n // remaining concern is alias placement. Object form is required \u2014\n // array form is silently ignored by rolldown's worker-runner.\n return {\n environments: {\n client: {\n optimizeDeps: { exclude: excludeList },\n resolve: { alias: aliasMap, dedupe },\n },\n ssr: {\n optimizeDeps: { exclude: excludeList },\n resolve: { alias: aliasMap, dedupe, noExternal: noExt },\n },\n },\n ssr: { noExternal: noExt },\n }\n },\n\n configResolved(config: any) {\n resolveAll(config.root)\n // With `packageRoots`, package sources live outside the consumer's Vite\n // project root, so the default server.fs.allow list blocks them. Append\n // to the resolved allow list rather than replacing via `config()`, so we\n // keep Vite's defaults (root + node_modules + client runtime).\n const fsAllow = Object.values(options.packageRoots ?? {})\n if (fsAllow.length && config.server?.fs?.allow) {\n for (const p of fsAllow) {\n if (!config.server.fs.allow.includes(p)) {\n config.server.fs.allow.push(p)\n }\n }\n }\n },\n\n async resolveId(this: any, id: string, importer?: string, opts?: any) {\n // Skip the RSC environment \u2014 it relies on real React internals via\n // @vitejs/plugin-rsc's vendored react-server-dom. Substituting our\n // shim there breaks Flight serialization. Client + SSR envs still swap.\n const envName = this?.environment?.name\n if (envName === 'rsc') return null\n\n // Feature-flag swap: when the reconciler's `features/index` module\n // imports a feature by relative path, redirect to that feature's stub\n // if the flag is off. The stub registers a graceful-degradation\n // matcher (e.g. Portal \u2192 Fragment) so user code keeps working.\n if (importer && /[\\\\/]features[\\\\/]index\\.[jt]sx?$/.test(importer)) {\n const m = id.match(/^\\.\\/([a-z-]+)$/)\n if (m) {\n const name = m[1] as keyof ResolvedFeatures\n if (name in features && !features[name]) {\n const r = await this.resolve(`./${name}/stub`, importer, {\n ...opts,\n skipSelf: true,\n })\n if (r) return r.id\n }\n }\n }\n\n // Hydration swap: hydration isn't self-registering, so it's imported\n // from reconcile.ts, root.ts, and the Suspense/Lazy feature modules.\n // Any specifier ending in `/hydration` that resolves to our feature\n // module gets redirected to the stub when the flag is off.\n if (!features.hydration && importer && /[\\\\/]hydration$/.test(id)) {\n const r = await this.resolve(id, importer, { ...opts, skipSelf: true })\n if (r && /features[\\\\/]hydration[\\\\/]index\\.(ts|js)$/.test(r.id)) {\n return r.id.replace(/index\\.(ts|js)$/, 'stub.$1')\n }\n }\n\n return resolvedMap[id] ?? null\n },\n }\n}\n\nexport default redact\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,YAAY,cAAc,oBAAoB;AACvD,SAAS,SAAS,WAAW,mBAAmB;AAChD,SAAS,qBAAqB;AAkF9B,IAAM,kBAA0D;AAAA;AAAA,EAE9D,MAAM;AAAA,IACJ,QAAQ;AAAA,IAAO,SAAS;AAAA,IAAO,UAAU;AAAA,IAAO,MAAM;AAAA,IACtD,YAAY;AAAA,IAAO,MAAM;AAAA,IAAO,iBAAiB;AAAA,IAAO,WAAW;AAAA,EACrE;AAAA;AAAA,EAEA,MAAM;AAAA,IACJ,QAAQ;AAAA,IAAM,SAAS;AAAA,IAAM,UAAU;AAAA,IAAM,MAAM;AAAA,IACnD,YAAY;AAAA,IAAM,MAAM;AAAA,IAAM,iBAAiB;AAAA,IAAM,WAAW;AAAA,EAClE;AACF;AAEA,SAAS,gBACP,QACA,WACkB;AAClB,QAAM,IAAI,gBAAgB,MAAM;AAChC,SAAO;AAAA,IACL,QAAQ,UAAU,UAAU,EAAE;AAAA,IAC9B,SAAS,UAAU,WAAW,EAAE;AAAA,IAChC,UAAU,UAAU,YAAY,EAAE;AAAA,IAClC,MAAM,UAAU,QAAQ,EAAE;AAAA,IAC1B,YAAY,UAAU,cAAc,EAAE;AAAA,IACtC,MAAM,UAAU,QAAQ,EAAE;AAAA,IAC1B,iBAAiB,UAAU,mBAAmB,EAAE;AAAA,IAChD,WAAW,UAAU,aAAa,EAAE;AAAA,EACtC;AACF;AA0CA,IAAM,UAAkC;AAAA;AAAA,EAEtC,8CAA8C;AAAA,EAC9C,iDAAiD;AAAA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MAAM,SAAS,CAAC,GAAG;AACvC,mBAAO,OAAO,GAAG,MAAM,KAAK,CAAC;AAAA,UAC/B;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,IAEA,MAAM,UAAqB,IAAY,UAAmB,MAAY;AAIpE,YAAM,UAAU,MAAM,aAAa;AACnC,UAAI,YAAY,MAAO,QAAO;AAM9B,UAAI,YAAY,oCAAoC,KAAK,QAAQ,GAAG;AAClE,cAAM,IAAI,GAAG,MAAM,iBAAiB;AACpC,YAAI,GAAG;AACL,gBAAM,OAAO,EAAE,CAAC;AAChB,cAAI,QAAQ,YAAY,CAAC,SAAS,IAAI,GAAG;AACvC,kBAAM,IAAI,MAAM,KAAK,QAAQ,KAAK,IAAI,SAAS,UAAU;AAAA,cACvD,GAAG;AAAA,cACH,UAAU;AAAA,YACZ,CAAC;AACD,gBAAI,EAAG,QAAO,EAAE;AAAA,UAClB;AAAA,QACF;AAAA,MACF;AAMA,UAAI,CAAC,SAAS,aAAa,YAAY,kBAAkB,KAAK,EAAE,GAAG;AACjE,cAAM,IAAI,MAAM,KAAK,QAAQ,IAAI,UAAU,EAAE,GAAG,MAAM,UAAU,KAAK,CAAC;AACtE,YAAI,KAAK,6CAA6C,KAAK,EAAE,EAAE,GAAG;AAChE,iBAAO,EAAE,GAAG,QAAQ,mBAAmB,SAAS;AAAA,QAClD;AAAA,MACF;AAEA,aAAO,YAAY,EAAE,KAAK;AAAA,IAC5B;AAAA,EACF;AACF;AAEA,IAAO,eAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
package/src/dom/reconcile.ts
CHANGED
|
@@ -1068,14 +1068,15 @@ function attachRef(fiber: Fiber, value: any): void {
|
|
|
1068
1068
|
const ref = fiber.ref ?? (fiber.pendingProps?.ref ?? null)
|
|
1069
1069
|
if (!ref) return
|
|
1070
1070
|
if (typeof ref === 'function') {
|
|
1071
|
-
|
|
1072
|
-
|
|
1071
|
+
// Match React's commit-phase semantics: callback refs run after render
|
|
1072
|
+
// (during the layout/commit phase), not during render. Calling them
|
|
1073
|
+
// synchronously here breaks libraries that assert no event handlers run
|
|
1074
|
+
// during render (e.g. base-ui's useStableCallback trampoline).
|
|
1075
|
+
scheduleLifecycle(fiber, () => {
|
|
1076
|
+
const cleanup = ref(value)
|
|
1073
1077
|
fiber.cleanups ||= []
|
|
1074
|
-
fiber.cleanups.push(cleanup)
|
|
1075
|
-
}
|
|
1076
|
-
fiber.cleanups ||= []
|
|
1077
|
-
fiber.cleanups.push(() => ref(null))
|
|
1078
|
-
}
|
|
1078
|
+
fiber.cleanups.push(typeof cleanup === 'function' ? cleanup : () => ref(null))
|
|
1079
|
+
})
|
|
1079
1080
|
} else {
|
|
1080
1081
|
ref.current = value
|
|
1081
1082
|
}
|
|
@@ -1088,11 +1089,10 @@ function syncRefIfChanged(fiber: Fiber, value: any): void {
|
|
|
1088
1089
|
}
|
|
1089
1090
|
|
|
1090
1091
|
function detachRef(ref: any): void {
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
} else if (ref && typeof ref === 'object') {
|
|
1092
|
+
// Function refs are handled via fiber.cleanups (queued in attachRef during
|
|
1093
|
+
// the commit phase): the cleanup either invokes the user-returned cleanup
|
|
1094
|
+
// fn or calls ref(null). Calling ref(null) here would double-fire it.
|
|
1095
|
+
if (ref && typeof ref === 'object') {
|
|
1096
1096
|
ref.current = null
|
|
1097
1097
|
}
|
|
1098
1098
|
}
|
package/src/dom/root.ts
CHANGED
|
@@ -36,8 +36,18 @@ export function createRoot(container: Element | DocumentFragment, options: RootO
|
|
|
36
36
|
rootFiber.root = root
|
|
37
37
|
rootFiber.stateNode = container
|
|
38
38
|
|
|
39
|
+
let firstRender = true
|
|
39
40
|
return {
|
|
40
41
|
render(children) {
|
|
42
|
+
if (firstRender) {
|
|
43
|
+
firstRender = false
|
|
44
|
+
// Match real React's `clearContainer` semantics: blow away any pre-render
|
|
45
|
+
// markup (server-rendered placeholder, splash shells, etc.) on the
|
|
46
|
+
// initial commit so it doesn't stack with the React tree.
|
|
47
|
+
if ((container as Node).nodeType === 1 /* ELEMENT_NODE */) {
|
|
48
|
+
;(container as Element).textContent = ''
|
|
49
|
+
}
|
|
50
|
+
}
|
|
41
51
|
flushSyncWork(() => {
|
|
42
52
|
renderRoot(root, children)
|
|
43
53
|
})
|
package/src/vite/index.ts
CHANGED
|
@@ -306,35 +306,33 @@ export function redact(options: RedactOptions = {}): any {
|
|
|
306
306
|
const excludeList = entries.map(([k]) => k)
|
|
307
307
|
// Single package — only one name to dedupe / no-external.
|
|
308
308
|
const noExt = ['@tanstack/redact']
|
|
309
|
-
// Top-level resolve.alias so `react` → `@tanstack/redact` happens
|
|
310
|
-
// BEFORE any plugin-based resolveId hook fires. The Cloudflare
|
|
311
|
-
// vite-plugin's rolldown worker-runner pre-scans the worker entry's
|
|
312
|
-
// exports and resolves bare specifiers via Vite's alias map directly
|
|
313
|
-
// (not via plugin hooks), so without this it would resolve `react` to
|
|
314
|
-
// the real npm package and try to `require()` it in a Worker (no CJS
|
|
315
|
-
// support). Object form is required — array form is silently ignored
|
|
316
|
-
// by rolldown's worker-runner.
|
|
317
309
|
const aliasMap = Object.fromEntries(entries.filter(([from, to]) => from !== to))
|
|
318
|
-
// Scope optimizeDeps to client + ssr environments ONLY. Do NOT set a
|
|
319
|
-
// top-level optimizeDeps — in Vite 6+ that's effectively the client
|
|
320
|
-
// env's default but also seeps into the rsc env's `'use client'`
|
|
321
|
-
// analysis, causing flood warnings like "inconsistently optimized".
|
|
322
310
|
// Dedupe `@tanstack/redact` so Vite resolves it to a single instance
|
|
323
311
|
// even when multiple packages (e.g. @tanstack/react-router and user
|
|
324
312
|
// code) drag it into different parts of the module graph.
|
|
325
313
|
const dedupe = noExt
|
|
314
|
+
// Scope `resolve.alias` to client + ssr environments ONLY. Do NOT set
|
|
315
|
+
// a top-level alias: it would apply to the `rsc` environment too,
|
|
316
|
+
// where `@vitejs/plugin-rsc`'s vendored `react-server-dom-server`
|
|
317
|
+
// imports `react` and needs the *real* React (with the `.d` field on
|
|
318
|
+
// ReactSharedInternals that our shim deliberately doesn't have).
|
|
319
|
+
// Aliasing `react` → `@tanstack/redact` in the RSC env crashes Flight
|
|
320
|
+
// serialization. The Cloudflare vite-plugin's rolldown worker-runner
|
|
321
|
+
// also pre-scans bare specifiers via Vite's alias map (not plugin
|
|
322
|
+
// hooks), but it scans within the *ssr* environment specifically —
|
|
323
|
+
// so per-env `environments.ssr.resolve.alias` covers it. The
|
|
324
|
+
// `enforce: 'pre'` resolveId hook below already skips RSC, so the
|
|
325
|
+
// remaining concern is alias placement. Object form is required —
|
|
326
|
+
// array form is silently ignored by rolldown's worker-runner.
|
|
326
327
|
return {
|
|
327
|
-
resolve: {
|
|
328
|
-
alias: aliasMap,
|
|
329
|
-
dedupe,
|
|
330
|
-
},
|
|
331
328
|
environments: {
|
|
332
329
|
client: {
|
|
333
330
|
optimizeDeps: { exclude: excludeList },
|
|
331
|
+
resolve: { alias: aliasMap, dedupe },
|
|
334
332
|
},
|
|
335
333
|
ssr: {
|
|
336
334
|
optimizeDeps: { exclude: excludeList },
|
|
337
|
-
resolve: { noExternal: noExt },
|
|
335
|
+
resolve: { alias: aliasMap, dedupe, noExternal: noExt },
|
|
338
336
|
},
|
|
339
337
|
},
|
|
340
338
|
ssr: { noExternal: noExt },
|