@tanstack/redact 0.0.17 → 0.0.19
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/core/internal.d.ts +1 -1
- package/dist/core/internal.js.map +1 -1
- package/dist/dom/dispatcher.js +3 -1
- package/dist/dom/dispatcher.js.map +2 -2
- package/dist/dom/features/hydration/full.d.ts +1 -0
- package/dist/dom/features/hydration/full.js +118 -114
- package/dist/dom/features/hydration/full.js.map +2 -2
- package/dist/dom/features/hydration/stub.d.ts +1 -0
- package/dist/dom/features/hydration/stub.js +4 -0
- package/dist/dom/features/hydration/stub.js.map +2 -2
- package/dist/dom/reconcile.js +9 -3
- package/dist/dom/reconcile.js.map +2 -2
- package/dist/dom/root-internal.js +1 -1
- package/dist/dom/root-internal.js.map +2 -2
- package/package.json +5 -5
- package/src/core/internal.ts +1 -1
- package/src/dom/dispatcher.ts +3 -3
- package/src/dom/features/hydration/full.ts +168 -121
- package/src/dom/features/hydration/stub.ts +4 -0
- package/src/dom/reconcile.ts +13 -2
- package/src/dom/root-internal.ts +1 -1
package/dist/core/internal.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/core/internal.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ReactElement, ReactNode, Ref } from './types'\n\nexport const enum FiberTag {\n Host = 0,\n Text = 1,\n Function = 2,\n Class = 3,\n Fragment = 4,\n Portal = 5,\n Provider = 6,\n Consumer = 7,\n ForwardRef = 8,\n Memo = 9,\n Lazy = 10,\n Suspense = 11,\n Root = 12,\n}\n\nexport interface Hook {\n s: any\n q: any\n d: any\n c: any\n n: Hook | null\n}\n\nexport interface Effect {\n t: 0 | 1\n c: () => any\n}\n\nexport interface Fiber {\n tag: FiberTag\n type: any\n key: string | null\n ref: Ref<any> | null\n pp: any\n mp: any\n ms: any\n sn: any\n dom: Node | null\n parent: Fiber | null\n child: Fiber | null\n sibling: Fiber | null\n hooks: Hook | null\n cu: Array<() => void> | null\n dy: boolean\n um: boolean\n root: FiberRoot | null\n}\n\nexport interface FiberRoot {\n c: Element | DocumentFragment\n r: Fiber\n p: Set<Fiber>\n s: boolean\n re?: ((err: unknown) => void) | undefined\n ce?: ((err: unknown) => void) | undefined\n ue?: ((err: unknown) => void) | undefined\n i: string\n ic: number\n h: boolean\n}\n\nexport function createFiber(tag: FiberTag, type: any, key: string | null): Fiber {\n return {\n tag,\n type,\n key,\n ref: null,\n pp: null,\n mp: null,\n ms: null,\n sn: null,\n dom: null,\n parent: null,\n child: null,\n sibling: null,\n hooks: null,\n cu: null,\n dy: false,\n um: false,\n root: null,\n }\n}\n\nexport type ChildNode = ReactElement | string | number | boolean | null | undefined | ChildNode[]\nexport type { ReactElement, ReactNode }\n"],
|
|
4
|
+
"sourcesContent": ["import type { ReactElement, ReactNode, Ref } from './types'\n\nexport const enum FiberTag {\n Host = 0,\n Text = 1,\n Function = 2,\n Class = 3,\n Fragment = 4,\n Portal = 5,\n Provider = 6,\n Consumer = 7,\n ForwardRef = 8,\n Memo = 9,\n Lazy = 10,\n Suspense = 11,\n Root = 12,\n}\n\nexport interface Hook {\n s: any\n q: any\n d: any\n c: any\n n: Hook | null\n}\n\nexport interface Effect {\n t: 0 | 1\n c: () => any\n}\n\nexport interface Fiber {\n tag: FiberTag\n type: any\n key: string | null\n ref: Ref<any> | null\n pp: any\n mp: any\n ms: any\n sn: any\n dom: Node | null\n parent: Fiber | null\n child: Fiber | null\n sibling: Fiber | null\n hooks: Hook | null\n cu: Array<() => void> | null\n dy: boolean\n um: boolean\n root: FiberRoot | null\n}\n\nexport interface FiberRoot {\n c: Element | DocumentFragment\n r: Fiber\n p: Set<Fiber>\n s: boolean\n re?: ((err: unknown) => void) | undefined\n ce?: ((err: unknown) => void) | undefined\n ue?: ((err: unknown) => void) | undefined\n i: string | undefined\n ic: number\n h: boolean\n}\n\nexport function createFiber(tag: FiberTag, type: any, key: string | null): Fiber {\n return {\n tag,\n type,\n key,\n ref: null,\n pp: null,\n mp: null,\n ms: null,\n sn: null,\n dom: null,\n parent: null,\n child: null,\n sibling: null,\n hooks: null,\n cu: null,\n dy: false,\n um: false,\n root: null,\n }\n}\n\nexport type ChildNode = ReactElement | string | number | boolean | null | undefined | ChildNode[]\nexport type { ReactElement, ReactNode }\n"],
|
|
5
5
|
"mappings": ";AAEO,IAAW,WAAX,kBAAWA,cAAX;AACL,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,cAAW,KAAX;AACA,EAAAA,oBAAA,WAAQ,KAAR;AACA,EAAAA,oBAAA,cAAW,KAAX;AACA,EAAAA,oBAAA,YAAS,KAAT;AACA,EAAAA,oBAAA,cAAW,KAAX;AACA,EAAAA,oBAAA,cAAW,KAAX;AACA,EAAAA,oBAAA,gBAAa,KAAb;AACA,EAAAA,oBAAA,UAAO,KAAP;AACA,EAAAA,oBAAA,UAAO,MAAP;AACA,EAAAA,oBAAA,cAAW,MAAX;AACA,EAAAA,oBAAA,UAAO,MAAP;AAbgB,SAAAA;AAAA,GAAA;AA8DX,SAAS,YAAY,KAAe,MAAW,KAA2B;AAC/E,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,KAAK;AAAA,IACL,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,OAAO;AAAA,IACP,SAAS;AAAA,IACT,OAAO;AAAA,IACP,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,IAAI;AAAA,IACJ,MAAM;AAAA,EACR;AACF;",
|
|
6
6
|
"names": ["FiberTag"]
|
|
7
7
|
}
|
package/dist/dom/dispatcher.js
CHANGED
|
@@ -173,7 +173,9 @@ function makeDispatcherImpl() {
|
|
|
173
173
|
if (hook.s === void 0) {
|
|
174
174
|
const fiber = getCurrentFiber();
|
|
175
175
|
const root = findRootFromFiber(fiber);
|
|
176
|
-
|
|
176
|
+
const prefix = root?.i ?? (root?.h ? ":R" : ":r");
|
|
177
|
+
const id = root?.h ? root.ic++ : idCounter++;
|
|
178
|
+
hook.s = prefix + id.toString(36);
|
|
177
179
|
}
|
|
178
180
|
return hook.s;
|
|
179
181
|
},
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dom/dispatcher.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Hook, Fiber, FiberRoot, Effect } from '../core'\nimport { ReactSharedInternals, REACT_CONTEXT_TYPE } from '../react'\nimport { scheduleUpdate, enqueueEffect, readContext } from './reconcile'\n\nfunction getCurrentFiber(): Fiber {\n const f = ReactSharedInternals.F\n if (!f) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Hook called outside a function component render.')\n }\n throw new Error()\n }\n return f\n}\n\nfunction nextHook(): Hook {\n const fiber = getCurrentFiber()\n const idx = ReactSharedInternals.I++\n\n let prev = ReactSharedInternals.K\n\n if (idx === 0) {\n if (fiber.hooks) {\n ReactSharedInternals.K = fiber.hooks\n return fiber.hooks\n }\n const h: Hook = { s: undefined, q: undefined, d: undefined, c: undefined, n: null }\n fiber.hooks = h\n ReactSharedInternals.K = h\n return h\n }\n\n if (prev && prev.n) {\n ReactSharedInternals.K = prev.n\n return prev.n\n }\n\n const h: Hook = { s: undefined, q: undefined, d: undefined, c: undefined, n: null }\n if (prev) prev.n = h\n else fiber.hooks = h\n ReactSharedInternals.K = h\n return h\n}\n\nfunction depsEqual(\n a: ReadonlyArray<unknown> | undefined,\n b: ReadonlyArray<unknown> | undefined,\n): boolean {\n if (a === b) return true\n if (!a || !b) return false\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) {\n if (!Object.is(a[i], b[i])) return false\n }\n return true\n}\n\ntype BasicStateAction<S> = S | ((p: S) => S)\n\n// Singleton \u2014 every method reads render context via ReactSharedInternals,\n// and per-hook closures live on the hook itself, so nothing is render-local\n// to capture. Allocating a fresh wrapper + 17 method closures per function-\n// component render was pure GC pressure.\nconst DISPATCHER = makeDispatcherImpl()\n\nexport function makeDispatcher() {\n return DISPATCHER\n}\n\nfunction makeDispatcherImpl() {\n return {\n useState<S>(initial: S | (() => S)): [S, (a: BasicStateAction<S>) => void] {\n return this.useReducer(\n basicReducer as (state: S, action: BasicStateAction<S>) => S,\n typeof initial == 'function' ? (initial as () => S)() : initial,\n )\n },\n\n useReducer<S, A>(reducer: (s: S, a: A) => S, initialArg: any, init?: (a: any) => S) {\n const hook = nextHook()\n const fiber = getCurrentFiber()\n if (hook.q === undefined) {\n hook.s = init ? init(initialArg) : initialArg\n const queue: any = { r: reducer }\n const dispatch = (action: A) => {\n const currentState = hook.s as S\n const next = queue.r(currentState, action)\n if (!Object.is(next, currentState)) {\n hook.s = next\n scheduleUpdate(fiber)\n }\n }\n queue.d = dispatch\n hook.q = queue\n } else {\n hook.q.r = reducer\n }\n return [hook.s, hook.q.d] as [S, (a: A) => void]\n },\n\n useEffect(create: () => any, deps?: ReadonlyArray<unknown>) {\n const hook = nextHook()\n const fiber = getCurrentFiber()\n const prevDeps = hook.d\n if (prevDeps !== undefined && depsEqual(prevDeps, deps)) return\n hook.d = deps\n const effect: Effect = {\n t: 0,\n c: () => {\n // Run the prior cleanup INSIDE the effect run, not during the\n // dispatch/render phase. If render A \u2192 B \u2192 C all happen back-to-\n // back before the passive microtask drains, dispatch-time cleanup\n // only fires once (between A\u2192B) and fx B + C both run fresh,\n // leaving two side-fx (e.g. two plot SVGs) in the DOM. Doing\n // it here, at effect-run time, means every new create first tears\n // down whatever cleanup is currently live on the hook.\n if (hook.c) {\n try { hook.c() } catch {}\n // The prior cleanup was also pushed onto fiber.cu; remove\n // it so unmount doesn't double-call it.\n if (fiber.cu) {\n const i = fiber.cu.indexOf(hook.c)\n if (i >= 0) fiber.cu.splice(i, 1)\n }\n hook.c = null\n }\n const c = create()\n hook.c = typeof c == 'function' ? c : null\n return hook.c\n },\n }\n enqueueEffect(fiber, effect)\n },\n\n useLayoutEffect(create: () => any, deps?: ReadonlyArray<unknown>) {\n const hook = nextHook()\n const fiber = getCurrentFiber()\n const prevDeps = hook.d\n if (prevDeps !== undefined && depsEqual(prevDeps, deps)) return\n hook.d = deps\n const effect: Effect = {\n t: 1,\n c: () => {\n // Mirror useEffect: tear down the prior cleanup at run time so\n // coalesced renders don't leak side-fx.\n if (hook.c) {\n try { hook.c() } catch {}\n if (fiber.cu) {\n const i = fiber.cu.indexOf(hook.c)\n if (i >= 0) fiber.cu.splice(i, 1)\n }\n hook.c = null\n }\n const c = create()\n hook.c = typeof c == 'function' ? c : null\n return hook.c\n },\n }\n enqueueEffect(fiber, effect)\n },\n\n useInsertionEffect(create: () => any, deps?: ReadonlyArray<unknown>) {\n return this.useLayoutEffect(create, deps)\n },\n\n useRef<T>(initial: T) {\n const hook = nextHook()\n if (hook.s === undefined) hook.s = { current: initial }\n return hook.s as { current: T }\n },\n\n useMemo<T>(factory: () => T, deps?: ReadonlyArray<unknown>) {\n const hook = nextHook()\n if (hook.d !== undefined && depsEqual(hook.d, deps)) {\n return hook.s as T\n }\n const value = factory()\n hook.s = value\n hook.d = deps\n return value\n },\n\n useCallback<T extends Function>(fn: T, deps?: ReadonlyArray<unknown>): T {\n return this.useMemo(() => fn, deps) as T\n },\n\n useContext<T>(ctx: any): T {\n const fiber = getCurrentFiber()\n return readContext(fiber, ctx)\n },\n\n useImperativeHandle<T>(ref: any, factory: () => T, deps?: ReadonlyArray<unknown>) {\n const hook = nextHook()\n if (hook.d !== undefined && depsEqual(hook.d, deps)) return\n hook.d = deps\n const value = factory()\n if (ref) {\n if (typeof ref == 'function') ref(value)\n else ref.current = value\n }\n },\n\n useDebugValue<T>(_value: T, _formatter?: (v: T) => any): void {\n // noop\n },\n\n useId(): string {\n const hook = nextHook()\n if (hook.s === undefined) {\n const fiber = getCurrentFiber()\n const root = findRootFromFiber(fiber)\n hook.s = root\n ? root.i + (root.ic++).toString(36)\n : ':r' + (idCounter++).toString(36)\n }\n return hook.s as string\n },\n\n useTransition(): [boolean, (fn: () => void) => void] {\n return [false, (fn: () => void) => fn()]\n },\n\n useDeferredValue<T>(v: T): T {\n return v\n },\n\n useSyncExternalStore<T>(\n subscribe: (cb: () => void) => () => void,\n getSnapshot: () => T,\n getServerSnapshot?: () => T,\n ): T {\n const fiber = getCurrentFiber()\n const hook = nextHook()\n const store: {\n g: () => T\n s: (() => T) | undefined\n } = hook.q ?? {\n g: getSnapshot,\n s: getServerSnapshot,\n }\n hook.q = store\n store.g = getSnapshot\n store.s = getServerSnapshot\n\n // During hydration, use the server snapshot (if provided) so the tree\n // matches the SSR output. Components like TanStack Router's ClientOnly\n // rely on this: they render `false` on server, `true` on client \u2014 and\n // if we return `true` during hydration, client and server diverge and\n // the tree mounts fresh next to the SSR fallback DOM.\n const root = fiber.root ?? findRootFromFiber(fiber)\n const isHydrating = Boolean(root?.h)\n const value =\n isHydrating && getServerSnapshot ? getServerSnapshot() : getSnapshot()\n hook.s = value\n\n const deps = [subscribe]\n if (hook.d === undefined || !depsEqual(hook.d, deps)) {\n hook.d = deps\n const effect: Effect = {\n t: 1,\n c: () => {\n if (hook.c) {\n try {\n hook.c()\n } catch {\n // ignore cleanup failures\n }\n if (fiber.cu) {\n const i = fiber.cu.indexOf(hook.c)\n if (i >= 0) fiber.cu.splice(i, 1)\n }\n hook.c = null\n }\n\n let unsubscribed = false\n const cleanup = () => {\n unsubscribed = true\n if (typeof unsubscribe == 'function') {\n unsubscribe()\n }\n }\n const forceUpdate = () => {\n if (unsubscribed || fiber.um) {\n return\n }\n\n let next: T\n try {\n next = store.g()\n } catch {\n scheduleUpdate(fiber)\n return\n }\n\n if (!Object.is(hook.s, next)) {\n hook.s = next\n scheduleUpdate(fiber)\n }\n }\n const unsubscribe = subscribe(forceUpdate)\n\n // If we served the server snapshot, run a post-hydration check so\n // components like `useHydrated()` flip from false \u2192 true after the\n // initial render commits. Queued late so hydration finishes first.\n if (isHydrating && store.s) {\n queueMicrotask(() => queueMicrotask(forceUpdate))\n }\n\n forceUpdate()\n hook.c = cleanup\n return cleanup\n },\n }\n enqueueEffect(fiber, effect)\n }\n return value\n },\n\n use<T>(resource: any): T {\n if (resource == null) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('use() received null or undefined')\n }\n throw new Error()\n }\n if (resource.$$typeof === REACT_CONTEXT_TYPE) {\n return readContext(getCurrentFiber(), resource)\n }\n if (typeof resource.then == 'function') {\n const thenable = resource\n switch (thenable.status) {\n case 'fulfilled':\n return thenable.value\n case 'rejected':\n throw thenable.reason\n default: {\n if (thenable.status === undefined) {\n thenable.status = 'pending'\n thenable.then(\n (v: any) => {\n if (thenable.status === 'pending') {\n thenable.status = 'fulfilled'\n thenable.value = v\n }\n },\n (e: any) => {\n if (thenable.status === 'pending') {\n thenable.status = 'rejected'\n thenable.reason = e\n }\n },\n )\n }\n throw thenable\n }\n }\n }\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('use() expected a Promise or Context')\n }\n throw new Error()\n },\n }\n}\n\nfunction basicReducer<S>(state: S, action: BasicStateAction<S>): S {\n return typeof action == 'function' ? (action as (p: S) => S)(state) : action\n}\n\nlet idCounter = 0\n\nfunction findRootFromFiber(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"],
|
|
5
|
-
"mappings": ";AACA,SAAS,sBAAsB,0BAA0B;AACzD,SAAS,gBAAgB,eAAe,mBAAmB;AAE3D,SAAS,kBAAyB;AAChC,QAAM,IAAI,qBAAqB;AAC/B,MAAI,CAAC,GAAG;AACN,QAAI,MAAuC;AACzC,YAAM,IAAI,MAAM,kDAAkD;AAAA,IACpE;AACA,UAAM,IAAI,MAAM;AAAA,EAClB;AACA,SAAO;AACT;AAEA,SAAS,WAAiB;AACxB,QAAM,QAAQ,gBAAgB;AAC9B,QAAM,MAAM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M,QAAQ,QAAQ;AACtB,UAAI,KAAK;AACP,YAAI,OAAO,OAAO,WAAY,KAAI,KAAK;AAAA,YAClC,KAAI,UAAU;AAAA,MACrB;AAAA,IACF;AAAA,IAEA,cAAiB,QAAW,YAAkC;AAAA,IAE9D;AAAA,IAEA,QAAgB;AACd,YAAM,OAAO,SAAS;AACtB,UAAI,KAAK,MAAM,QAAW;AACxB,cAAM,QAAQ,gBAAgB;AAC9B,cAAM,OAAO,kBAAkB,KAAK;AACpC,
|
|
4
|
+
"sourcesContent": ["import type { Hook, Fiber, FiberRoot, Effect } from '../core'\nimport { ReactSharedInternals, REACT_CONTEXT_TYPE } from '../react'\nimport { scheduleUpdate, enqueueEffect, readContext } from './reconcile'\n\nfunction getCurrentFiber(): Fiber {\n const f = ReactSharedInternals.F\n if (!f) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Hook called outside a function component render.')\n }\n throw new Error()\n }\n return f\n}\n\nfunction nextHook(): Hook {\n const fiber = getCurrentFiber()\n const idx = ReactSharedInternals.I++\n\n let prev = ReactSharedInternals.K\n\n if (idx === 0) {\n if (fiber.hooks) {\n ReactSharedInternals.K = fiber.hooks\n return fiber.hooks\n }\n const h: Hook = { s: undefined, q: undefined, d: undefined, c: undefined, n: null }\n fiber.hooks = h\n ReactSharedInternals.K = h\n return h\n }\n\n if (prev && prev.n) {\n ReactSharedInternals.K = prev.n\n return prev.n\n }\n\n const h: Hook = { s: undefined, q: undefined, d: undefined, c: undefined, n: null }\n if (prev) prev.n = h\n else fiber.hooks = h\n ReactSharedInternals.K = h\n return h\n}\n\nfunction depsEqual(\n a: ReadonlyArray<unknown> | undefined,\n b: ReadonlyArray<unknown> | undefined,\n): boolean {\n if (a === b) return true\n if (!a || !b) return false\n if (a.length !== b.length) return false\n for (let i = 0; i < a.length; i++) {\n if (!Object.is(a[i], b[i])) return false\n }\n return true\n}\n\ntype BasicStateAction<S> = S | ((p: S) => S)\n\n// Singleton \u2014 every method reads render context via ReactSharedInternals,\n// and per-hook closures live on the hook itself, so nothing is render-local\n// to capture. Allocating a fresh wrapper + 17 method closures per function-\n// component render was pure GC pressure.\nconst DISPATCHER = makeDispatcherImpl()\n\nexport function makeDispatcher() {\n return DISPATCHER\n}\n\nfunction makeDispatcherImpl() {\n return {\n useState<S>(initial: S | (() => S)): [S, (a: BasicStateAction<S>) => void] {\n return this.useReducer(\n basicReducer as (state: S, action: BasicStateAction<S>) => S,\n typeof initial == 'function' ? (initial as () => S)() : initial,\n )\n },\n\n useReducer<S, A>(reducer: (s: S, a: A) => S, initialArg: any, init?: (a: any) => S) {\n const hook = nextHook()\n const fiber = getCurrentFiber()\n if (hook.q === undefined) {\n hook.s = init ? init(initialArg) : initialArg\n const queue: any = { r: reducer }\n const dispatch = (action: A) => {\n const currentState = hook.s as S\n const next = queue.r(currentState, action)\n if (!Object.is(next, currentState)) {\n hook.s = next\n scheduleUpdate(fiber)\n }\n }\n queue.d = dispatch\n hook.q = queue\n } else {\n hook.q.r = reducer\n }\n return [hook.s, hook.q.d] as [S, (a: A) => void]\n },\n\n useEffect(create: () => any, deps?: ReadonlyArray<unknown>) {\n const hook = nextHook()\n const fiber = getCurrentFiber()\n const prevDeps = hook.d\n if (prevDeps !== undefined && depsEqual(prevDeps, deps)) return\n hook.d = deps\n const effect: Effect = {\n t: 0,\n c: () => {\n // Run the prior cleanup INSIDE the effect run, not during the\n // dispatch/render phase. If render A \u2192 B \u2192 C all happen back-to-\n // back before the passive microtask drains, dispatch-time cleanup\n // only fires once (between A\u2192B) and fx B + C both run fresh,\n // leaving two side-fx (e.g. two plot SVGs) in the DOM. Doing\n // it here, at effect-run time, means every new create first tears\n // down whatever cleanup is currently live on the hook.\n if (hook.c) {\n try { hook.c() } catch {}\n // The prior cleanup was also pushed onto fiber.cu; remove\n // it so unmount doesn't double-call it.\n if (fiber.cu) {\n const i = fiber.cu.indexOf(hook.c)\n if (i >= 0) fiber.cu.splice(i, 1)\n }\n hook.c = null\n }\n const c = create()\n hook.c = typeof c == 'function' ? c : null\n return hook.c\n },\n }\n enqueueEffect(fiber, effect)\n },\n\n useLayoutEffect(create: () => any, deps?: ReadonlyArray<unknown>) {\n const hook = nextHook()\n const fiber = getCurrentFiber()\n const prevDeps = hook.d\n if (prevDeps !== undefined && depsEqual(prevDeps, deps)) return\n hook.d = deps\n const effect: Effect = {\n t: 1,\n c: () => {\n // Mirror useEffect: tear down the prior cleanup at run time so\n // coalesced renders don't leak side-fx.\n if (hook.c) {\n try { hook.c() } catch {}\n if (fiber.cu) {\n const i = fiber.cu.indexOf(hook.c)\n if (i >= 0) fiber.cu.splice(i, 1)\n }\n hook.c = null\n }\n const c = create()\n hook.c = typeof c == 'function' ? c : null\n return hook.c\n },\n }\n enqueueEffect(fiber, effect)\n },\n\n useInsertionEffect(create: () => any, deps?: ReadonlyArray<unknown>) {\n return this.useLayoutEffect(create, deps)\n },\n\n useRef<T>(initial: T) {\n const hook = nextHook()\n if (hook.s === undefined) hook.s = { current: initial }\n return hook.s as { current: T }\n },\n\n useMemo<T>(factory: () => T, deps?: ReadonlyArray<unknown>) {\n const hook = nextHook()\n if (hook.d !== undefined && depsEqual(hook.d, deps)) {\n return hook.s as T\n }\n const value = factory()\n hook.s = value\n hook.d = deps\n return value\n },\n\n useCallback<T extends Function>(fn: T, deps?: ReadonlyArray<unknown>): T {\n return this.useMemo(() => fn, deps) as T\n },\n\n useContext<T>(ctx: any): T {\n const fiber = getCurrentFiber()\n return readContext(fiber, ctx)\n },\n\n useImperativeHandle<T>(ref: any, factory: () => T, deps?: ReadonlyArray<unknown>) {\n const hook = nextHook()\n if (hook.d !== undefined && depsEqual(hook.d, deps)) return\n hook.d = deps\n const value = factory()\n if (ref) {\n if (typeof ref == 'function') ref(value)\n else ref.current = value\n }\n },\n\n useDebugValue<T>(_value: T, _formatter?: (v: T) => any): void {\n // noop\n },\n\n useId(): string {\n const hook = nextHook()\n if (hook.s === undefined) {\n const fiber = getCurrentFiber()\n const root = findRootFromFiber(fiber)\n const prefix = root?.i ?? (root?.h ? ':R' : ':r')\n const id = root?.h ? root.ic++ : idCounter++\n hook.s = prefix + id.toString(36)\n }\n return hook.s as string\n },\n\n useTransition(): [boolean, (fn: () => void) => void] {\n return [false, (fn: () => void) => fn()]\n },\n\n useDeferredValue<T>(v: T): T {\n return v\n },\n\n useSyncExternalStore<T>(\n subscribe: (cb: () => void) => () => void,\n getSnapshot: () => T,\n getServerSnapshot?: () => T,\n ): T {\n const fiber = getCurrentFiber()\n const hook = nextHook()\n const store: {\n g: () => T\n s: (() => T) | undefined\n } = hook.q ?? {\n g: getSnapshot,\n s: getServerSnapshot,\n }\n hook.q = store\n store.g = getSnapshot\n store.s = getServerSnapshot\n\n // During hydration, use the server snapshot (if provided) so the tree\n // matches the SSR output. Components like TanStack Router's ClientOnly\n // rely on this: they render `false` on server, `true` on client \u2014 and\n // if we return `true` during hydration, client and server diverge and\n // the tree mounts fresh next to the SSR fallback DOM.\n const root = fiber.root ?? findRootFromFiber(fiber)\n const isHydrating = Boolean(root?.h)\n const value =\n isHydrating && getServerSnapshot ? getServerSnapshot() : getSnapshot()\n hook.s = value\n\n const deps = [subscribe]\n if (hook.d === undefined || !depsEqual(hook.d, deps)) {\n hook.d = deps\n const effect: Effect = {\n t: 1,\n c: () => {\n if (hook.c) {\n try {\n hook.c()\n } catch {\n // ignore cleanup failures\n }\n if (fiber.cu) {\n const i = fiber.cu.indexOf(hook.c)\n if (i >= 0) fiber.cu.splice(i, 1)\n }\n hook.c = null\n }\n\n let unsubscribed = false\n const cleanup = () => {\n unsubscribed = true\n if (typeof unsubscribe == 'function') {\n unsubscribe()\n }\n }\n const forceUpdate = () => {\n if (unsubscribed || fiber.um) {\n return\n }\n\n let next: T\n try {\n next = store.g()\n } catch {\n scheduleUpdate(fiber)\n return\n }\n\n if (!Object.is(hook.s, next)) {\n hook.s = next\n scheduleUpdate(fiber)\n }\n }\n const unsubscribe = subscribe(forceUpdate)\n\n // If we served the server snapshot, run a post-hydration check so\n // components like `useHydrated()` flip from false \u2192 true after the\n // initial render commits. Queued late so hydration finishes first.\n if (isHydrating && store.s) {\n queueMicrotask(() => queueMicrotask(forceUpdate))\n }\n\n forceUpdate()\n hook.c = cleanup\n return cleanup\n },\n }\n enqueueEffect(fiber, effect)\n }\n return value\n },\n\n use<T>(resource: any): T {\n if (resource == null) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('use() received null or undefined')\n }\n throw new Error()\n }\n if (resource.$$typeof === REACT_CONTEXT_TYPE) {\n return readContext(getCurrentFiber(), resource)\n }\n if (typeof resource.then == 'function') {\n const thenable = resource\n switch (thenable.status) {\n case 'fulfilled':\n return thenable.value\n case 'rejected':\n throw thenable.reason\n default: {\n if (thenable.status === undefined) {\n thenable.status = 'pending'\n thenable.then(\n (v: any) => {\n if (thenable.status === 'pending') {\n thenable.status = 'fulfilled'\n thenable.value = v\n }\n },\n (e: any) => {\n if (thenable.status === 'pending') {\n thenable.status = 'rejected'\n thenable.reason = e\n }\n },\n )\n }\n throw thenable\n }\n }\n }\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('use() expected a Promise or Context')\n }\n throw new Error()\n },\n }\n}\n\nfunction basicReducer<S>(state: S, action: BasicStateAction<S>): S {\n return typeof action == 'function' ? (action as (p: S) => S)(state) : action\n}\n\nlet idCounter = 0\n\nfunction findRootFromFiber(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"],
|
|
5
|
+
"mappings": ";AACA,SAAS,sBAAsB,0BAA0B;AACzD,SAAS,gBAAgB,eAAe,mBAAmB;AAE3D,SAAS,kBAAyB;AAChC,QAAM,IAAI,qBAAqB;AAC/B,MAAI,CAAC,GAAG;AACN,QAAI,MAAuC;AACzC,YAAM,IAAI,MAAM,kDAAkD;AAAA,IACpE;AACA,UAAM,IAAI,MAAM;AAAA,EAClB;AACA,SAAO;AACT;AAEA,SAAS,WAAiB;AACxB,QAAM,QAAQ,gBAAg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;AAAA,UACjB,SAAS;AACP,gBAAI,SAAS,WAAW,QAAW;AACjC,uBAAS,SAAS;AAClB,uBAAS;AAAA,gBACP,CAAC,MAAW;AACV,sBAAI,SAAS,WAAW,WAAW;AACjC,6BAAS,SAAS;AAClB,6BAAS,QAAQ;AAAA,kBACnB;AAAA,gBACF;AAAA,gBACA,CAAC,MAAW;AACV,sBAAI,SAAS,WAAW,WAAW;AACjC,6BAAS,SAAS;AAClB,6BAAS,SAAS;AAAA,kBACpB;AAAA,gBACF;AAAA,cACF;AAAA,YACF;AACA,kBAAM;AAAA,UACR;AAAA,QACF;AAAA,MACF;AACA,UAAI,MAAuC;AACzC,cAAM,IAAI,MAAM,qCAAqC;AAAA,MACvD;AACA,YAAM,IAAI,MAAM;AAAA,IAClB;AAAA,EACF;AACF;AAEA,SAAS,aAAgB,OAAU,QAAgC;AACjE,SAAO,OAAO,UAAU,aAAc,OAAuB,KAAK,IAAI;AACxE;AAEA,IAAI,YAAY;AAEhB,SAAS,kBAAkB,OAAgC;AACzD,MAAI,IAAkB;AACtB,SAAO,GAAG;AACR,QAAI,EAAE,KAAM,QAAO,EAAE;AACrB,QAAI,EAAE;AAAA,EACR;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["h"]
|
|
7
7
|
}
|
|
@@ -71,3 +71,4 @@ export declare function clearHydrationCursor(hostFiber: Fiber): void;
|
|
|
71
71
|
export declare function adoptHostDom(fiber: Fiber, parent: Fiber): boolean;
|
|
72
72
|
export declare function adoptTextDom(fiber: Fiber, parent: Fiber, text: string): boolean;
|
|
73
73
|
export declare function findHostParent(fiber: Fiber): Fiber;
|
|
74
|
+
export declare function recoverHydration(root: FiberRoot, error: unknown): boolean;
|
|
@@ -85,14 +85,7 @@ var HydrationCursor = class {
|
|
|
85
85
|
has() {
|
|
86
86
|
let n = this.n;
|
|
87
87
|
while (n && n !== this.e) {
|
|
88
|
-
if (n.nodeType === 1)
|
|
89
|
-
if (n.tagName === "SCRIPT") {
|
|
90
|
-
n = n.nextSibling;
|
|
91
|
-
continue;
|
|
92
|
-
}
|
|
93
|
-
return true;
|
|
94
|
-
}
|
|
95
|
-
if (n.nodeType === 3 && n.data.trim() !== "") return true;
|
|
88
|
+
if (n.nodeType === 1 || n.nodeType === 3) return true;
|
|
96
89
|
n = n.nextSibling;
|
|
97
90
|
}
|
|
98
91
|
return false;
|
|
@@ -112,13 +105,9 @@ function hydrateRootImpl(container, initialChildren, options) {
|
|
|
112
105
|
const target = container;
|
|
113
106
|
const isDocument = container.nodeType === 9;
|
|
114
107
|
const body = isDocument ? target.body : null;
|
|
115
|
-
const root = createFiberRoot(target,
|
|
116
|
-
...options,
|
|
117
|
-
identifierPrefix: options.identifierPrefix ?? ":R"
|
|
118
|
-
});
|
|
108
|
+
const root = createFiberRoot(target, options);
|
|
119
109
|
installHydrationScrollGuard();
|
|
120
110
|
const normalizedInitialChildren = isDocument ? normalizeDocumentChildren(initialChildren) : initialChildren;
|
|
121
|
-
let documentBodyFallback = false;
|
|
122
111
|
let hydrationError = null;
|
|
123
112
|
beginHydration(root);
|
|
124
113
|
try {
|
|
@@ -129,36 +118,7 @@ function hydrateRootImpl(container, initialChildren, options) {
|
|
|
129
118
|
hydrationError = e;
|
|
130
119
|
}
|
|
131
120
|
endHydration(root);
|
|
132
|
-
if (hydrationError)
|
|
133
|
-
if (!isHydrationBailout(hydrationError)) {
|
|
134
|
-
throw hydrationError;
|
|
135
|
-
}
|
|
136
|
-
let recoveryContainer = target;
|
|
137
|
-
let recoveryChildren = normalizedInitialChildren;
|
|
138
|
-
const hostRecovery = getRecoverableHostChildren(hydrationError);
|
|
139
|
-
if (hostRecovery) {
|
|
140
|
-
recoveryContainer = hostRecovery[0];
|
|
141
|
-
recoveryChildren = hostRecovery[1];
|
|
142
|
-
} else if (body) {
|
|
143
|
-
const bodyChildren = getRecoverableDocumentBodyChildren(hydrationError);
|
|
144
|
-
if (bodyChildren != null) {
|
|
145
|
-
documentBodyFallback = true;
|
|
146
|
-
recoveryContainer = body;
|
|
147
|
-
recoveryChildren = bodyChildren;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
resetAfterHydrationFailure(root, recoveryContainer);
|
|
151
|
-
try {
|
|
152
|
-
root.i = options.identifierPrefix ?? ":r";
|
|
153
|
-
root.ic = 0;
|
|
154
|
-
flushSyncWork(() => {
|
|
155
|
-
renderRoot(root, recoveryChildren);
|
|
156
|
-
});
|
|
157
|
-
} catch (clientError) {
|
|
158
|
-
resetAfterHydrationFailure(root, recoveryContainer);
|
|
159
|
-
throw clientError;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
121
|
+
if (hydrationError && !recoverHydration(root, hydrationError)) throw hydrationError;
|
|
162
122
|
drainReplayQueue();
|
|
163
123
|
return {
|
|
164
124
|
render(children) {
|
|
@@ -166,7 +126,7 @@ function hydrateRootImpl(container, initialChildren, options) {
|
|
|
166
126
|
const normalized = isDocument ? normalizeDocumentChildren(children) : children;
|
|
167
127
|
renderRoot(
|
|
168
128
|
root,
|
|
169
|
-
|
|
129
|
+
root.c === body ? getStaticDocumentBodyChildren(normalized) ?? normalized : normalized
|
|
170
130
|
);
|
|
171
131
|
});
|
|
172
132
|
},
|
|
@@ -179,26 +139,25 @@ function hydrateRootImpl(container, initialChildren, options) {
|
|
|
179
139
|
}
|
|
180
140
|
var HEAD_KEY_ATTRS = {
|
|
181
141
|
link: ["rel", "href", "sizes", "type"],
|
|
182
|
-
meta: ["name", "property", "
|
|
183
|
-
script: ["src", "type"]
|
|
142
|
+
meta: ["name", "property", "charSet", "httpEquiv"],
|
|
143
|
+
script: ["src", "type"],
|
|
144
|
+
style: ["id", "media", "nonce", "title"]
|
|
184
145
|
};
|
|
185
146
|
var DOCUMENT_HEAD_TAGS = /* @__PURE__ */ new Set(["base", "link", "meta", "script", "style", "title"]);
|
|
186
147
|
var CLAIMED = /* @__PURE__ */ new WeakSet();
|
|
187
148
|
function headAttrsMatch(el, props, keys) {
|
|
188
149
|
if (CLAIMED.has(el)) return false;
|
|
189
150
|
if (!keys) return true;
|
|
190
|
-
let matched = false;
|
|
191
151
|
for (const k of keys) {
|
|
192
|
-
const propVal = props[k]
|
|
193
|
-
const elVal = el.getAttribute(k);
|
|
152
|
+
const propVal = props[k];
|
|
153
|
+
const elVal = el.getAttribute(attributeName(k));
|
|
194
154
|
if (propVal == null && elVal == null) continue;
|
|
195
|
-
|
|
196
|
-
if (propVal == null || elVal == null) continue;
|
|
197
|
-
if (String(propVal) !== elVal) return false;
|
|
155
|
+
if (propVal == null || elVal == null || String(propVal) !== elVal) return false;
|
|
198
156
|
}
|
|
199
|
-
return
|
|
157
|
+
return true;
|
|
200
158
|
}
|
|
201
159
|
function beginHydration(root) {
|
|
160
|
+
root.ic = 0;
|
|
202
161
|
root.h = true;
|
|
203
162
|
hydrationCursors.set(root.r, new HydrationCursor(root.c));
|
|
204
163
|
}
|
|
@@ -275,10 +234,11 @@ function adoptHostDom(fiber, parent) {
|
|
|
275
234
|
fiber.dom = candidate;
|
|
276
235
|
const props = fiber.pp ?? {};
|
|
277
236
|
const isSvg = tag === "svg" || candidate.namespaceURI === "http://www.w3.org/2000/svg" && tag !== "foreignobject";
|
|
237
|
+
const syncHydrationProps = !props.suppressHydrationWarning && canRecoverHydrationPropMismatch(candidate, tag);
|
|
278
238
|
validateHydrationProps(fiber, candidate, props, tag, isSvg);
|
|
279
239
|
for (const k in props) {
|
|
280
|
-
if (k === "children") continue;
|
|
281
|
-
if (k[0] === "o" && k[1] === "n" && typeof props[k] == "function") {
|
|
240
|
+
if (k === "children" || k === "key" || k === "ref" || k === "suppressHydrationWarning" || k === "suppressContentEditableWarning") continue;
|
|
241
|
+
if (syncHydrationProps || k[0] === "o" && k[1] === "n" && typeof props[k] == "function") {
|
|
282
242
|
setProp(candidate, k, props[k], void 0, isSvg);
|
|
283
243
|
}
|
|
284
244
|
}
|
|
@@ -289,16 +249,23 @@ function adoptTextDom(fiber, parent, text) {
|
|
|
289
249
|
const cursor = hydrationCursors.get(findHostParent(parent));
|
|
290
250
|
if (!cursor) return false;
|
|
291
251
|
const candidate = cursor.take();
|
|
292
|
-
if (!candidate)
|
|
252
|
+
if (!candidate) {
|
|
253
|
+
onMismatch(fiber, null);
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
293
256
|
if (candidate.nodeType === 3) {
|
|
294
257
|
if (candidate.data !== text) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
)
|
|
258
|
+
const recovered = failHydration(
|
|
259
|
+
fiber,
|
|
260
|
+
true ? new Error(
|
|
261
|
+
`Hydration text mismatch: expected "${text}" but found "${candidate.data}".`
|
|
262
|
+
) : void 0,
|
|
263
|
+
canRecoverHydrationPropMismatch(candidate)
|
|
264
|
+
);
|
|
265
|
+
if (recovered) {
|
|
266
|
+
;
|
|
267
|
+
candidate.data = text;
|
|
300
268
|
}
|
|
301
|
-
failHydration(fiber);
|
|
302
269
|
}
|
|
303
270
|
fiber.dom = candidate;
|
|
304
271
|
return true;
|
|
@@ -321,23 +288,24 @@ function findHostParent(fiber) {
|
|
|
321
288
|
throw new Error();
|
|
322
289
|
}
|
|
323
290
|
function onMismatch(fiber, actualNode) {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
);
|
|
331
|
-
}
|
|
332
|
-
failHydration(fiber);
|
|
291
|
+
failHydration(
|
|
292
|
+
fiber,
|
|
293
|
+
true ? new Error(
|
|
294
|
+
`Hydration mismatch: expected <${fiber.type ?? "text"}> but found ${actualNode ? actualNode.nodeType === 1 ? actualNode.tagName : "text" : "nothing"}.`
|
|
295
|
+
) : void 0
|
|
296
|
+
);
|
|
333
297
|
}
|
|
334
|
-
function failHydration(fiber, error = new Error(PROD_HYDRATION_ERROR)) {
|
|
298
|
+
function failHydration(fiber, error = new Error(PROD_HYDRATION_ERROR), recoverInPlace = false) {
|
|
335
299
|
const root = findRoot(fiber);
|
|
336
300
|
if (root?.re) {
|
|
337
301
|
root.re(error);
|
|
338
302
|
}
|
|
303
|
+
if (recoverInPlace) return true;
|
|
339
304
|
abortHydration(error, findHostRecoveryParent(fiber) ?? fiber);
|
|
340
305
|
}
|
|
306
|
+
function canRecoverHydrationPropMismatch(node, tag) {
|
|
307
|
+
return tag === "html" || tag === "head" || tag === "body" || !!node.ownerDocument?.head?.contains(node);
|
|
308
|
+
}
|
|
341
309
|
function findHostRecoveryParent(fiber) {
|
|
342
310
|
if (fiber.tag === FiberTag.Text) {
|
|
343
311
|
let directHost = fiber.parent;
|
|
@@ -379,6 +347,30 @@ function isSafeHostRecoveryElement(fiber) {
|
|
|
379
347
|
const tag = fiber.type.toLowerCase();
|
|
380
348
|
return tag !== "html" && tag !== "head" && tag !== "body";
|
|
381
349
|
}
|
|
350
|
+
function recoverHydration(root, error) {
|
|
351
|
+
if (!isHydrationBailout(error)) return false;
|
|
352
|
+
let container = root.c;
|
|
353
|
+
let children = root.r.pp?.children ?? null;
|
|
354
|
+
const hostRecovery = getRecoverableHostChildren(error);
|
|
355
|
+
if (hostRecovery) {
|
|
356
|
+
container = hostRecovery[0];
|
|
357
|
+
children = hostRecovery[1];
|
|
358
|
+
} else if (container.nodeType === 9) {
|
|
359
|
+
const bodyChildren = getRecoverableDocumentBodyChildren(error);
|
|
360
|
+
if (bodyChildren != null) {
|
|
361
|
+
container = container.body;
|
|
362
|
+
children = bodyChildren;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
resetAfterHydrationFailure(root, container);
|
|
366
|
+
try {
|
|
367
|
+
flushSyncWork(() => renderRoot(root, children));
|
|
368
|
+
} catch (clientError) {
|
|
369
|
+
resetAfterHydrationFailure(root, container);
|
|
370
|
+
throw clientError;
|
|
371
|
+
}
|
|
372
|
+
return true;
|
|
373
|
+
}
|
|
382
374
|
function resetAfterHydrationFailure(root, container) {
|
|
383
375
|
discardPendingWork(root);
|
|
384
376
|
clearHydrationContainer(container);
|
|
@@ -499,21 +491,24 @@ function createHostElement(type, props) {
|
|
|
499
491
|
}
|
|
500
492
|
function validateHydrationProps(fiber, el, props, tag, isSvg) {
|
|
501
493
|
if (props.suppressHydrationWarning) return;
|
|
494
|
+
const recoverInPlace = canRecoverHydrationPropMismatch(el, tag);
|
|
502
495
|
let expected;
|
|
503
496
|
for (const k in props) {
|
|
504
497
|
const value = props[k];
|
|
505
498
|
if (k === "children" || k === "key" || k === "ref" || k === "suppressHydrationWarning" || k === "suppressContentEditableWarning" || k[0] === "o" && k[1] === "n" && typeof value == "function") continue;
|
|
506
499
|
if (k === "dangerouslySetInnerHTML") {
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
500
|
+
let html = "" + (value?.__html ?? "");
|
|
501
|
+
if (tag !== "script" && tag !== "style") {
|
|
502
|
+
const probe = document.createElement("div");
|
|
503
|
+
probe.innerHTML = html;
|
|
504
|
+
html = probe.innerHTML;
|
|
505
|
+
}
|
|
506
|
+
if (el.innerHTML !== html) {
|
|
507
|
+
failHydration(
|
|
508
|
+
fiber,
|
|
509
|
+
true ? new Error(`Hydration HTML mismatch inside <${tag}>.`) : void 0,
|
|
510
|
+
recoverInPlace
|
|
511
|
+
);
|
|
517
512
|
}
|
|
518
513
|
continue;
|
|
519
514
|
}
|
|
@@ -522,10 +517,11 @@ function validateHydrationProps(fiber, el, props, tag, isSvg) {
|
|
|
522
517
|
if (tag === "input" || tag === "textarea") {
|
|
523
518
|
if (k === "value" || props.value == null) {
|
|
524
519
|
if (value != null && el.value !== "" + value) {
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
520
|
+
failHydration(
|
|
521
|
+
fiber,
|
|
522
|
+
true ? new Error(`Hydration ${tag} value mismatch on <${tag}>.`) : void 0,
|
|
523
|
+
recoverInPlace
|
|
524
|
+
);
|
|
529
525
|
}
|
|
530
526
|
}
|
|
531
527
|
continue;
|
|
@@ -534,34 +530,37 @@ function validateHydrationProps(fiber, el, props, tag, isSvg) {
|
|
|
534
530
|
if (tag === "input" && (k === "checked" || k === "defaultChecked")) {
|
|
535
531
|
if (k === "checked" || props.checked == null) {
|
|
536
532
|
if (value != null && el.checked !== !!value) {
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
533
|
+
failHydration(
|
|
534
|
+
fiber,
|
|
535
|
+
true ? new Error(`Hydration checked mismatch on <input>.`) : void 0,
|
|
536
|
+
recoverInPlace
|
|
537
|
+
);
|
|
541
538
|
}
|
|
542
539
|
}
|
|
543
540
|
continue;
|
|
544
541
|
}
|
|
545
542
|
if (tag === "option" && k === "selected") {
|
|
546
543
|
if (value != null && el.selected !== !!value) {
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
544
|
+
failHydration(
|
|
545
|
+
fiber,
|
|
546
|
+
true ? new Error(`Hydration selected mismatch on <option>.`) : void 0,
|
|
547
|
+
recoverInPlace
|
|
548
|
+
);
|
|
551
549
|
}
|
|
552
550
|
continue;
|
|
553
551
|
}
|
|
554
552
|
if (k === "style") {
|
|
555
553
|
expected ??= createHostNode(tag, isSvg);
|
|
556
554
|
setProp(expected, k, value, void 0, isSvg);
|
|
557
|
-
if (
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
555
|
+
if (!hydrationStylesMatch(
|
|
556
|
+
el.style,
|
|
557
|
+
expected.style
|
|
558
|
+
)) {
|
|
559
|
+
failHydration(
|
|
560
|
+
fiber,
|
|
561
|
+
true ? new Error(`Hydration style mismatch on <${tag}>.`) : void 0,
|
|
562
|
+
recoverInPlace
|
|
563
|
+
);
|
|
565
564
|
}
|
|
566
565
|
continue;
|
|
567
566
|
}
|
|
@@ -577,21 +576,25 @@ function validateHydrationProps(fiber, el, props, tag, isSvg) {
|
|
|
577
576
|
}
|
|
578
577
|
const actualValue = el.getAttribute(attr);
|
|
579
578
|
if (expectedValue !== actualValue) {
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
`Hydration attribute mismatch on <${tag}> for "${attr}": expected ${formatHydrationValue(expectedValue)} but found ${formatHydrationValue(actualValue)}.`
|
|
588
|
-
)
|
|
589
|
-
);
|
|
590
|
-
}
|
|
591
|
-
failHydration(fiber);
|
|
579
|
+
failHydration(
|
|
580
|
+
fiber,
|
|
581
|
+
true ? new Error(
|
|
582
|
+
`Hydration attribute mismatch on <${tag}> for "${attr}": expected ${formatHydrationValue(expectedValue)} but found ${formatHydrationValue(actualValue)}.`
|
|
583
|
+
) : void 0,
|
|
584
|
+
recoverInPlace
|
|
585
|
+
);
|
|
592
586
|
}
|
|
593
587
|
}
|
|
594
588
|
}
|
|
589
|
+
function hydrationStylesMatch(actual, expected) {
|
|
590
|
+
for (let index = 0; index < expected.length; index++) {
|
|
591
|
+
const property = expected.item(index);
|
|
592
|
+
if (actual.getPropertyValue(property) !== expected.getPropertyValue(property) || actual.getPropertyPriority(property) !== expected.getPropertyPriority(property)) {
|
|
593
|
+
return false;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
return true;
|
|
597
|
+
}
|
|
595
598
|
function formatHydrationValue(value) {
|
|
596
599
|
return value == null ? "nothing" : JSON.stringify(value);
|
|
597
600
|
}
|
|
@@ -610,6 +613,7 @@ export {
|
|
|
610
613
|
hydrateRootImpl,
|
|
611
614
|
installHydrationScrollGuard,
|
|
612
615
|
isHydrationBailout,
|
|
616
|
+
recoverHydration,
|
|
613
617
|
setHydrationCursor,
|
|
614
618
|
tryConsumeBoundary
|
|
615
619
|
};
|