@tanstack/redact 0.0.13 → 0.0.15
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 +23 -39
- package/dist/core/internal.js +7 -23
- package/dist/core/internal.js.map +3 -3
- package/dist/dom/dispatcher.d.ts +3 -1
- package/dist/dom/dispatcher.js +104 -97
- package/dist/dom/dispatcher.js.map +2 -2
- package/dist/dom/dom.js +1 -1
- package/dist/dom/dom.js.map +2 -2
- package/dist/dom/event-replay.js +7 -29
- package/dist/dom/event-replay.js.map +2 -2
- package/dist/dom/features/class/full.js +16 -16
- package/dist/dom/features/class/full.js.map +2 -2
- package/dist/dom/features/class/stub.js +7 -7
- package/dist/dom/features/class/stub.js.map +2 -2
- package/dist/dom/features/context/full.js +7 -7
- package/dist/dom/features/context/full.js.map +2 -2
- package/dist/dom/features/context/stub.js +3 -3
- package/dist/dom/features/context/stub.js.map +2 -2
- package/dist/dom/features/forward-ref/full.js +11 -11
- package/dist/dom/features/forward-ref/full.js.map +2 -2
- package/dist/dom/features/hydration/full.d.ts +26 -14
- package/dist/dom/features/hydration/full.js +412 -92
- package/dist/dom/features/hydration/full.js.map +2 -2
- package/dist/dom/features/hydration/stub.d.ts +13 -12
- package/dist/dom/features/hydration/stub.js +23 -8
- package/dist/dom/features/hydration/stub.js.map +2 -2
- package/dist/dom/features/lazy/full.js +3 -43
- package/dist/dom/features/lazy/full.js.map +2 -2
- package/dist/dom/features/lazy/stub.js +1 -1
- package/dist/dom/features/lazy/stub.js.map +2 -2
- package/dist/dom/features/memo/full.js +3 -3
- package/dist/dom/features/memo/full.js.map +2 -2
- package/dist/dom/features/memo/stub.js +1 -1
- package/dist/dom/features/memo/stub.js.map +2 -2
- package/dist/dom/features/portal/full.js +2 -2
- package/dist/dom/features/portal/full.js.map +2 -2
- package/dist/dom/features/suspense/full.js +151 -109
- package/dist/dom/features/suspense/full.js.map +2 -2
- package/dist/dom/reconcile.d.ts +3 -1
- package/dist/dom/reconcile.js +141 -129
- package/dist/dom/reconcile.js.map +2 -2
- package/dist/dom/root-internal.d.ts +9 -0
- package/dist/dom/root-internal.js +31 -0
- package/dist/dom/root-internal.js.map +7 -0
- package/dist/dom/root.d.ts +1 -1
- package/dist/dom/root.js +4 -136
- package/dist/dom/root.js.map +2 -2
- package/dist/dom/test-utils.js +1 -1
- package/dist/dom/test-utils.js.map +2 -2
- package/dist/react/children.js +4 -1
- package/dist/react/children.js.map +2 -2
- package/dist/react/class.js +8 -2
- package/dist/react/class.js.map +2 -2
- package/dist/react/context.js +4 -1
- package/dist/react/context.js.map +2 -2
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +2 -2
- package/dist/react/shared-internals.d.ts +4 -7
- package/dist/react/shared-internals.js +4 -7
- package/dist/react/shared-internals.js.map +2 -2
- package/dist/server/stream.d.ts +5 -1
- package/dist/server/stream.js.map +2 -2
- package/dist/vite/index.js +19 -3
- package/dist/vite/index.js.map +2 -2
- package/package.json +1 -1
- package/src/core/internal.ts +30 -50
- package/src/dom/dispatcher.ts +114 -105
- package/src/dom/dom.ts +1 -1
- package/src/dom/event-replay.ts +14 -30
- package/src/dom/features/class/full.ts +16 -16
- package/src/dom/features/class/stub.ts +7 -7
- package/src/dom/features/context/full.ts +7 -7
- package/src/dom/features/context/stub.ts +3 -3
- package/src/dom/features/forward-ref/full.ts +11 -11
- package/src/dom/features/hydration/full.ts +516 -104
- package/src/dom/features/hydration/stub.ts +28 -14
- package/src/dom/features/lazy/full.ts +3 -56
- package/src/dom/features/lazy/stub.ts +1 -1
- package/src/dom/features/memo/full.ts +3 -3
- package/src/dom/features/memo/stub.ts +1 -1
- package/src/dom/features/portal/full.ts +2 -2
- package/src/dom/features/suspense/full.ts +176 -129
- package/src/dom/reconcile.ts +164 -170
- package/src/dom/root-internal.ts +40 -0
- package/src/dom/root.ts +5 -165
- package/src/dom/test-utils.ts +1 -1
- package/src/react/children.ts +4 -1
- package/src/react/class.ts +8 -2
- package/src/react/context.ts +4 -1
- package/src/react/index.ts +1 -1
- package/src/react/shared-internals.ts +8 -14
- package/src/server/stream.ts +9 -4
- package/src/vite/index.ts +34 -3
package/dist/core/internal.d.ts
CHANGED
|
@@ -14,62 +14,46 @@ export declare const enum FiberTag {
|
|
|
14
14
|
Suspense = 11,
|
|
15
15
|
Root = 12
|
|
16
16
|
}
|
|
17
|
-
export declare const enum FiberFlag {
|
|
18
|
-
None = 0,
|
|
19
|
-
Placement = 1,
|
|
20
|
-
Update = 2,
|
|
21
|
-
Deletion = 4,
|
|
22
|
-
Ref = 8,
|
|
23
|
-
Effect = 16,
|
|
24
|
-
LayoutEffect = 32,
|
|
25
|
-
ContentReset = 64,
|
|
26
|
-
DidCapture = 128
|
|
27
|
-
}
|
|
28
17
|
export interface Hook {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
18
|
+
s: any;
|
|
19
|
+
q: any;
|
|
20
|
+
d: any;
|
|
21
|
+
c: any;
|
|
22
|
+
n: Hook | null;
|
|
34
23
|
}
|
|
35
24
|
export interface Effect {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
destroy: (() => void) | void;
|
|
39
|
-
deps: ReadonlyArray<unknown> | undefined;
|
|
25
|
+
t: 0 | 1;
|
|
26
|
+
c: () => any;
|
|
40
27
|
}
|
|
41
28
|
export interface Fiber {
|
|
42
29
|
tag: FiberTag;
|
|
43
30
|
type: any;
|
|
44
31
|
key: string | null;
|
|
45
32
|
ref: Ref<any> | null;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
33
|
+
pp: any;
|
|
34
|
+
mp: any;
|
|
35
|
+
ms: any;
|
|
36
|
+
sn: any;
|
|
50
37
|
dom: Node | null;
|
|
51
38
|
parent: Fiber | null;
|
|
52
39
|
child: Fiber | null;
|
|
53
40
|
sibling: Fiber | null;
|
|
54
41
|
hooks: Hook | null;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
flags: FiberFlag;
|
|
59
|
-
dirty: boolean;
|
|
60
|
-
unmounted: boolean;
|
|
42
|
+
cu: Array<() => void> | null;
|
|
43
|
+
dy: boolean;
|
|
44
|
+
um: boolean;
|
|
61
45
|
root: FiberRoot | null;
|
|
62
46
|
}
|
|
63
47
|
export interface FiberRoot {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
48
|
+
c: Element | DocumentFragment;
|
|
49
|
+
r: Fiber;
|
|
50
|
+
p: Set<Fiber>;
|
|
51
|
+
s: boolean;
|
|
52
|
+
re?: ((err: unknown) => void) | undefined;
|
|
53
|
+
ce?: ((err: unknown) => void) | undefined;
|
|
54
|
+
ue?: ((err: unknown) => void) | undefined;
|
|
55
|
+
i: string;
|
|
56
|
+
h: boolean;
|
|
73
57
|
}
|
|
74
58
|
export declare function createFiber(tag: FiberTag, type: any, key: string | null): Fiber;
|
|
75
59
|
export type ChildNode = ReactElement | string | number | boolean | null | undefined | ChildNode[];
|
package/dist/core/internal.js
CHANGED
|
@@ -15,44 +15,28 @@ var FiberTag = /* @__PURE__ */ ((FiberTag2) => {
|
|
|
15
15
|
FiberTag2[FiberTag2["Root"] = 12] = "Root";
|
|
16
16
|
return FiberTag2;
|
|
17
17
|
})(FiberTag || {});
|
|
18
|
-
var FiberFlag = /* @__PURE__ */ ((FiberFlag2) => {
|
|
19
|
-
FiberFlag2[FiberFlag2["None"] = 0] = "None";
|
|
20
|
-
FiberFlag2[FiberFlag2["Placement"] = 1] = "Placement";
|
|
21
|
-
FiberFlag2[FiberFlag2["Update"] = 2] = "Update";
|
|
22
|
-
FiberFlag2[FiberFlag2["Deletion"] = 4] = "Deletion";
|
|
23
|
-
FiberFlag2[FiberFlag2["Ref"] = 8] = "Ref";
|
|
24
|
-
FiberFlag2[FiberFlag2["Effect"] = 16] = "Effect";
|
|
25
|
-
FiberFlag2[FiberFlag2["LayoutEffect"] = 32] = "LayoutEffect";
|
|
26
|
-
FiberFlag2[FiberFlag2["ContentReset"] = 64] = "ContentReset";
|
|
27
|
-
FiberFlag2[FiberFlag2["DidCapture"] = 128] = "DidCapture";
|
|
28
|
-
return FiberFlag2;
|
|
29
|
-
})(FiberFlag || {});
|
|
30
18
|
function createFiber(tag, type, key) {
|
|
31
19
|
return {
|
|
32
20
|
tag,
|
|
33
21
|
type,
|
|
34
22
|
key,
|
|
35
23
|
ref: null,
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
24
|
+
pp: null,
|
|
25
|
+
mp: null,
|
|
26
|
+
ms: null,
|
|
27
|
+
sn: null,
|
|
40
28
|
dom: null,
|
|
41
29
|
parent: null,
|
|
42
30
|
child: null,
|
|
43
31
|
sibling: null,
|
|
44
32
|
hooks: null,
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
flags: 0 /* None */,
|
|
49
|
-
dirty: false,
|
|
50
|
-
unmounted: false,
|
|
33
|
+
cu: null,
|
|
34
|
+
dy: false,
|
|
35
|
+
um: false,
|
|
51
36
|
root: null
|
|
52
37
|
};
|
|
53
38
|
}
|
|
54
39
|
export {
|
|
55
|
-
FiberFlag,
|
|
56
40
|
FiberTag,
|
|
57
41
|
createFiber
|
|
58
42
|
};
|
|
@@ -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
|
|
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;
|
|
6
|
-
"names": ["FiberTag"
|
|
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;AA6DX,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
|
+
"names": ["FiberTag"]
|
|
7
7
|
}
|
package/dist/dom/dispatcher.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
type BasicStateAction<S> = S | ((p: S) => S);
|
|
1
2
|
export declare function makeDispatcher(): {
|
|
2
|
-
useState<S>(initial: S | (() => S)):
|
|
3
|
+
useState<S>(initial: S | (() => S)): [S, (a: BasicStateAction<S>) => void];
|
|
3
4
|
useReducer<S, A>(reducer: (s: S, a: A) => S, initialArg: any, init?: (a: any) => S): [S, (a: A) => void];
|
|
4
5
|
useEffect(create: () => any, deps?: ReadonlyArray<unknown>): void;
|
|
5
6
|
useLayoutEffect(create: () => any, deps?: ReadonlyArray<unknown>): void;
|
|
@@ -18,3 +19,4 @@ export declare function makeDispatcher(): {
|
|
|
18
19
|
useSyncExternalStore<T>(subscribe: (cb: () => void) => () => void, getSnapshot: () => T, getServerSnapshot?: () => T): T;
|
|
19
20
|
use<T>(resource: any): T;
|
|
20
21
|
};
|
|
22
|
+
export {};
|
package/dist/dom/dispatcher.js
CHANGED
|
@@ -2,32 +2,37 @@
|
|
|
2
2
|
import { ReactSharedInternals, REACT_CONTEXT_TYPE } from "../react";
|
|
3
3
|
import { scheduleUpdate, enqueueEffect, readContext } from "./reconcile";
|
|
4
4
|
function getCurrentFiber() {
|
|
5
|
-
const f = ReactSharedInternals.
|
|
6
|
-
if (!f)
|
|
5
|
+
const f = ReactSharedInternals.F;
|
|
6
|
+
if (!f) {
|
|
7
|
+
if (true) {
|
|
8
|
+
throw new Error("Hook called outside a function component render.");
|
|
9
|
+
}
|
|
10
|
+
throw new Error();
|
|
11
|
+
}
|
|
7
12
|
return f;
|
|
8
13
|
}
|
|
9
14
|
function nextHook() {
|
|
10
15
|
const fiber = getCurrentFiber();
|
|
11
|
-
const idx = ReactSharedInternals.
|
|
12
|
-
let prev = ReactSharedInternals.
|
|
16
|
+
const idx = ReactSharedInternals.I++;
|
|
17
|
+
let prev = ReactSharedInternals.K;
|
|
13
18
|
if (idx === 0) {
|
|
14
19
|
if (fiber.hooks) {
|
|
15
|
-
ReactSharedInternals.
|
|
20
|
+
ReactSharedInternals.K = fiber.hooks;
|
|
16
21
|
return fiber.hooks;
|
|
17
22
|
}
|
|
18
|
-
const h2 = {
|
|
23
|
+
const h2 = { s: void 0, q: void 0, d: void 0, c: void 0, n: null };
|
|
19
24
|
fiber.hooks = h2;
|
|
20
|
-
ReactSharedInternals.
|
|
25
|
+
ReactSharedInternals.K = h2;
|
|
21
26
|
return h2;
|
|
22
27
|
}
|
|
23
|
-
if (prev && prev.
|
|
24
|
-
ReactSharedInternals.
|
|
25
|
-
return prev.
|
|
28
|
+
if (prev && prev.n) {
|
|
29
|
+
ReactSharedInternals.K = prev.n;
|
|
30
|
+
return prev.n;
|
|
26
31
|
}
|
|
27
|
-
const h = {
|
|
28
|
-
if (prev) prev.
|
|
32
|
+
const h = { s: void 0, q: void 0, d: void 0, c: void 0, n: null };
|
|
33
|
+
if (prev) prev.n = h;
|
|
29
34
|
else fiber.hooks = h;
|
|
30
|
-
ReactSharedInternals.
|
|
35
|
+
ReactSharedInternals.K = h;
|
|
31
36
|
return h;
|
|
32
37
|
}
|
|
33
38
|
function depsEqual(a, b) {
|
|
@@ -48,85 +53,81 @@ function makeDispatcherImpl() {
|
|
|
48
53
|
useState(initial) {
|
|
49
54
|
return this.useReducer(
|
|
50
55
|
basicReducer,
|
|
51
|
-
typeof initial
|
|
56
|
+
typeof initial == "function" ? initial() : initial
|
|
52
57
|
);
|
|
53
58
|
},
|
|
54
59
|
useReducer(reducer, initialArg, init) {
|
|
55
60
|
const hook = nextHook();
|
|
56
61
|
const fiber = getCurrentFiber();
|
|
57
|
-
if (hook.
|
|
58
|
-
hook.
|
|
59
|
-
const queue = { reducer };
|
|
62
|
+
if (hook.q === void 0) {
|
|
63
|
+
hook.s = init ? init(initialArg) : initialArg;
|
|
64
|
+
const queue = { r: reducer };
|
|
60
65
|
const dispatch = (action) => {
|
|
61
|
-
const currentState = hook.
|
|
62
|
-
const next = queue.
|
|
66
|
+
const currentState = hook.s;
|
|
67
|
+
const next = queue.r(currentState, action);
|
|
63
68
|
if (!Object.is(next, currentState)) {
|
|
64
|
-
hook.
|
|
69
|
+
hook.s = next;
|
|
65
70
|
scheduleUpdate(fiber);
|
|
66
71
|
}
|
|
67
72
|
};
|
|
68
|
-
queue.
|
|
69
|
-
hook.
|
|
73
|
+
queue.d = dispatch;
|
|
74
|
+
hook.q = queue;
|
|
70
75
|
} else {
|
|
71
|
-
hook.
|
|
76
|
+
hook.q.r = reducer;
|
|
72
77
|
}
|
|
73
|
-
return [hook.
|
|
78
|
+
return [hook.s, hook.q.d];
|
|
74
79
|
},
|
|
75
80
|
useEffect(create, deps) {
|
|
76
81
|
const hook = nextHook();
|
|
77
82
|
const fiber = getCurrentFiber();
|
|
78
|
-
const prevDeps = hook.
|
|
83
|
+
const prevDeps = hook.d;
|
|
79
84
|
if (prevDeps !== void 0 && depsEqual(prevDeps, deps)) return;
|
|
80
|
-
hook.
|
|
85
|
+
hook.d = deps;
|
|
81
86
|
const effect = {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (hook.
|
|
87
|
+
t: 0,
|
|
88
|
+
c: () => {
|
|
89
|
+
if (hook.c) {
|
|
85
90
|
try {
|
|
86
|
-
hook.
|
|
91
|
+
hook.c();
|
|
87
92
|
} catch {
|
|
88
93
|
}
|
|
89
|
-
if (fiber.
|
|
90
|
-
const i = fiber.
|
|
91
|
-
if (i >= 0) fiber.
|
|
94
|
+
if (fiber.cu) {
|
|
95
|
+
const i = fiber.cu.indexOf(hook.c);
|
|
96
|
+
if (i >= 0) fiber.cu.splice(i, 1);
|
|
92
97
|
}
|
|
93
|
-
hook.
|
|
98
|
+
hook.c = null;
|
|
94
99
|
}
|
|
95
100
|
const c = create();
|
|
96
|
-
hook.
|
|
97
|
-
return hook.
|
|
98
|
-
}
|
|
99
|
-
destroy: void 0,
|
|
100
|
-
deps
|
|
101
|
+
hook.c = typeof c == "function" ? c : null;
|
|
102
|
+
return hook.c;
|
|
103
|
+
}
|
|
101
104
|
};
|
|
102
105
|
enqueueEffect(fiber, effect);
|
|
103
106
|
},
|
|
104
107
|
useLayoutEffect(create, deps) {
|
|
105
108
|
const hook = nextHook();
|
|
106
109
|
const fiber = getCurrentFiber();
|
|
107
|
-
const prevDeps = hook.
|
|
110
|
+
const prevDeps = hook.d;
|
|
108
111
|
if (prevDeps !== void 0 && depsEqual(prevDeps, deps)) return;
|
|
109
|
-
hook.
|
|
112
|
+
hook.d = deps;
|
|
110
113
|
const effect = {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
if (hook.
|
|
114
|
+
t: 1,
|
|
115
|
+
c: () => {
|
|
116
|
+
if (hook.c) {
|
|
114
117
|
try {
|
|
115
|
-
hook.
|
|
118
|
+
hook.c();
|
|
116
119
|
} catch {
|
|
117
120
|
}
|
|
118
|
-
if (fiber.
|
|
119
|
-
const i = fiber.
|
|
120
|
-
if (i >= 0) fiber.
|
|
121
|
+
if (fiber.cu) {
|
|
122
|
+
const i = fiber.cu.indexOf(hook.c);
|
|
123
|
+
if (i >= 0) fiber.cu.splice(i, 1);
|
|
121
124
|
}
|
|
122
|
-
hook.
|
|
125
|
+
hook.c = null;
|
|
123
126
|
}
|
|
124
127
|
const c = create();
|
|
125
|
-
hook.
|
|
126
|
-
return hook.
|
|
127
|
-
}
|
|
128
|
-
destroy: void 0,
|
|
129
|
-
deps
|
|
128
|
+
hook.c = typeof c == "function" ? c : null;
|
|
129
|
+
return hook.c;
|
|
130
|
+
}
|
|
130
131
|
};
|
|
131
132
|
enqueueEffect(fiber, effect);
|
|
132
133
|
},
|
|
@@ -135,17 +136,17 @@ function makeDispatcherImpl() {
|
|
|
135
136
|
},
|
|
136
137
|
useRef(initial) {
|
|
137
138
|
const hook = nextHook();
|
|
138
|
-
if (hook.
|
|
139
|
-
return hook.
|
|
139
|
+
if (hook.s === void 0) hook.s = { current: initial };
|
|
140
|
+
return hook.s;
|
|
140
141
|
},
|
|
141
142
|
useMemo(factory, deps) {
|
|
142
143
|
const hook = nextHook();
|
|
143
|
-
if (hook.
|
|
144
|
-
return hook.
|
|
144
|
+
if (hook.d !== void 0 && depsEqual(hook.d, deps)) {
|
|
145
|
+
return hook.s;
|
|
145
146
|
}
|
|
146
147
|
const value = factory();
|
|
147
|
-
hook.
|
|
148
|
-
hook.
|
|
148
|
+
hook.s = value;
|
|
149
|
+
hook.d = deps;
|
|
149
150
|
return value;
|
|
150
151
|
},
|
|
151
152
|
useCallback(fn, deps) {
|
|
@@ -157,11 +158,11 @@ function makeDispatcherImpl() {
|
|
|
157
158
|
},
|
|
158
159
|
useImperativeHandle(ref, factory, deps) {
|
|
159
160
|
const hook = nextHook();
|
|
160
|
-
if (hook.
|
|
161
|
-
hook.
|
|
161
|
+
if (hook.d !== void 0 && depsEqual(hook.d, deps)) return;
|
|
162
|
+
hook.d = deps;
|
|
162
163
|
const value = factory();
|
|
163
164
|
if (ref) {
|
|
164
|
-
if (typeof ref
|
|
165
|
+
if (typeof ref == "function") ref(value);
|
|
165
166
|
else ref.current = value;
|
|
166
167
|
}
|
|
167
168
|
},
|
|
@@ -169,12 +170,12 @@ function makeDispatcherImpl() {
|
|
|
169
170
|
},
|
|
170
171
|
useId() {
|
|
171
172
|
const hook = nextHook();
|
|
172
|
-
if (hook.
|
|
173
|
+
if (hook.s === void 0) {
|
|
173
174
|
const fiber = getCurrentFiber();
|
|
174
175
|
const root = findRootFromFiber(fiber);
|
|
175
|
-
hook.
|
|
176
|
+
hook.s = (root?.i ?? ":r") + (idCounter++).toString(36);
|
|
176
177
|
}
|
|
177
|
-
return hook.
|
|
178
|
+
return hook.s;
|
|
178
179
|
},
|
|
179
180
|
useTransition() {
|
|
180
181
|
return [false, (fn) => fn()];
|
|
@@ -185,65 +186,63 @@ function makeDispatcherImpl() {
|
|
|
185
186
|
useSyncExternalStore(subscribe, getSnapshot, getServerSnapshot) {
|
|
186
187
|
const fiber = getCurrentFiber();
|
|
187
188
|
const hook = nextHook();
|
|
188
|
-
const store = hook.
|
|
189
|
-
getSnapshot,
|
|
190
|
-
getServerSnapshot
|
|
189
|
+
const store = hook.q ?? {
|
|
190
|
+
g: getSnapshot,
|
|
191
|
+
s: getServerSnapshot
|
|
191
192
|
};
|
|
192
|
-
hook.
|
|
193
|
-
store.
|
|
194
|
-
store.
|
|
193
|
+
hook.q = store;
|
|
194
|
+
store.g = getSnapshot;
|
|
195
|
+
store.s = getServerSnapshot;
|
|
195
196
|
const root = fiber.root ?? findRootFromFiber(fiber);
|
|
196
|
-
const isHydrating = Boolean(root?.
|
|
197
|
+
const isHydrating = Boolean(root?.h);
|
|
197
198
|
const value = isHydrating && getServerSnapshot ? getServerSnapshot() : getSnapshot();
|
|
198
|
-
hook.
|
|
199
|
+
hook.s = value;
|
|
199
200
|
const deps = [subscribe];
|
|
200
|
-
if (hook.
|
|
201
|
-
hook.
|
|
201
|
+
if (hook.d === void 0 || !depsEqual(hook.d, deps)) {
|
|
202
|
+
hook.d = deps;
|
|
202
203
|
const effect = {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
create: () => {
|
|
207
|
-
if (hook.cleanup) {
|
|
204
|
+
t: 1,
|
|
205
|
+
c: () => {
|
|
206
|
+
if (hook.c) {
|
|
208
207
|
try {
|
|
209
|
-
hook.
|
|
208
|
+
hook.c();
|
|
210
209
|
} catch {
|
|
211
210
|
}
|
|
212
|
-
if (fiber.
|
|
213
|
-
const i = fiber.
|
|
214
|
-
if (i >= 0) fiber.
|
|
211
|
+
if (fiber.cu) {
|
|
212
|
+
const i = fiber.cu.indexOf(hook.c);
|
|
213
|
+
if (i >= 0) fiber.cu.splice(i, 1);
|
|
215
214
|
}
|
|
216
|
-
hook.
|
|
215
|
+
hook.c = null;
|
|
217
216
|
}
|
|
218
217
|
let unsubscribed = false;
|
|
219
218
|
const cleanup = () => {
|
|
220
219
|
unsubscribed = true;
|
|
221
|
-
if (typeof unsubscribe
|
|
220
|
+
if (typeof unsubscribe == "function") {
|
|
222
221
|
unsubscribe();
|
|
223
222
|
}
|
|
224
223
|
};
|
|
225
224
|
const forceUpdate = () => {
|
|
226
|
-
if (unsubscribed || fiber.
|
|
225
|
+
if (unsubscribed || fiber.um) {
|
|
227
226
|
return;
|
|
228
227
|
}
|
|
229
228
|
let next;
|
|
230
229
|
try {
|
|
231
|
-
next = store.
|
|
230
|
+
next = store.g();
|
|
232
231
|
} catch {
|
|
233
232
|
scheduleUpdate(fiber);
|
|
234
233
|
return;
|
|
235
234
|
}
|
|
236
|
-
if (!Object.is(hook.
|
|
237
|
-
hook.
|
|
235
|
+
if (!Object.is(hook.s, next)) {
|
|
236
|
+
hook.s = next;
|
|
238
237
|
scheduleUpdate(fiber);
|
|
239
238
|
}
|
|
240
239
|
};
|
|
241
240
|
const unsubscribe = subscribe(forceUpdate);
|
|
242
|
-
if (isHydrating && store.
|
|
241
|
+
if (isHydrating && store.s) {
|
|
243
242
|
queueMicrotask(() => queueMicrotask(forceUpdate));
|
|
244
243
|
}
|
|
245
244
|
forceUpdate();
|
|
246
|
-
hook.
|
|
245
|
+
hook.c = cleanup;
|
|
247
246
|
return cleanup;
|
|
248
247
|
}
|
|
249
248
|
};
|
|
@@ -252,11 +251,16 @@ function makeDispatcherImpl() {
|
|
|
252
251
|
return value;
|
|
253
252
|
},
|
|
254
253
|
use(resource) {
|
|
255
|
-
if (resource == null)
|
|
254
|
+
if (resource == null) {
|
|
255
|
+
if (true) {
|
|
256
|
+
throw new Error("use() received null or undefined");
|
|
257
|
+
}
|
|
258
|
+
throw new Error();
|
|
259
|
+
}
|
|
256
260
|
if (resource.$$typeof === REACT_CONTEXT_TYPE) {
|
|
257
261
|
return readContext(getCurrentFiber(), resource);
|
|
258
262
|
}
|
|
259
|
-
if (typeof resource.then
|
|
263
|
+
if (typeof resource.then == "function") {
|
|
260
264
|
const thenable = resource;
|
|
261
265
|
switch (thenable.status) {
|
|
262
266
|
case "fulfilled":
|
|
@@ -285,12 +289,15 @@ function makeDispatcherImpl() {
|
|
|
285
289
|
}
|
|
286
290
|
}
|
|
287
291
|
}
|
|
288
|
-
|
|
292
|
+
if (true) {
|
|
293
|
+
throw new Error("use() expected a Promise or Context");
|
|
294
|
+
}
|
|
295
|
+
throw new Error();
|
|
289
296
|
}
|
|
290
297
|
};
|
|
291
298
|
}
|
|
292
299
|
function basicReducer(state, action) {
|
|
293
|
-
return typeof action
|
|
300
|
+
return typeof action == "function" ? action(state) : action;
|
|
294
301
|
}
|
|
295
302
|
var idCounter = 0;
|
|
296
303
|
function findRootFromFiber(fiber) {
|
|
@@ -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.currentFiber\n if (!f) throw new Error('Hook called outside a function component render.')\n return f\n}\n\nfunction nextHook(): Hook {\n const fiber = getCurrentFiber()\n const idx = ReactSharedInternals.hookIndex++\n\n let prev = ReactSharedInternals.currentHook\n\n if (idx === 0) {\n if (fiber.hooks) {\n ReactSharedInternals.currentHook = fiber.hooks\n return fiber.hooks\n }\n const h: Hook = { state: undefined, queue: undefined, deps: undefined, cleanup: undefined, next: null }\n fiber.hooks = h\n ReactSharedInternals.currentHook = h\n return h\n }\n\n if (prev && prev.next) {\n ReactSharedInternals.currentHook = prev.next\n return prev.next\n }\n\n const h: Hook = { state: undefined, queue: undefined, deps: undefined, cleanup: undefined, next: null }\n if (prev) prev.next = h\n else fiber.hooks = h\n ReactSharedInternals.currentHook = 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\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)) {\n return this.useReducer<S, S | ((p: S) => S)>(\n basicReducer as any,\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.queue === undefined) {\n hook.state = init ? init(initialArg) : initialArg\n const queue: any = { reducer }\n const dispatch = (action: A) => {\n const currentState = hook.state as S\n const next = queue.reducer(currentState, action)\n if (!Object.is(next, currentState)) {\n hook.state = next\n scheduleUpdate(fiber)\n }\n }\n queue.dispatch = dispatch\n hook.queue = queue\n } else {\n hook.queue.reducer = reducer\n }\n return [hook.state, hook.queue.dispatch] 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.deps\n if (prevDeps !== undefined && depsEqual(prevDeps, deps)) return\n hook.deps = deps\n const effect: Effect = {\n tag: 'effect',\n create: () => {\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 effects B + C both run fresh,\n // leaving two side-effects (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.cleanup) {\n try { hook.cleanup() } catch {}\n // The prior cleanup was also pushed onto fiber.cleanups; remove\n // it so unmount doesn't double-call it.\n if (fiber.cleanups) {\n const i = fiber.cleanups.indexOf(hook.cleanup)\n if (i >= 0) fiber.cleanups.splice(i, 1)\n }\n hook.cleanup = null\n }\n const c = create()\n hook.cleanup = typeof c === 'function' ? c : null\n return hook.cleanup\n },\n destroy: undefined,\n deps,\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.deps\n if (prevDeps !== undefined && depsEqual(prevDeps, deps)) return\n hook.deps = deps\n const effect: Effect = {\n tag: 'layout',\n create: () => {\n // Mirror useEffect: tear down the prior cleanup at run time so\n // coalesced renders don't leak side-effects.\n if (hook.cleanup) {\n try { hook.cleanup() } catch {}\n if (fiber.cleanups) {\n const i = fiber.cleanups.indexOf(hook.cleanup)\n if (i >= 0) fiber.cleanups.splice(i, 1)\n }\n hook.cleanup = null\n }\n const c = create()\n hook.cleanup = typeof c === 'function' ? c : null\n return hook.cleanup\n },\n destroy: undefined,\n deps,\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.state === undefined) hook.state = { current: initial }\n return hook.state as { current: T }\n },\n\n useMemo<T>(factory: () => T, deps?: ReadonlyArray<unknown>) {\n const hook = nextHook()\n if (hook.deps !== undefined && depsEqual(hook.deps, deps)) {\n return hook.state as T\n }\n const value = factory()\n hook.state = value\n hook.deps = 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.deps !== undefined && depsEqual(hook.deps, deps)) return\n hook.deps = 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.state === undefined) {\n const fiber = getCurrentFiber()\n const root = findRootFromFiber(fiber)\n hook.state = (root?.identifierPrefix ?? ':r') + (idCounter++).toString(36)\n }\n return hook.state 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 getSnapshot: () => T\n getServerSnapshot: (() => T) | undefined\n } = hook.queue ?? {\n getSnapshot,\n getServerSnapshot,\n }\n hook.queue = store\n store.getSnapshot = getSnapshot\n store.getServerSnapshot = 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?.hydrating)\n const value =\n isHydrating && getServerSnapshot ? getServerSnapshot() : getSnapshot()\n hook.state = value\n\n const deps = [subscribe]\n if (hook.deps === undefined || !depsEqual(hook.deps, deps)) {\n hook.deps = deps\n const effect: Effect = {\n tag: 'layout',\n deps,\n destroy: undefined,\n create: () => {\n if (hook.cleanup) {\n try {\n hook.cleanup()\n } catch {\n // ignore cleanup failures\n }\n if (fiber.cleanups) {\n const i = fiber.cleanups.indexOf(hook.cleanup)\n if (i >= 0) fiber.cleanups.splice(i, 1)\n }\n hook.cleanup = 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.unmounted) {\n return\n }\n\n let next: T\n try {\n next = store.getSnapshot()\n } catch {\n scheduleUpdate(fiber)\n return\n }\n\n if (!Object.is(hook.state, next)) {\n hook.state = 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.getServerSnapshot) {\n queueMicrotask(() => queueMicrotask(forceUpdate))\n }\n\n forceUpdate()\n hook.cleanup = 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) throw new Error('use() received null or undefined')\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 throw new Error('use() expected a Promise or Context')\n },\n }\n}\n\nfunction basicReducer<S>(state: S, action: S | ((p: S) => 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,
|
|
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,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I,IAAkB;AACtB,SAAO,GAAG;AACR,QAAI,EAAE,KAAM,QAAO,EAAE;AACrB,QAAI,EAAE;AAAA,EACR;AACA,SAAO;AACT;",
|
|
6
6
|
"names": ["h"]
|
|
7
7
|
}
|
package/dist/dom/dom.js
CHANGED
|
@@ -202,7 +202,7 @@ var UNITLESS_STYLE = /* @__PURE__ */ new Set([
|
|
|
202
202
|
"strokeWidth"
|
|
203
203
|
]);
|
|
204
204
|
function setEventHandler(el, name, next, prev) {
|
|
205
|
-
if (next != null && typeof next
|
|
205
|
+
if (next != null && typeof next != "function") next = null;
|
|
206
206
|
const capture = name.endsWith("Capture");
|
|
207
207
|
const reactEventName = name.slice(2, capture ? -7 : void 0);
|
|
208
208
|
const eventName = domEventFor(reactEventName, el);
|