@tanstack/redact 0.0.16 → 0.0.18
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/attributes.d.ts +1 -0
- package/dist/core/attributes.js +19 -0
- package/dist/core/attributes.js.map +7 -0
- package/dist/core/internal.d.ts +2 -1
- package/dist/core/internal.js.map +2 -2
- package/dist/dom/dispatcher.js +3 -1
- package/dist/dom/dispatcher.js.map +2 -2
- package/dist/dom/dom.js +9 -7
- package/dist/dom/dom.js.map +2 -2
- package/dist/dom/features/hydration/full.d.ts +1 -0
- package/dist/dom/features/hydration/full.js +42 -42
- 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 +3 -1
- package/dist/dom/root-internal.js.map +2 -2
- package/dist/server/escape.d.ts +1 -2
- package/dist/server/escape.js +3 -13
- package/dist/server/escape.js.map +2 -2
- package/dist/server/walk.d.ts +1 -0
- package/dist/server/walk.js +9 -4
- package/dist/server/walk.js.map +2 -2
- package/package.json +5 -5
- package/src/core/attributes.ts +17 -0
- package/src/core/internal.ts +2 -1
- package/src/dom/dispatcher.ts +3 -1
- package/src/dom/dom.ts +10 -7
- package/src/dom/features/hydration/full.ts +44 -45
- package/src/dom/features/hydration/stub.ts +4 -0
- package/src/dom/reconcile.ts +13 -2
- package/src/dom/root-internal.ts +3 -1
- package/src/server/escape.ts +4 -13
- package/src/server/walk.ts +10 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function attributeName(name: string, isSvg?: boolean): string;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// packages/redact/src/core/attributes.ts
|
|
2
|
+
function attributeName(name, isSvg = false) {
|
|
3
|
+
if (isSvg && name !== "viewBox" && SVG_KEBAB_PREFIX.test(name)) {
|
|
4
|
+
return name.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase());
|
|
5
|
+
}
|
|
6
|
+
if (name === "className") return "class";
|
|
7
|
+
if (name === "htmlFor") return "for";
|
|
8
|
+
if (name === "httpEquiv") return "http-equiv";
|
|
9
|
+
if (name === "acceptCharset") return "accept-charset";
|
|
10
|
+
if (name === "crossOrigin") return "crossorigin";
|
|
11
|
+
if (name === "noModule") return "nomodule";
|
|
12
|
+
if (name === "viewBox") return "viewBox";
|
|
13
|
+
return name.startsWith("aria-") || name.startsWith("data-") ? name : name.toLowerCase();
|
|
14
|
+
}
|
|
15
|
+
var SVG_KEBAB_PREFIX = /^(?:clip|fill|stroke)/;
|
|
16
|
+
export {
|
|
17
|
+
attributeName
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=attributes.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/core/attributes.ts"],
|
|
4
|
+
"sourcesContent": ["export function attributeName(name: string, isSvg = false): string {\n if (isSvg && name !== 'viewBox' && SVG_KEBAB_PREFIX.test(name)) {\n return name.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase())\n }\n if (name === 'className') return 'class'\n if (name === 'htmlFor') return 'for'\n if (name === 'httpEquiv') return 'http-equiv'\n if (name === 'acceptCharset') return 'accept-charset'\n if (name === 'crossOrigin') return 'crossorigin'\n if (name === 'noModule') return 'nomodule'\n if (name === 'viewBox') return 'viewBox'\n return name.startsWith('aria-') || name.startsWith('data-')\n ? name\n : name.toLowerCase()\n}\n\nconst SVG_KEBAB_PREFIX = /^(?:clip|fill|stroke)/\n"],
|
|
5
|
+
"mappings": ";AAAO,SAAS,cAAc,MAAc,QAAQ,OAAe;AACjE,MAAI,SAAS,SAAS,aAAa,iBAAiB,KAAK,IAAI,GAAG;AAC9D,WAAO,KAAK,QAAQ,UAAU,CAAC,MAAM,MAAM,EAAE,YAAY,CAAC;AAAA,EAC5D;AACA,MAAI,SAAS,YAAa,QAAO;AACjC,MAAI,SAAS,UAAW,QAAO;AAC/B,MAAI,SAAS,YAAa,QAAO;AACjC,MAAI,SAAS,gBAAiB,QAAO;AACrC,MAAI,SAAS,cAAe,QAAO;AACnC,MAAI,SAAS,WAAY,QAAO;AAChC,MAAI,SAAS,UAAW,QAAO;AAC/B,SAAO,KAAK,WAAW,OAAO,KAAK,KAAK,WAAW,OAAO,IACtD,OACA,KAAK,YAAY;AACvB;AAEA,IAAM,mBAAmB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/core/internal.d.ts
CHANGED
|
@@ -52,7 +52,8 @@ export interface FiberRoot {
|
|
|
52
52
|
re?: ((err: unknown) => void) | undefined;
|
|
53
53
|
ce?: ((err: unknown) => void) | undefined;
|
|
54
54
|
ue?: ((err: unknown) => void) | undefined;
|
|
55
|
-
i: string;
|
|
55
|
+
i: string | undefined;
|
|
56
|
+
ic: number;
|
|
56
57
|
h: boolean;
|
|
57
58
|
}
|
|
58
59
|
export declare function createFiber(tag: FiberTag, type: any, key: string | null): Fiber;
|
|
@@ -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 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
|
-
"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;
|
|
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
|
+
"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?.i ?? ':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,qBAAqB;AAEjC,MAAI,OAAO,qBAAqB;AAEhC,MAAI,QAAQ,GAAG;AACb,QAAI,MAAM,OAAO;AACf,2BAAqB,IAAI,MAAM;AAC/B,aAAO,MAAM;AAAA,IACf;AACA,UAAMA,KAAU,EAAE,GAAG,QAAW,GAAG,QAAW,GAAG,QAAW,GAAG,QAAW,GAAG,KAAK;AAClF,UAAM,QAAQA;AACd,yBAAqB,IAAIA;AACzB,WAAOA;AAAA,EACT;AAEA,MAAI,QAAQ,KAAK,GAAG;AAClB,yBAAqB,IAAI,KAAK;AAC9B,WAAO,KAAK;AAAA,EACd;AAEA,QAAM,IAAU,EAAE,GAAG,QAAW,GAAG,QAAW,GAAG,QAAW,GAAG,QAAW,GAAG,KAAK;AAClF,MAAI,KAAM,MAAK,IAAI;AAAA,MACd,OAAM,QAAQ;AACnB,uBAAqB,IAAI;AACzB,SAAO;AACT;AAEA,SAAS,UACP,GACA,GACS;AACT,MAAI,MAAM,EAAG,QAAO;AACpB,MAAI,CAAC,KAAK,CAAC,EAAG,QAAO;AACrB,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,QAAI,CAAC,OAAO,GAAG,E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AAI,GAAG;AACnD,eAAO,KAAK;AAAA,MACd;AACA,YAAM,QAAQ,QAAQ;AACtB,WAAK,IAAI;AACT,WAAK,IAAI;AACT,aAAO;AAAA,IACT;AAAA,IAEA,YAAgC,IAAO,MAAkC;AACvE,aAAO,KAAK,QAAQ,MAAM,IAAI,IAAI;AAAA,IACpC;AAAA,IAEA,WAAc,KAAa;AACzB,YAAM,QAAQ,gBAAgB;AAC9B,aAAO,YAAY,OAAO,GAAG;AAAA,IAC/B;AAAA,IAEA,oBAAuB,KAAU,SAAkB,MAA+B;AAChF,YAAM,OAAO,SAAS;AACtB,UAAI,KAAK,MAAM,UAAa,UAAU,KAAK,GAAG,IAAI,EAAG;AACrD,WAAK,IAAI;AACT,YAAM,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,gBAAgB;AAC9B,QAAM,MAAM,qBAAqB;AAEjC,MAAI,OAAO,qBAAqB;AAEhC,MAAI,QAAQ,GAAG;AACb,QAAI,MAAM,OAAO;AACf,2BAAqB,IAAI,MAAM;AAC/B,aAAO,MAAM;AAAA,IACf;AACA,UAAMA,KAAU,EAAE,GAAG,QAAW,GAAG,QAAW,GAAG,QAAW,GAAG,QAAW,GAAG,KAAK;AAClF,UAAM,QAAQA;AACd,yBAAqB,IAAIA;AACzB,WAAOA;AAAA,EACT;AAEA,MAAI,QAAQ,KAAK,GAAG;AAClB,yBAAqB,IAAI,KAAK;AAC9B,WAAO,KAAK;AAAA,EACd;AAEA,QAAM,IAAU,EAAE,GAAG,QAAW,GAAG,QAAW,GAAG,QAAW,GAAG,QAAW,GAAG,KAAK;AAClF,MAAI,KAAM,MAAK,IAAI;AAAA,MACd,OAAM,QAAQ;AACnB,uBAAqB,IAAI;AACzB,SAAO;AACT;AAEA,SAAS,UACP,GACA,GACS;AACT,MAAI,MAAM,EAAG,QAAO;AACpB,MAAI,CAAC,KAAK,CAAC,EAAG,QAAO;AACrB,MAAI,EAAE,WAAW,EAAE,OAAQ,QAAO;AAClC,WAAS,IAAI,GAAG,IAAI,EAAE,QAAQ,KAAK;AACjC,QAAI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|
|
7
7
|
}
|
package/dist/dom/dom.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// packages/redact/src/dom/dom.ts
|
|
2
|
+
import { attributeName } from "../core/attributes";
|
|
2
3
|
var SVG_NS = "http://www.w3.org/2000/svg";
|
|
3
4
|
var BOOLEAN_ATTRS = /* @__PURE__ */ new Set([
|
|
4
5
|
"allowfullscreen",
|
|
@@ -50,6 +51,7 @@ function isSvgElement(el) {
|
|
|
50
51
|
}
|
|
51
52
|
function setProp(el, name, next, prev, isSvg) {
|
|
52
53
|
if (name === "children" || name === "key" || name === "ref") return;
|
|
54
|
+
const attr = attributeName(name, isSvg);
|
|
53
55
|
if (name === "defaultValue" || name === "defaultChecked") {
|
|
54
56
|
if (prev === void 0 && next != null) {
|
|
55
57
|
try {
|
|
@@ -103,26 +105,26 @@ function setProp(el, name, next, prev, isSvg) {
|
|
|
103
105
|
}
|
|
104
106
|
}
|
|
105
107
|
if (BOOLEAN_ATTRS.has(name.toLowerCase())) {
|
|
106
|
-
if (next) el.setAttribute(
|
|
107
|
-
else el.removeAttribute(
|
|
108
|
+
if (next) el.setAttribute(attr, "");
|
|
109
|
+
else el.removeAttribute(attr);
|
|
108
110
|
return;
|
|
109
111
|
}
|
|
110
112
|
if (name.length > 5 && (name.charCodeAt(0) === 97 || name.charCodeAt(0) === 100)) {
|
|
111
113
|
if (name.startsWith("aria-") || name.startsWith("data-")) {
|
|
112
114
|
if (next == null) {
|
|
113
|
-
el.removeAttribute(
|
|
115
|
+
el.removeAttribute(attr);
|
|
114
116
|
} else {
|
|
115
|
-
el.setAttribute(
|
|
117
|
+
el.setAttribute(attr, "" + next);
|
|
116
118
|
}
|
|
117
119
|
return;
|
|
118
120
|
}
|
|
119
121
|
}
|
|
120
122
|
if (next == null || next === false) {
|
|
121
|
-
el.removeAttribute(
|
|
123
|
+
el.removeAttribute(attr);
|
|
122
124
|
} else if (next === true) {
|
|
123
|
-
el.setAttribute(
|
|
125
|
+
el.setAttribute(attr, "");
|
|
124
126
|
} else {
|
|
125
|
-
el.setAttribute(
|
|
127
|
+
el.setAttribute(attr, "" + next);
|
|
126
128
|
}
|
|
127
129
|
}
|
|
128
130
|
function setStyle(el, next, prev) {
|
package/dist/dom/dom.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/dom/dom.ts"],
|
|
4
|
-
"sourcesContent": ["
|
|
5
|
-
"mappings": ";AAAA,IAAM,SAAS;AAEf,IAAM,gBAAgB,oBAAI,IAAI;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAED,IAAM,YAAY,oBAAI,IAAI;AAAA,EACxB;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAEM,SAAS,eAAe,MAAc,OAAyB;AACpE,MAAI,SAAS,SAAS,OAAO;AAC3B,WAAO,SAAS,gBAAgB,QAAQ,IAAI;AAAA,EAC9C;AACA,SAAO,SAAS,cAAc,IAAI;AACpC;AAEO,SAAS,aAAa,IAAsB;AACjD,SAAQ,GAAW,oBAAoB,UAAa,GAAG,YAAY;AACrE;AAEO,SAAS,QACd,IACA,MACA,MACA,MACA,OACM;AACN,MAAI,SAAS,cAAc,SAAS,SAAS,SAAS,MAAO;
|
|
4
|
+
"sourcesContent": ["import { attributeName } from '../core/attributes'\n\nconst SVG_NS = 'http://www.w3.org/2000/svg'\n\nconst BOOLEAN_ATTRS = new Set([\n 'allowfullscreen',\n 'async',\n 'autofocus',\n 'autoplay',\n 'checked',\n 'controls',\n 'default',\n 'defer',\n 'disabled',\n 'formnovalidate',\n 'hidden',\n 'inert',\n 'ismap',\n 'itemscope',\n 'loop',\n 'multiple',\n 'muted',\n 'nomodule',\n 'novalidate',\n 'open',\n 'playsinline',\n 'readonly',\n 'required',\n 'reversed',\n 'selected',\n])\n\nconst IDL_ATTRS = new Set([\n 'value',\n 'checked',\n 'selected',\n 'disabled',\n 'multiple',\n 'muted',\n 'readonly',\n 'contentEditable',\n 'spellcheck',\n 'draggable',\n])\n\nexport function createHostNode(type: string, isSvg: boolean): Element {\n if (isSvg || type === 'svg') {\n return document.createElementNS(SVG_NS, type)\n }\n return document.createElement(type)\n}\n\nexport function isSvgElement(el: Element): boolean {\n return (el as any).ownerSVGElement !== undefined || el.tagName === 'svg'\n}\n\nexport function setProp(\n el: Element,\n name: string,\n next: any,\n prev: any,\n isSvg: boolean,\n): void {\n if (name === 'children' || name === 'key' || name === 'ref') return\n const attr = attributeName(name, isSvg)\n\n // defaultValue / defaultChecked are IDL-property-only \u2014 they seed the\n // initial value/checked of a form control on first mount and must NOT be\n // emitted as HTML attributes (which would leak as `defaultValue=\"...\"`).\n // Setting `el.defaultValue` on a fresh control also sets the initial\n // `el.value`, which is what consumers expect. Skip on hydrated DOM so we\n // don't clobber a live user-typed value.\n if (name === 'defaultValue' || name === 'defaultChecked') {\n if (prev === undefined && next != null) {\n try {\n ;(el as any)[name] = next\n } catch {}\n }\n return\n }\n\n if (name === 'className') {\n if (isSvg) {\n if (next == null) el.removeAttribute('class')\n else el.setAttribute('class', '' + next)\n } else {\n ;(el as HTMLElement).className = next == null ? '' : '' + next\n }\n return\n }\n\n if (name === 'class') {\n if (next == null) el.removeAttribute('class')\n else el.setAttribute('class', '' + next)\n return\n }\n\n if (name === 'style') {\n setStyle(el as HTMLElement, next, prev)\n return\n }\n\n if (name === 'dangerouslySetInnerHTML') {\n const nextHtml = next?.__html ?? ''\n const prevHtml = prev?.__html ?? ''\n if (nextHtml !== prevHtml) (el as HTMLElement).innerHTML = nextHtml\n return\n }\n\n if (name[0] === 'o' && name[1] === 'n') {\n setEventHandler(el, name, next, prev)\n return\n }\n\n if (name === 'htmlFor') {\n if (next == null) el.removeAttribute('for')\n else el.setAttribute('for', '' + next)\n return\n }\n\n if (!isSvg && IDL_ATTRS.has(name) && name in el) {\n try {\n ;(el as any)[name] = next == null ? '' : next\n return\n } catch {}\n }\n\n if (BOOLEAN_ATTRS.has(name.toLowerCase())) {\n if (next) el.setAttribute(attr, '')\n else el.removeAttribute(attr)\n return\n }\n\n // aria-* and data-* attributes stringify booleans to `\"true\"`/`\"false\"`\n // rather than using the HTML boolean-attribute presence/absence semantics.\n // This matches React and the ARIA spec (aria-hidden=\"false\" is meaningful).\n if (name.length > 5 && (name.charCodeAt(0) === 97 /* a */ || name.charCodeAt(0) === 100 /* d */)) {\n if (name.startsWith('aria-') || name.startsWith('data-')) {\n if (next == null) {\n el.removeAttribute(attr)\n } else {\n el.setAttribute(attr, '' + next)\n }\n return\n }\n }\n\n if (next == null || next === false) {\n el.removeAttribute(attr)\n } else if (next === true) {\n el.setAttribute(attr, '')\n } else {\n el.setAttribute(attr, '' + next)\n }\n}\n\nfunction setStyle(el: HTMLElement, next: any, prev: any): void {\n const style = el.style\n if (typeof next === 'string') {\n style.cssText = next\n return\n }\n if (typeof prev === 'string') style.cssText = ''\n if (prev && typeof prev === 'object') {\n for (const k in prev) {\n if (!next || !(k in next)) setStyleProperty(style, k, '')\n }\n }\n if (next && typeof next === 'object') {\n for (const k in next) {\n if (!prev || prev[k] !== next[k]) setStyleProperty(style, k, next[k])\n }\n }\n}\n\nfunction setStyleProperty(style: CSSStyleDeclaration, key: string, value: any): void {\n if (key[0] === '-') {\n style.setProperty(key, value == null ? '' : '' + value)\n } else if (value == null || value === '') {\n ;(style as any)[key] = ''\n } else if (typeof value === 'number' && !UNITLESS_STYLE.has(key)) {\n ;(style as any)[key] = value + 'px'\n } else {\n ;(style as any)[key] = '' + value\n }\n}\n\nconst UNITLESS_STYLE = new Set([\n 'animationIterationCount',\n 'borderImageOutset',\n 'borderImageSlice',\n 'borderImageWidth',\n 'boxFlex',\n 'boxFlexGroup',\n 'boxOrdinalGroup',\n 'columnCount',\n 'columns',\n 'flex',\n 'flexGrow',\n 'flexPositive',\n 'flexShrink',\n 'flexNegative',\n 'flexOrder',\n 'gridArea',\n 'gridRow',\n 'gridRowEnd',\n 'gridRowSpan',\n 'gridRowStart',\n 'gridColumn',\n 'gridColumnEnd',\n 'gridColumnSpan',\n 'gridColumnStart',\n 'fontWeight',\n 'lineClamp',\n 'lineHeight',\n 'opacity',\n 'order',\n 'orphans',\n 'tabSize',\n 'widows',\n 'zIndex',\n 'zoom',\n 'fillOpacity',\n 'floodOpacity',\n 'stopOpacity',\n 'strokeDasharray',\n 'strokeDashoffset',\n 'strokeMiterlimit',\n 'strokeOpacity',\n 'strokeWidth',\n])\n\nexport interface SyntheticEvent extends Event {\n nativeEvent: Event\n isDefaultPrevented(): boolean\n isPropagationStopped(): boolean\n persist(): void\n currentTarget: EventTarget & Element\n}\n\nfunction setEventHandler(el: Element, name: string, next: any, prev: any): void {\n // Only function handlers are accepted. Reject strings/objects/etc \u2014 the\n // legacy `onclick=\"...\"` HTML attribute (string handler) is a known XSS\n // vector if a parent spreads untrusted props onto a host element. React\n // also ignores non-function handlers.\n if (next != null && typeof next != 'function') next = null\n\n const capture = name.endsWith('Capture')\n const reactEventName = name.slice(2, capture ? -7 : undefined)\n const eventName = domEventFor(reactEventName, el)\n\n // Key by the React prop name (not DOM event name) so `onChange` and\n // `onInput` on the same text input \u2014 which both dispatch from the native\n // `input` event \u2014 can coexist without clobbering each other's handlers.\n const handlers = ((el as any).__handlers ||= Object.create(null))\n const key = name\n\n const existing = handlers[key]\n\n if (existing && !next) {\n el.removeEventListener(existing.event, existing.listener, existing.capture)\n handlers[key] = null\n return\n }\n\n if (!existing && next) {\n const entry = {\n current: next as Function,\n listener: null as any,\n event: eventName,\n capture,\n }\n entry.listener = (e: Event) => {\n // React hands handlers a SyntheticEvent that carries `.nativeEvent`.\n // Many libraries check `event.nativeEvent.isComposing` (react-instantsearch)\n // or `event.nativeEvent.shiftKey` (UI kits) \u2014 without the alias they throw\n // on `undefined.foo`. Aliasing the native event to itself is the cheapest\n // way to satisfy the shape without building a full synthetic layer.\n if ((e as any).nativeEvent === undefined) (e as any).nativeEvent = e\n entry.current(e)\n }\n handlers[key] = entry\n el.addEventListener(eventName, entry.listener, capture)\n return\n }\n\n if (existing) {\n // Re-bind if the effective DOM event changed (e.g. <input> whose `type`\n // flipped from \"text\" to \"checkbox\" \u2014 onChange should now follow `change`\n // instead of `input`). This is rare but keeps semantics correct.\n if (existing.event !== eventName || existing.capture !== capture) {\n el.removeEventListener(existing.event, existing.listener, existing.capture)\n existing.event = eventName\n existing.capture = capture\n el.addEventListener(eventName, existing.listener, capture)\n }\n existing.current = next\n }\n}\n\nfunction domEventFor(reactEventName: string, el: Element): string {\n const lower = reactEventName.toLowerCase()\n // React's `onChange` on text-like <input> and <textarea> maps to the\n // native `input` event so handlers fire on every keystroke. On checkbox,\n // radio, file inputs, and <select>, React's `onChange` maps to the\n // native `change` event (which fires on click / option select).\n if (lower === 'change') {\n const tag = el.tagName\n if (tag === 'TEXTAREA') return 'input'\n if (tag === 'INPUT') {\n const type = ((el as HTMLInputElement).type || 'text').toLowerCase()\n if (type !== 'checkbox' && type !== 'radio' && type !== 'file') {\n return 'input'\n }\n }\n }\n if (lower === 'doubleclick') return 'dblclick'\n return lower\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,qBAAqB;AAE9B,IAAM,SAAS;AAEf,IAAM,gBAAgB,oBAAI,IAAI;AAAA,EAC5B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAC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B;AAChE,QAAM,QAAQ,eAAe,YAAY;AAKzC,MAAI,UAAU,UAAU;AACtB,UAAM,MAAM,GAAG;AACf,QAAI,QAAQ,WAAY,QAAO;AAC/B,QAAI,QAAQ,SAAS;AACnB,YAAM,QAAS,GAAwB,QAAQ,QAAQ,YAAY;AACnE,UAAI,SAAS,cAAc,SAAS,WAAW,SAAS,QAAQ;AAC9D,eAAO;AAAA,MACT;AAAA,IACF;AAAA,EACF;AACA,MAAI,UAAU,cAAe,QAAO;AACpC,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
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;
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
FiberTag,
|
|
4
4
|
REACT_ELEMENT_TYPE
|
|
5
5
|
} from "../../../core";
|
|
6
|
+
import { attributeName } from "../../../core/attributes";
|
|
6
7
|
import { createHostNode, setProp } from "../../dom";
|
|
7
8
|
import { drainReplayQueue } from "../../event-replay";
|
|
8
9
|
import { discardPendingWork, findRoot, flushSyncWork, renderRoot } from "../../reconcile";
|
|
@@ -107,7 +108,6 @@ function hydrateRootImpl(container, initialChildren, options) {
|
|
|
107
108
|
const root = createFiberRoot(target, options);
|
|
108
109
|
installHydrationScrollGuard();
|
|
109
110
|
const normalizedInitialChildren = isDocument ? normalizeDocumentChildren(initialChildren) : initialChildren;
|
|
110
|
-
let documentBodyFallback = false;
|
|
111
111
|
let hydrationError = null;
|
|
112
112
|
beginHydration(root);
|
|
113
113
|
try {
|
|
@@ -118,34 +118,7 @@ function hydrateRootImpl(container, initialChildren, options) {
|
|
|
118
118
|
hydrationError = e;
|
|
119
119
|
}
|
|
120
120
|
endHydration(root);
|
|
121
|
-
if (hydrationError)
|
|
122
|
-
if (!isHydrationBailout(hydrationError)) {
|
|
123
|
-
throw hydrationError;
|
|
124
|
-
}
|
|
125
|
-
let recoveryContainer = target;
|
|
126
|
-
let recoveryChildren = normalizedInitialChildren;
|
|
127
|
-
const hostRecovery = getRecoverableHostChildren(hydrationError);
|
|
128
|
-
if (hostRecovery) {
|
|
129
|
-
recoveryContainer = hostRecovery[0];
|
|
130
|
-
recoveryChildren = hostRecovery[1];
|
|
131
|
-
} else if (body) {
|
|
132
|
-
const bodyChildren = getRecoverableDocumentBodyChildren(hydrationError);
|
|
133
|
-
if (bodyChildren != null) {
|
|
134
|
-
documentBodyFallback = true;
|
|
135
|
-
recoveryContainer = body;
|
|
136
|
-
recoveryChildren = bodyChildren;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
resetAfterHydrationFailure(root, recoveryContainer);
|
|
140
|
-
try {
|
|
141
|
-
flushSyncWork(() => {
|
|
142
|
-
renderRoot(root, recoveryChildren);
|
|
143
|
-
});
|
|
144
|
-
} catch (clientError) {
|
|
145
|
-
resetAfterHydrationFailure(root, recoveryContainer);
|
|
146
|
-
throw clientError;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
121
|
+
if (hydrationError && !recoverHydration(root, hydrationError)) throw hydrationError;
|
|
149
122
|
drainReplayQueue();
|
|
150
123
|
return {
|
|
151
124
|
render(children) {
|
|
@@ -153,7 +126,7 @@ function hydrateRootImpl(container, initialChildren, options) {
|
|
|
153
126
|
const normalized = isDocument ? normalizeDocumentChildren(children) : children;
|
|
154
127
|
renderRoot(
|
|
155
128
|
root,
|
|
156
|
-
|
|
129
|
+
root.c === body ? getStaticDocumentBodyChildren(normalized) ?? normalized : normalized
|
|
157
130
|
);
|
|
158
131
|
});
|
|
159
132
|
},
|
|
@@ -166,7 +139,7 @@ function hydrateRootImpl(container, initialChildren, options) {
|
|
|
166
139
|
}
|
|
167
140
|
var HEAD_KEY_ATTRS = {
|
|
168
141
|
link: ["rel", "href", "sizes", "type"],
|
|
169
|
-
meta: ["name", "property", "
|
|
142
|
+
meta: ["name", "property", "charSet", "httpEquiv"],
|
|
170
143
|
script: ["src", "type"]
|
|
171
144
|
};
|
|
172
145
|
var DOCUMENT_HEAD_TAGS = /* @__PURE__ */ new Set(["base", "link", "meta", "script", "style", "title"]);
|
|
@@ -174,18 +147,16 @@ var CLAIMED = /* @__PURE__ */ new WeakSet();
|
|
|
174
147
|
function headAttrsMatch(el, props, keys) {
|
|
175
148
|
if (CLAIMED.has(el)) return false;
|
|
176
149
|
if (!keys) return true;
|
|
177
|
-
let matched = false;
|
|
178
150
|
for (const k of keys) {
|
|
179
|
-
const propVal = props[k]
|
|
180
|
-
const elVal = el.getAttribute(k);
|
|
151
|
+
const propVal = props[k];
|
|
152
|
+
const elVal = el.getAttribute(attributeName(k));
|
|
181
153
|
if (propVal == null && elVal == null) continue;
|
|
182
|
-
|
|
183
|
-
if (propVal == null || elVal == null) continue;
|
|
184
|
-
if (String(propVal) !== elVal) return false;
|
|
154
|
+
if (propVal == null || elVal == null || String(propVal) !== elVal) return false;
|
|
185
155
|
}
|
|
186
|
-
return
|
|
156
|
+
return true;
|
|
187
157
|
}
|
|
188
158
|
function beginHydration(root) {
|
|
159
|
+
root.ic = 0;
|
|
189
160
|
root.h = true;
|
|
190
161
|
hydrationCursors.set(root.r, new HydrationCursor(root.c));
|
|
191
162
|
}
|
|
@@ -366,6 +337,30 @@ function isSafeHostRecoveryElement(fiber) {
|
|
|
366
337
|
const tag = fiber.type.toLowerCase();
|
|
367
338
|
return tag !== "html" && tag !== "head" && tag !== "body";
|
|
368
339
|
}
|
|
340
|
+
function recoverHydration(root, error) {
|
|
341
|
+
if (!isHydrationBailout(error)) return false;
|
|
342
|
+
let container = root.c;
|
|
343
|
+
let children = root.r.pp?.children ?? null;
|
|
344
|
+
const hostRecovery = getRecoverableHostChildren(error);
|
|
345
|
+
if (hostRecovery) {
|
|
346
|
+
container = hostRecovery[0];
|
|
347
|
+
children = hostRecovery[1];
|
|
348
|
+
} else if (container.nodeType === 9) {
|
|
349
|
+
const bodyChildren = getRecoverableDocumentBodyChildren(error);
|
|
350
|
+
if (bodyChildren != null) {
|
|
351
|
+
container = container.body;
|
|
352
|
+
children = bodyChildren;
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
resetAfterHydrationFailure(root, container);
|
|
356
|
+
try {
|
|
357
|
+
flushSyncWork(() => renderRoot(root, children));
|
|
358
|
+
} catch (clientError) {
|
|
359
|
+
resetAfterHydrationFailure(root, container);
|
|
360
|
+
throw clientError;
|
|
361
|
+
}
|
|
362
|
+
return true;
|
|
363
|
+
}
|
|
369
364
|
function resetAfterHydrationFailure(root, container) {
|
|
370
365
|
discardPendingWork(root);
|
|
371
366
|
clearHydrationContainer(container);
|
|
@@ -491,9 +486,13 @@ function validateHydrationProps(fiber, el, props, tag, isSvg) {
|
|
|
491
486
|
const value = props[k];
|
|
492
487
|
if (k === "children" || k === "key" || k === "ref" || k === "suppressHydrationWarning" || k === "suppressContentEditableWarning" || k[0] === "o" && k[1] === "n" && typeof value == "function") continue;
|
|
493
488
|
if (k === "dangerouslySetInnerHTML") {
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
489
|
+
let html = "" + (value?.__html ?? "");
|
|
490
|
+
if (tag !== "script" && tag !== "style") {
|
|
491
|
+
const probe = document.createElement("div");
|
|
492
|
+
probe.innerHTML = html;
|
|
493
|
+
html = probe.innerHTML;
|
|
494
|
+
}
|
|
495
|
+
if (el.innerHTML !== html) {
|
|
497
496
|
if (true) {
|
|
498
497
|
failHydration(
|
|
499
498
|
fiber,
|
|
@@ -553,7 +552,7 @@ function validateHydrationProps(fiber, el, props, tag, isSvg) {
|
|
|
553
552
|
continue;
|
|
554
553
|
}
|
|
555
554
|
const stringifiedBoolean = k.startsWith("aria-") || k.startsWith("data-");
|
|
556
|
-
const attr = k
|
|
555
|
+
const attr = attributeName(k, isSvg);
|
|
557
556
|
let expectedValue;
|
|
558
557
|
if (value == null || value === false && !stringifiedBoolean) {
|
|
559
558
|
expectedValue = null;
|
|
@@ -594,6 +593,7 @@ export {
|
|
|
594
593
|
hydrateRootImpl,
|
|
595
594
|
installHydrationScrollGuard,
|
|
596
595
|
isHydrationBailout,
|
|
596
|
+
recoverHydration,
|
|
597
597
|
setHydrationCursor,
|
|
598
598
|
tryConsumeBoundary
|
|
599
599
|
};
|