@bleedingdev/tanstack-redact 0.2.2 → 0.3.2
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/bundler-core/resolution.d.ts +31 -0
- package/dist/bundler-core/resolution.js +80 -0
- package/dist/bundler-core/resolution.js.map +7 -0
- package/dist/bundler-core/selection.d.ts +89 -0
- package/dist/bundler-core/selection.js +103 -0
- package/dist/bundler-core/selection.js.map +7 -0
- package/dist/core/devtools.d.ts +1 -1
- package/dist/core/devtools.js +1 -0
- package/dist/core/devtools.js.map +2 -2
- package/dist/core/functions.js +1 -0
- package/dist/core/functions.js.map +2 -2
- package/dist/core/internal.d.ts +5 -4
- package/dist/core/internal.js +4 -3
- package/dist/core/internal.js.map +2 -2
- package/dist/core/types.d.ts +2 -2
- package/dist/core/types.js +1 -0
- package/dist/core/types.js.map +1 -1
- package/dist/dom/devtools.d.ts +5 -5
- package/dist/dom/devtools.js +1 -0
- package/dist/dom/devtools.js.map +2 -2
- package/dist/dom/dispatcher.d.ts +1 -1
- package/dist/dom/dispatcher.js +1 -0
- package/dist/dom/dispatcher.js.map +3 -3
- package/dist/dom/document-metadata.d.ts +1 -1
- package/dist/dom/document-metadata.js +3 -1
- package/dist/dom/document-metadata.js.map +2 -2
- package/dist/dom/dom.js +1 -1
- package/dist/dom/dom.js.map +2 -2
- package/dist/dom/features/class/full.js +25 -32
- package/dist/dom/features/class/full.js.map +2 -2
- package/dist/dom/features/class/stub.js +1 -0
- package/dist/dom/features/class/stub.js.map +2 -2
- package/dist/dom/features/hydration/full.d.ts +6 -6
- package/dist/dom/features/hydration/full.js +20 -29
- package/dist/dom/features/hydration/full.js.map +2 -2
- package/dist/dom/features/hydration/stub.d.ts +7 -2
- package/dist/dom/features/hydration/stub.js +1 -0
- package/dist/dom/features/hydration/stub.js.map +2 -2
- package/dist/dom/features/lazy/full.js +1 -0
- package/dist/dom/features/lazy/full.js.map +2 -2
- package/dist/dom/features/suspense/full.d.ts +4 -1
- package/dist/dom/features/suspense/full.js +22 -161
- package/dist/dom/features/suspense/full.js.map +2 -2
- package/dist/dom/features/suspense-hydration/full.d.ts +8 -0
- package/dist/dom/features/suspense-hydration/full.js +147 -0
- package/dist/dom/features/suspense-hydration/full.js.map +7 -0
- package/dist/dom/features/suspense-hydration/index.d.ts +1 -0
- package/dist/dom/features/suspense-hydration/index.js +2 -0
- package/dist/dom/features/suspense-hydration/index.js.map +7 -0
- package/dist/dom/features/suspense-hydration/stub.d.ts +2 -0
- package/dist/dom/features/suspense-hydration/stub.js +9 -0
- package/dist/dom/features/suspense-hydration/stub.js.map +7 -0
- package/dist/dom/features/suspense-runtime/stub.js +1 -0
- package/dist/dom/features/suspense-runtime/stub.js.map +2 -2
- package/dist/dom/profiling.d.ts +36 -0
- package/dist/dom/profiling.js +9 -0
- package/dist/dom/profiling.js.map +7 -0
- package/dist/dom/react-ids.js +1 -0
- package/dist/dom/react-ids.js.map +2 -2
- package/dist/dom/reconcile.d.ts +4 -5
- package/dist/dom/reconcile.js +102 -144
- package/dist/dom/reconcile.js.map +2 -2
- package/dist/dom/resources.js +1 -0
- package/dist/dom/resources.js.map +2 -2
- package/dist/dom/root-internal.d.ts +1 -1
- package/dist/dom/root-internal.js +4 -3
- package/dist/dom/root-internal.js.map +2 -2
- package/dist/dom/root.d.ts +2 -2
- package/dist/dom/root.js +1 -0
- package/dist/dom/root.js.map +2 -2
- package/dist/dom/synthetic-event.js.map +2 -2
- package/dist/dom/transitions.d.ts +1 -1
- package/dist/dom/transitions.js +1 -0
- package/dist/dom/transitions.js.map +2 -2
- package/dist/react/action-scope.d.ts +1 -1
- package/dist/react/action-scope.js +1 -0
- package/dist/react/action-scope.js.map +2 -2
- package/dist/rspack/index.d.ts +2 -0
- package/dist/rspack/index.js +6 -0
- package/dist/rspack/index.js.map +7 -0
- package/dist/server/bootstrap-script.js +1 -0
- package/dist/server/bootstrap-script.js.map +2 -2
- package/dist/server/dispatcher.js +11 -20
- package/dist/server/dispatcher.js.map +2 -2
- package/dist/server/insertion-context.js +9 -16
- package/dist/server/insertion-context.js.map +7 -0
- package/dist/server/stream-ids.js +1 -0
- package/dist/server/stream-ids.js.map +7 -0
- package/dist/server/stream.d.ts +1 -2
- package/dist/server/stream.js +106 -122
- package/dist/server/stream.js.map +2 -2
- package/dist/server/walk.js +69 -72
- package/dist/server/walk.js.map +3 -3
- package/dist/vite/index.d.ts +5 -99
- package/dist/vite/index.js +56 -179
- package/dist/vite/index.js.map +2 -2
- package/dist/webpack/index.d.ts +46 -0
- package/dist/webpack/index.js +102 -0
- package/dist/webpack/index.js.map +7 -0
- package/dist/webpack/react18-loader.cjs +25 -0
- package/package.json +17 -3
- package/src/bundler-core/resolution.ts +131 -0
- package/src/bundler-core/selection.ts +192 -0
- package/src/core/internal.ts +2 -1
- package/src/core/types.ts +3 -2
- package/src/dom/dom.ts +1 -1
- package/src/dom/features/class/full.ts +26 -34
- package/src/dom/features/suspense/full.ts +7 -165
- package/src/dom/features/suspense-hydration/full.ts +166 -0
- package/src/dom/features/suspense-hydration/index.ts +1 -0
- package/src/dom/features/suspense-hydration/stub.ts +2 -0
- package/src/dom/profiling.ts +6 -0
- package/src/dom/reconcile.ts +16 -6
- package/src/rspack/index.ts +2 -0
- package/src/server/stream.ts +15 -14
- package/src/vite/index.ts +55 -317
- package/src/webpack/index.ts +108 -0
- package/src/webpack/react18-loader.cjs +25 -0
|
@@ -1,49 +1,15 @@
|
|
|
1
|
-
import { readOwnerStack, runWithOwnerStack } from '../../../core/devtools';
|
|
2
1
|
import { a as transitionRender } from '../suspense-runtime';
|
|
3
2
|
import { cleanupEffect } from '../../dispatcher';
|
|
4
|
-
import { checkpointCommit, rewindCommit, queueMutation, onCommitFailure, onCommitRollback
|
|
3
|
+
import { checkpointCommit, rewindCommit, queueMutation, onCommitFailure, onCommitRollback } from '../../commit';
|
|
5
4
|
import { REACT_SUSPENSE_TYPE, ReactSharedInternals, startTransition } from '../../../react';
|
|
6
5
|
import { FiberTag, createFiber, type Fiber } from '../../../core';
|
|
7
6
|
import { disconnectClass, inSuspensePrimary, setRetainedFlag, walkRetained } from '../../retained-effects';
|
|
8
7
|
import { hasContextChanged, renderContextConsumers } from '../context';
|
|
9
8
|
import { installRenderer, registerTypeMatcher, installCapability, reconcileRaw, childrenToArray, renderNode, scheduleUpdate, unmountAllChildren, removeFiber, findRoot, runEffects, getCurrentRoot, withCurrentRoot, discardPendingWork, findSuspenseBoundary, RenderSuspenseCapture, activityIsDisconnected, isActivityHidden, attachRef, detachRef, enqueueEffect, flushFiberCommits, scheduleLifecycle, handleCommitError, disposeCleanup, isThenable, defaultHandleSuspended, } from '../../reconcile';
|
|
10
|
-
import {
|
|
9
|
+
import { tryConsumeBoundary, isHydrationBailout, } from '../hydration';
|
|
10
|
+
import { hydrateSuspenseBoundary, recoverBoundaryHydration } from '../suspense-hydration';
|
|
11
11
|
import { devToolsSuspension } from '../../devtools';
|
|
12
12
|
let suspendHandler: ((t: Promise<any>) => void) | null = null;
|
|
13
|
-
function clearBoundaryRange(startMark: Comment, endMark: Comment): void {
|
|
14
|
-
queueMutation(() => {
|
|
15
|
-
let node = startMark.nextSibling;
|
|
16
|
-
while (node && node !== endMark) {
|
|
17
|
-
const next = node.nextSibling;
|
|
18
|
-
(node as ChildNode).remove();
|
|
19
|
-
node = next;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
function rehydrateBoundary(fiber: Fiber): void {
|
|
24
|
-
const state = fiber.b;
|
|
25
|
-
if (!state?.b || !state.e)
|
|
26
|
-
return;
|
|
27
|
-
const root = findRoot(fiber);
|
|
28
|
-
const parent = state.b.parentNode as Node;
|
|
29
|
-
if (!(root && parent))
|
|
30
|
-
return;
|
|
31
|
-
// Both initial hydration and a streamed reveal adopt the same marked range.
|
|
32
|
-
commitSynchronously(() => withCurrentRoot(root, () => {
|
|
33
|
-
const previous = root.h;
|
|
34
|
-
try {
|
|
35
|
-
const kind = state.b.data.startsWith('$E') ? 3 : state.b.data.startsWith('$!') ? 2 : 0;
|
|
36
|
-
if (!kind)
|
|
37
|
-
unmountAllChildren(fiber);
|
|
38
|
-
root.h = true;
|
|
39
|
-
hydrateSuspenseBoundary(fiber, { ...fiber.v, children: state.r }, [kind, 0, state.b, state.e], true);
|
|
40
|
-
}
|
|
41
|
-
finally {
|
|
42
|
-
root.h = previous;
|
|
43
|
-
}
|
|
44
|
-
runEffects(root);
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
13
|
// React's Suspense semantics: when a re-render of an already-committed
|
|
48
14
|
// boundary suspends, the previously-committed children are kept in the DOM
|
|
49
15
|
// (hidden) so their scroll position, focus, selection, native form state,
|
|
@@ -71,54 +37,7 @@ interface SuspenseState {
|
|
|
71
37
|
]> | null;
|
|
72
38
|
f?: Fiber | null;
|
|
73
39
|
}
|
|
74
|
-
function
|
|
75
|
-
const error = new Error(process.env.NODE_ENV !== 'production' ? 'Switched to client rendering because the server render did not complete.' : '');
|
|
76
|
-
const handler = findRoot(fiber)?.re;
|
|
77
|
-
if (handler) {
|
|
78
|
-
if (process.env.NODE_ENV !== 'production') runWithOwnerStack(readOwnerStack(fiber), () => handler(error, { componentStack: null }));
|
|
79
|
-
else handler(error, { componentStack: null });
|
|
80
|
-
}
|
|
81
|
-
else
|
|
82
|
-
console.error(error);
|
|
83
|
-
}
|
|
84
|
-
function recoverBoundaryHydration(fiber: Fiber, children: any, parent: Node, startMark: Comment | null, endMark: Comment | null, retryBoundary?: boolean): void {
|
|
85
|
-
const clear = () => {
|
|
86
|
-
const dispose = fiber.b?.x;
|
|
87
|
-
if (dispose) queueMutation(dispose);
|
|
88
|
-
if (startMark && endMark)
|
|
89
|
-
clearBoundaryRange(startMark, endMark);
|
|
90
|
-
else
|
|
91
|
-
queueMutation(() => { parent.textContent = ''; });
|
|
92
|
-
};
|
|
93
|
-
const root = findRoot(fiber)!;
|
|
94
|
-
const prevHydrating = root.h;
|
|
95
|
-
if (!retryBoundary)
|
|
96
|
-
discardPendingWork(root);
|
|
97
|
-
clear();
|
|
98
|
-
unmountAllChildren(fiber);
|
|
99
|
-
root.h = false;
|
|
100
|
-
try {
|
|
101
|
-
if (retryBoundary) {
|
|
102
|
-
fiber.b = { b: startMark, e: endMark };
|
|
103
|
-
renderSuspense(fiber);
|
|
104
|
-
}
|
|
105
|
-
else
|
|
106
|
-
reconcileRaw(fiber, children);
|
|
107
|
-
if (endMark)
|
|
108
|
-
advanceCursorPast(fiber.p!, endMark);
|
|
109
|
-
}
|
|
110
|
-
catch (clientError) {
|
|
111
|
-
onCommitFailure(() => {
|
|
112
|
-
clear();
|
|
113
|
-
unmountAllChildren(fiber);
|
|
114
|
-
});
|
|
115
|
-
throw clientError;
|
|
116
|
-
}
|
|
117
|
-
finally {
|
|
118
|
-
root.h = prevHydrating;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
function scheduleRetry(fiber: Fiber): void {
|
|
40
|
+
export function scheduleRetry(fiber: Fiber): void {
|
|
122
41
|
const previous = ReactSharedInternals.T;
|
|
123
42
|
ReactSharedInternals.T = null;
|
|
124
43
|
try {
|
|
@@ -128,88 +47,11 @@ function scheduleRetry(fiber: Fiber): void {
|
|
|
128
47
|
ReactSharedInternals.T = previous;
|
|
129
48
|
}
|
|
130
49
|
}
|
|
131
|
-
function retryHydration(fiber: Fiber, thenable: Promise<any>): void {
|
|
50
|
+
export function retryHydration(fiber: Fiber, thenable: Promise<any>): void {
|
|
132
51
|
const retry = () => { if (!fiber.u) scheduleRetry(fiber); };
|
|
133
52
|
thenable.then(retry, retry);
|
|
134
53
|
}
|
|
135
|
-
|
|
136
|
-
0 | 1 | 2 | 3,
|
|
137
|
-
number,
|
|
138
|
-
Comment,
|
|
139
|
-
Comment
|
|
140
|
-
], reveal?: boolean): void {
|
|
141
|
-
const [pendingBoundary, id, startMark, endMark] = boundary;
|
|
142
|
-
// Record the boundary shape so we can re-hydrate on reveal.
|
|
143
|
-
fiber.b = {
|
|
144
|
-
b: startMark,
|
|
145
|
-
e: endMark,
|
|
146
|
-
r: props.children,
|
|
147
|
-
};
|
|
148
|
-
if (pendingBoundary >= 2) {
|
|
149
|
-
if (pendingBoundary === 3)
|
|
150
|
-
reportServerFailure(fiber);
|
|
151
|
-
recoverBoundaryHydration(fiber, props.children, startMark.parentNode!, startMark, endMark, true);
|
|
152
|
-
fiber.m = props;
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
if (!pendingBoundary) {
|
|
156
|
-
// Real DOM is inline between startMark and endMark. Hydrate into it.
|
|
157
|
-
const checkpoint = checkpointCommit(fiber);
|
|
158
|
-
const parent = startMark.parentNode!;
|
|
159
|
-
try {
|
|
160
|
-
setHydrationCursor(fiber, new HydrationCursor(parent, startMark.nextSibling, endMark));
|
|
161
|
-
reconcileRaw(fiber, props.children);
|
|
162
|
-
advanceCursorPast(fiber.p!, endMark);
|
|
163
|
-
}
|
|
164
|
-
catch (e) {
|
|
165
|
-
// A marked boundary owns a known server range. Roll back only its
|
|
166
|
-
// unfinished preparation so siblings can hydrate while it waits.
|
|
167
|
-
if (isThenable(e)) {
|
|
168
|
-
rewindCommit(checkpoint);
|
|
169
|
-
fiber.b.w = true;
|
|
170
|
-
retryHydration(fiber, e);
|
|
171
|
-
advanceCursorPast(fiber.p!, endMark);
|
|
172
|
-
}
|
|
173
|
-
else if (!isHydrationBailout(e)) {
|
|
174
|
-
onCommitFailure(() => {
|
|
175
|
-
clearBoundaryRange(startMark, endMark);
|
|
176
|
-
unmountAllChildren(fiber);
|
|
177
|
-
});
|
|
178
|
-
throw e;
|
|
179
|
-
}
|
|
180
|
-
else recoverBoundaryHydration(fiber, props.children, parent, startMark, endMark);
|
|
181
|
-
}
|
|
182
|
-
finally {
|
|
183
|
-
clearHydrationCursor(fiber);
|
|
184
|
-
}
|
|
185
|
-
fiber.m = props;
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
if (startMark.data === '$?' || startMark.data === '$~') {
|
|
189
|
-
// React owns this pending server range until its reveal script runs.
|
|
190
|
-
// Hydrating the fallback would consume the transport template as a host.
|
|
191
|
-
fiber.b.w = true;
|
|
192
|
-
(startMark as any)._reactRetry = () => {
|
|
193
|
-
if (!fiber.u)
|
|
194
|
-
scheduleRetry(fiber);
|
|
195
|
-
};
|
|
196
|
-
advanceCursorPast(fiber.p!, endMark);
|
|
197
|
-
fiber.m = props;
|
|
198
|
-
return;
|
|
199
|
-
}
|
|
200
|
-
// Pending transport owns this range until reveal. Keep the opaque server
|
|
201
|
-
// range owned by this fiber so deletion also retires its template/fallback.
|
|
202
|
-
fiber.b.w = true;
|
|
203
|
-
advanceCursorPast(fiber.p!, endMark);
|
|
204
|
-
const boundaryId = (findRoot(fiber)?.i ?? '') + 'B:' + id.toString(16);
|
|
205
|
-
const dispose = (globalThis as any).$RH?.(boundaryId, () => {
|
|
206
|
-
if (!fiber.u && !fiber.pd) rehydrateBoundary(fiber);
|
|
207
|
-
});
|
|
208
|
-
fiber.b.x = dispose;
|
|
209
|
-
if (dispose) onCommitRollback(dispose);
|
|
210
|
-
// If the inline runtime isn't present, nothing external will mark us dy.
|
|
211
|
-
fiber.m = props;
|
|
212
|
-
}
|
|
54
|
+
|
|
213
55
|
function reconnectLayout(fiber: Fiber): void {
|
|
214
56
|
if (!fiber.ld || isActivityHidden(fiber) || activityIsDisconnected(fiber))
|
|
215
57
|
return;
|
|
@@ -287,7 +129,7 @@ function setUpdateBoundary(fiber: Fiber, boundary: Fiber | null | undefined): vo
|
|
|
287
129
|
if (fiber.t === FiberTag.Suspense && fiber.b?.f)
|
|
288
130
|
setUpdateBoundary(fiber.b.f, boundary);
|
|
289
131
|
}
|
|
290
|
-
function renderSuspense(fiber: Fiber): void {
|
|
132
|
+
export function renderSuspense(fiber: Fiber): void {
|
|
291
133
|
const props = fiber.v ?? {};
|
|
292
134
|
let state = (fiber.b ??= {}) as SuspenseState;
|
|
293
135
|
// Streaming hydration: if the next DOM node is a server-emitted boundary
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { readOwnerStack, runWithOwnerStack } from '../../../core/devtools';
|
|
2
|
+
import type { Fiber } from '../../../core';
|
|
3
|
+
import { checkpointCommit, rewindCommit, queueMutation, onCommitFailure, onCommitRollback, commitSynchronously } from '../../commit';
|
|
4
|
+
import { findRoot, unmountAllChildren, withCurrentRoot, runEffects, discardPendingWork, reconcileRaw, isThenable } from '../../reconcile';
|
|
5
|
+
import { HydrationCursor, setHydrationCursor, clearHydrationCursor, advanceCursorPast, isHydrationBailout } from '../hydration';
|
|
6
|
+
import { renderSuspense, scheduleRetry, retryHydration } from '../suspense/full';
|
|
7
|
+
|
|
8
|
+
function clearBoundaryRange(startMark: Comment, endMark: Comment): void {
|
|
9
|
+
queueMutation(() => {
|
|
10
|
+
let node = startMark.nextSibling;
|
|
11
|
+
while (node && node !== endMark) {
|
|
12
|
+
const next = node.nextSibling;
|
|
13
|
+
(node as ChildNode).remove();
|
|
14
|
+
node = next;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
function rehydrateBoundary(fiber: Fiber): void {
|
|
19
|
+
const state = fiber.b;
|
|
20
|
+
if (!state?.b || !state.e)
|
|
21
|
+
return;
|
|
22
|
+
const root = findRoot(fiber);
|
|
23
|
+
const parent = state.b.parentNode as Node;
|
|
24
|
+
if (!(root && parent))
|
|
25
|
+
return;
|
|
26
|
+
// Both initial hydration and a streamed reveal adopt the same marked range.
|
|
27
|
+
commitSynchronously(() => withCurrentRoot(root, () => {
|
|
28
|
+
const previous = root.h;
|
|
29
|
+
try {
|
|
30
|
+
const kind = state.b.data.startsWith('$E') ? 3 : state.b.data.startsWith('$!') ? 2 : 0;
|
|
31
|
+
if (!kind)
|
|
32
|
+
unmountAllChildren(fiber);
|
|
33
|
+
root.h = true;
|
|
34
|
+
hydrateSuspenseBoundary(fiber, { ...fiber.v, children: state.r }, [kind, 0, state.b, state.e], true);
|
|
35
|
+
}
|
|
36
|
+
finally {
|
|
37
|
+
root.h = previous;
|
|
38
|
+
}
|
|
39
|
+
runEffects(root);
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
function reportServerFailure(fiber: Fiber): void {
|
|
43
|
+
const error = new Error(process.env.NODE_ENV !== 'production' ? 'Switched to client rendering because the server render did not complete.' : '');
|
|
44
|
+
const handler = findRoot(fiber)?.re;
|
|
45
|
+
if (handler) {
|
|
46
|
+
if (process.env.NODE_ENV !== 'production') runWithOwnerStack(readOwnerStack(fiber), () => handler(error, { componentStack: null }));
|
|
47
|
+
else handler(error, { componentStack: null });
|
|
48
|
+
}
|
|
49
|
+
else
|
|
50
|
+
console.error(error);
|
|
51
|
+
}
|
|
52
|
+
export function recoverBoundaryHydration(fiber: Fiber, children: any, parent: Node, startMark: Comment | null, endMark: Comment | null, retryBoundary?: boolean): void {
|
|
53
|
+
const clear = () => {
|
|
54
|
+
const dispose = fiber.b?.x;
|
|
55
|
+
if (dispose) queueMutation(dispose);
|
|
56
|
+
if (startMark && endMark)
|
|
57
|
+
clearBoundaryRange(startMark, endMark);
|
|
58
|
+
else
|
|
59
|
+
queueMutation(() => { parent.textContent = ''; });
|
|
60
|
+
};
|
|
61
|
+
const root = findRoot(fiber)!;
|
|
62
|
+
const prevHydrating = root.h;
|
|
63
|
+
if (!retryBoundary)
|
|
64
|
+
discardPendingWork(root);
|
|
65
|
+
clear();
|
|
66
|
+
unmountAllChildren(fiber);
|
|
67
|
+
root.h = false;
|
|
68
|
+
try {
|
|
69
|
+
if (retryBoundary) {
|
|
70
|
+
fiber.b = { b: startMark, e: endMark };
|
|
71
|
+
renderSuspense(fiber);
|
|
72
|
+
}
|
|
73
|
+
else
|
|
74
|
+
reconcileRaw(fiber, children);
|
|
75
|
+
if (endMark)
|
|
76
|
+
advanceCursorPast(fiber.p!, endMark);
|
|
77
|
+
}
|
|
78
|
+
catch (clientError) {
|
|
79
|
+
onCommitFailure(() => {
|
|
80
|
+
clear();
|
|
81
|
+
unmountAllChildren(fiber);
|
|
82
|
+
});
|
|
83
|
+
throw clientError;
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
root.h = prevHydrating;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
export function hydrateSuspenseBoundary(fiber: Fiber, props: any, boundary: [
|
|
90
|
+
0 | 1 | 2 | 3,
|
|
91
|
+
number,
|
|
92
|
+
Comment,
|
|
93
|
+
Comment
|
|
94
|
+
], reveal?: boolean): void {
|
|
95
|
+
const [pendingBoundary, id, startMark, endMark] = boundary;
|
|
96
|
+
// Record the boundary shape so we can re-hydrate on reveal.
|
|
97
|
+
fiber.b = {
|
|
98
|
+
b: startMark,
|
|
99
|
+
e: endMark,
|
|
100
|
+
r: props.children,
|
|
101
|
+
};
|
|
102
|
+
if (pendingBoundary >= 2) {
|
|
103
|
+
if (pendingBoundary === 3)
|
|
104
|
+
reportServerFailure(fiber);
|
|
105
|
+
recoverBoundaryHydration(fiber, props.children, startMark.parentNode!, startMark, endMark, true);
|
|
106
|
+
fiber.m = props;
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
if (!pendingBoundary) {
|
|
110
|
+
// Real DOM is inline between startMark and endMark. Hydrate into it.
|
|
111
|
+
const checkpoint = checkpointCommit(fiber);
|
|
112
|
+
const parent = startMark.parentNode!;
|
|
113
|
+
try {
|
|
114
|
+
setHydrationCursor(fiber, new HydrationCursor(parent, startMark.nextSibling, endMark));
|
|
115
|
+
reconcileRaw(fiber, props.children);
|
|
116
|
+
advanceCursorPast(fiber.p!, endMark);
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
// A marked boundary owns a known server range. Roll back only its
|
|
120
|
+
// unfinished preparation so siblings can hydrate while it waits.
|
|
121
|
+
if (isThenable(e)) {
|
|
122
|
+
rewindCommit(checkpoint);
|
|
123
|
+
fiber.b.w = true;
|
|
124
|
+
retryHydration(fiber, e);
|
|
125
|
+
advanceCursorPast(fiber.p!, endMark);
|
|
126
|
+
}
|
|
127
|
+
else if (!isHydrationBailout(e)) {
|
|
128
|
+
onCommitFailure(() => {
|
|
129
|
+
clearBoundaryRange(startMark, endMark);
|
|
130
|
+
unmountAllChildren(fiber);
|
|
131
|
+
});
|
|
132
|
+
throw e;
|
|
133
|
+
}
|
|
134
|
+
else recoverBoundaryHydration(fiber, props.children, parent, startMark, endMark);
|
|
135
|
+
}
|
|
136
|
+
finally {
|
|
137
|
+
clearHydrationCursor(fiber);
|
|
138
|
+
}
|
|
139
|
+
fiber.m = props;
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
if (startMark.data === '$?' || startMark.data === '$~') {
|
|
143
|
+
// React owns this pending server range until its reveal script runs.
|
|
144
|
+
// Hydrating the fallback would consume the transport template as a host.
|
|
145
|
+
fiber.b.w = true;
|
|
146
|
+
(startMark as any)._reactRetry = () => {
|
|
147
|
+
if (!fiber.u)
|
|
148
|
+
scheduleRetry(fiber);
|
|
149
|
+
};
|
|
150
|
+
advanceCursorPast(fiber.p!, endMark);
|
|
151
|
+
fiber.m = props;
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
// Pending transport owns this range until reveal. Keep the opaque server
|
|
155
|
+
// range owned by this fiber so deletion also retires its template/fallback.
|
|
156
|
+
fiber.b.w = true;
|
|
157
|
+
advanceCursorPast(fiber.p!, endMark);
|
|
158
|
+
const boundaryId = (findRoot(fiber)?.i ?? '') + 'B:' + id.toString(16);
|
|
159
|
+
const dispose = (globalThis as any).$RH?.(boundaryId, () => {
|
|
160
|
+
if (!fiber.u && !fiber.pd) rehydrateBoundary(fiber);
|
|
161
|
+
});
|
|
162
|
+
fiber.b.x = dispose;
|
|
163
|
+
if (dispose) onCommitRollback(dispose);
|
|
164
|
+
// If the inline runtime isn't present, nothing external will mark us dy.
|
|
165
|
+
fiber.m = props;
|
|
166
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './full'
|
package/src/dom/reconcile.ts
CHANGED
|
@@ -764,10 +764,9 @@ export function reconcileChildren(parent: Fiber, nodes: Parameters<typeof reconc
|
|
|
764
764
|
export function installRenderer(tag: FiberTag, fn: RenderFn): void {
|
|
765
765
|
RENDERERS[tag] = fn;
|
|
766
766
|
}
|
|
767
|
-
export const recoveringBoundaries = new Set<Fiber>();
|
|
768
767
|
function findErrorBoundary(fiber: Fiber): Fiber | null {
|
|
769
768
|
for (let parent = fiber.p; parent; parent = parent.p) {
|
|
770
|
-
if (parent.u || parent.pd ||
|
|
769
|
+
if (parent.u || parent.pd || parent.br)
|
|
771
770
|
continue;
|
|
772
771
|
const instance = parent.i;
|
|
773
772
|
if (instance?._f === parent && (parent.b?.b?.getDerivedStateFromError || instance.componentDidCatch))
|
|
@@ -1006,6 +1005,8 @@ function renderHost(fiber: Fiber): void {
|
|
|
1006
1005
|
applyHostProps(fiber.n as Element, props, undefined, isSvg, isInput, isTextarea, deferValue);
|
|
1007
1006
|
}
|
|
1008
1007
|
updateFragmentHost(fiber, true);
|
|
1008
|
+
if (!hydrated && props.autoFocus && !isSvg && (deferValue || type === 'button'))
|
|
1009
|
+
scheduleLifecycle(fiber, () => (fiber.n as HTMLElement).focus());
|
|
1009
1010
|
attachRef(fiber, fiber.n);
|
|
1010
1011
|
}
|
|
1011
1012
|
else if (prev !== props) {
|
|
@@ -1330,12 +1331,21 @@ export function scheduleUpdate(fiber: Fiber): void {
|
|
|
1330
1331
|
pendingRoots.add(root);
|
|
1331
1332
|
if (isBatching)
|
|
1332
1333
|
return;
|
|
1334
|
+
// Act owns in-scope work even when a normal microtask is already pending.
|
|
1335
|
+
if (process.env.NODE_ENV !== 'production' && ReactSharedInternals.A) {
|
|
1336
|
+
ReactSharedInternals.A.push(flushPending);
|
|
1337
|
+
return;
|
|
1338
|
+
}
|
|
1333
1339
|
if (!root.s) {
|
|
1334
1340
|
root.s = true;
|
|
1335
|
-
if (process.env.NODE_ENV !== 'production'
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1341
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1342
|
+
const scheduled = () => {
|
|
1343
|
+
if (root.s === scheduled) flushPending();
|
|
1344
|
+
};
|
|
1345
|
+
root.s = scheduled;
|
|
1346
|
+
queueMicrotask(scheduled);
|
|
1347
|
+
}
|
|
1348
|
+
else queueMicrotask(flushPending);
|
|
1339
1349
|
}
|
|
1340
1350
|
}
|
|
1341
1351
|
setCommitCheckpointHook(() => {
|
package/src/server/stream.ts
CHANGED
|
@@ -40,9 +40,8 @@ export interface PipeableWritable {
|
|
|
40
40
|
|
|
41
41
|
export interface OrchestratorState {
|
|
42
42
|
nextId: number
|
|
43
|
-
pending:
|
|
43
|
+
pending: (task?: Promise<void>) => Promise<void> | undefined
|
|
44
44
|
closed: boolean
|
|
45
|
-
errored: unknown | null
|
|
46
45
|
aborted: boolean
|
|
47
46
|
reason: unknown
|
|
48
47
|
abort: (reason?: unknown) => void
|
|
@@ -58,8 +57,17 @@ export interface OrchestratorState {
|
|
|
58
57
|
|
|
59
58
|
function createState(): OrchestratorState {
|
|
60
59
|
let wake!: () => void
|
|
60
|
+
let count = 0, notify: (() => void) | undefined, failed: unknown[] | undefined
|
|
61
61
|
const state: OrchestratorState = {
|
|
62
|
-
nextId: 0, pending
|
|
62
|
+
nextId: 0, pending(task) {
|
|
63
|
+
if (task) {
|
|
64
|
+
count++
|
|
65
|
+
const done = () => { count--; notify?.() }
|
|
66
|
+
// The empty box marks a consumed failure without retaining it or accepting later failures.
|
|
67
|
+
task.then(done, error => { failed ||= [error]; done() })
|
|
68
|
+
} else if (failed?.length) return Promise.reject(failed.pop())
|
|
69
|
+
else if (count) return new Promise<void>(resolve => { notify = resolve })
|
|
70
|
+
}, closed: false,
|
|
63
71
|
aborted: false, reason: undefined,
|
|
64
72
|
cancelled: new Promise<void>((resolve) => { wake = resolve }),
|
|
65
73
|
abort(reason) {
|
|
@@ -154,6 +162,7 @@ export async function streamHtml(
|
|
|
154
162
|
if (hints) shellChunks.splice(head, 0, hints)
|
|
155
163
|
if (state.frame) state.frame.shellFlushed = true
|
|
156
164
|
let html = partsHtml(shellChunks, state, options)
|
|
165
|
+
shellChunks.length = 0
|
|
157
166
|
|
|
158
167
|
// Inject runtime + bootstrap scripts (once, after shell). Skip the
|
|
159
168
|
// reveal/event-replay runtime when nothing needs it — no pending
|
|
@@ -184,13 +193,12 @@ export async function streamHtml(
|
|
|
184
193
|
|
|
185
194
|
// 3. Stream suspended boundaries as they resolve
|
|
186
195
|
for (const b of boundaries) streamBoundary(b, emit, options, state)
|
|
187
|
-
|
|
196
|
+
for (let next; (next = state.pending());) await next
|
|
188
197
|
} catch (err) {
|
|
189
198
|
if (isBrowserError(err)) {
|
|
190
199
|
err = new Error('The server render could not complete because client rendering was requested outside a Suspense boundary.',
|
|
191
200
|
Object.hasOwn(err, 'cause') ? { cause: err.cause } : undefined)
|
|
192
201
|
}
|
|
193
|
-
state.errored = err
|
|
194
202
|
if (options.onError) options.onError(err)
|
|
195
203
|
throw err
|
|
196
204
|
} finally {
|
|
@@ -266,8 +274,7 @@ function streamBoundary(
|
|
|
266
274
|
// Recurse: any nested suspensions inside the now-revealed content
|
|
267
275
|
for (const s of sub) streamBoundary(s, emit, options, state)
|
|
268
276
|
})()
|
|
269
|
-
state.pending
|
|
270
|
-
task.then(() => state.pending.delete(task), () => state.pending.delete(task))
|
|
277
|
+
state.pending(task)
|
|
271
278
|
}
|
|
272
279
|
|
|
273
280
|
// Serialize buffered output. Boundaries that completed or failed before this
|
|
@@ -288,12 +295,6 @@ function partsHtml(parts: HtmlPart[], state: OrchestratorState, options: StreamO
|
|
|
288
295
|
return html
|
|
289
296
|
}
|
|
290
297
|
|
|
291
|
-
async function drain(state: OrchestratorState): Promise<void> {
|
|
292
|
-
while (state.pending.size > 0) {
|
|
293
|
-
await Promise.race(state.pending)
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
|
|
297
298
|
function scriptNonce(options: StreamOptions): string | undefined {
|
|
298
299
|
return typeof options.nonce === 'string' ? options.nonce : options.nonce?.script
|
|
299
300
|
}
|
|
@@ -435,7 +436,7 @@ export function renderToReadableStream(
|
|
|
435
436
|
pull(controller) {
|
|
436
437
|
state.flowing = true
|
|
437
438
|
state.flush?.()
|
|
438
|
-
if (state.closed
|
|
439
|
+
if (state.closed) close(controller)
|
|
439
440
|
},
|
|
440
441
|
cancel(reason) {
|
|
441
442
|
state.abort(reason)
|