@tanstack/redact 0.0.20 → 0.1.0
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.js +2 -1
- package/dist/core/attributes.js.map +2 -2
- package/dist/core/browser.d.ts +9 -0
- package/dist/core/browser.js +35 -0
- package/dist/core/browser.js.map +7 -0
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +3 -3
- package/dist/core/internal.d.ts +31 -8
- package/dist/core/internal.js +3 -1
- package/dist/core/internal.js.map +2 -2
- package/dist/core/resource-hints.d.ts +7 -0
- package/dist/core/resource-hints.js +19 -0
- package/dist/core/resource-hints.js.map +7 -0
- package/dist/core/types.js +1 -1
- package/dist/dom/_all.d.ts +11 -16
- package/dist/dom/_all.js +9 -20
- package/dist/dom/_all.js.map +2 -2
- package/dist/dom/client.d.ts +4 -4
- package/dist/dom/client.js +4 -4
- package/dist/dom/commit.d.ts +23 -0
- package/dist/dom/commit.js +191 -0
- package/dist/dom/commit.js.map +7 -0
- package/dist/dom/dispatcher.d.ts +4 -22
- package/dist/dom/dispatcher.js +184 -126
- package/dist/dom/dispatcher.js.map +3 -3
- package/dist/dom/dom.d.ts +2 -0
- package/dist/dom/dom.js +72 -52
- package/dist/dom/dom.js.map +2 -2
- package/dist/dom/error-info.d.ts +2 -0
- package/dist/dom/error-info.js +16 -0
- package/dist/dom/error-info.js.map +7 -0
- package/dist/dom/event-replay.js +1 -1
- package/dist/dom/features/activity/full.d.ts +1 -0
- package/dist/dom/features/activity/full.js +162 -0
- package/dist/dom/features/activity/full.js.map +7 -0
- package/dist/dom/features/activity/index.d.ts +1 -0
- package/dist/dom/features/activity/index.js +3 -0
- package/dist/dom/features/activity/index.js.map +7 -0
- package/dist/dom/features/activity/stub.d.ts +1 -0
- package/dist/dom/features/activity/stub.js +12 -0
- package/dist/dom/features/activity/stub.js.map +7 -0
- package/dist/dom/features/class/full.js +87 -21
- package/dist/dom/features/class/full.js.map +2 -2
- package/dist/dom/features/class/index.d.ts +1 -1
- package/dist/dom/features/class/index.js +2 -2
- package/dist/dom/features/class/stub.js +3 -3
- package/dist/dom/features/context/full.d.ts +4 -1
- package/dist/dom/features/context/full.js +69 -9
- package/dist/dom/features/context/full.js.map +2 -2
- package/dist/dom/features/context/index.d.ts +1 -1
- package/dist/dom/features/context/index.js +2 -2
- package/dist/dom/features/context/stub.d.ts +4 -1
- package/dist/dom/features/context/stub.js +15 -4
- package/dist/dom/features/context/stub.js.map +2 -2
- package/dist/dom/features/forward-ref/full.js +12 -21
- package/dist/dom/features/forward-ref/full.js.map +2 -2
- package/dist/dom/features/forward-ref/index.d.ts +1 -1
- package/dist/dom/features/forward-ref/index.js +2 -2
- package/dist/dom/features/forward-ref/stub.js +4 -4
- package/dist/dom/features/fragment-refs/index.d.ts +1 -0
- package/dist/dom/features/fragment-refs/index.js +8 -0
- package/dist/dom/features/fragment-refs/index.js.map +7 -0
- package/dist/dom/features/fragment-refs/stub.d.ts +3 -0
- package/dist/dom/features/fragment-refs/stub.js +14 -0
- package/dist/dom/features/fragment-refs/stub.js.map +7 -0
- package/dist/dom/features/hydration/full.d.ts +11 -6
- package/dist/dom/features/hydration/full.js +76 -76
- package/dist/dom/features/hydration/full.js.map +2 -2
- package/dist/dom/features/hydration/index.d.ts +1 -1
- package/dist/dom/features/hydration/index.js +2 -2
- package/dist/dom/features/hydration/stub.d.ts +7 -2
- package/dist/dom/features/hydration/stub.js +1 -1
- package/dist/dom/features/hydration/stub.js.map +1 -1
- package/dist/dom/features/index.d.ts +8 -7
- package/dist/dom/features/index.js +9 -8
- package/dist/dom/features/index.js.map +2 -2
- package/dist/dom/features/lazy/full.js +4 -4
- package/dist/dom/features/lazy/index.d.ts +1 -1
- package/dist/dom/features/lazy/index.js +2 -2
- package/dist/dom/features/lazy/stub.js +4 -4
- package/dist/dom/features/memo/full.js +8 -6
- package/dist/dom/features/memo/full.js.map +2 -2
- package/dist/dom/features/memo/index.d.ts +1 -1
- package/dist/dom/features/memo/index.js +2 -2
- package/dist/dom/features/memo/stub.js +4 -4
- package/dist/dom/features/portal/full.js +4 -4
- package/dist/dom/features/portal/index.d.ts +1 -1
- package/dist/dom/features/portal/index.js +2 -2
- package/dist/dom/features/portal/stub.js +4 -4
- package/dist/dom/features/suspense/full.js +192 -47
- package/dist/dom/features/suspense/full.js.map +2 -2
- package/dist/dom/features/suspense/index.d.ts +1 -1
- package/dist/dom/features/suspense/index.js +2 -2
- package/dist/dom/features/suspense/stub.js +4 -4
- package/dist/dom/features/view-transition/full.d.ts +6 -0
- package/dist/dom/features/view-transition/full.js +280 -0
- package/dist/dom/features/view-transition/full.js.map +7 -0
- package/dist/dom/features/view-transition/index.d.ts +1 -0
- package/dist/dom/features/view-transition/index.js +3 -0
- package/dist/dom/features/view-transition/index.js.map +7 -0
- package/dist/dom/features/view-transition/resources.d.ts +11 -0
- package/dist/dom/features/view-transition/resources.js +108 -0
- package/dist/dom/features/view-transition/resources.js.map +7 -0
- package/dist/dom/features/view-transition/stub.d.ts +6 -0
- package/dist/dom/features/view-transition/stub.js +22 -0
- package/dist/dom/features/view-transition/stub.js.map +7 -0
- package/dist/dom/features/view-transition/visual.d.ts +14 -0
- package/dist/dom/features/view-transition/visual.js +356 -0
- package/dist/dom/features/view-transition/visual.js.map +7 -0
- package/dist/dom/fragment-instance.d.ts +40 -0
- package/dist/dom/fragment-instance.js +324 -0
- package/dist/dom/fragment-instance.js.map +7 -0
- package/dist/dom/index.d.ts +11 -11
- package/dist/dom/index.js +11 -18
- package/dist/dom/index.js.map +3 -3
- package/dist/dom/portal.d.ts +2 -2
- package/dist/dom/portal.js +2 -2
- package/dist/dom/portal.js.map +1 -1
- package/dist/dom/reconcile.d.ts +32 -3
- package/dist/dom/reconcile.js +686 -222
- package/dist/dom/reconcile.js.map +2 -2
- package/dist/dom/resource-hints.d.ts +6 -0
- package/dist/dom/resource-hints.js +115 -0
- package/dist/dom/resource-hints.js.map +7 -0
- package/dist/dom/resource-store.d.ts +13 -0
- package/dist/dom/resource-store.js +43 -0
- package/dist/dom/resource-store.js.map +7 -0
- package/dist/dom/resources.d.ts +1 -0
- package/dist/dom/resources.js +44 -0
- package/dist/dom/resources.js.map +7 -0
- package/dist/dom/retained-effects.d.ts +6 -0
- package/dist/dom/retained-effects.js +49 -0
- package/dist/dom/retained-effects.js.map +7 -0
- package/dist/dom/root-internal.d.ts +4 -4
- package/dist/dom/root-internal.js +2 -2
- package/dist/dom/root-internal.js.map +2 -2
- package/dist/dom/root.d.ts +5 -5
- package/dist/dom/root.js +11 -11
- package/dist/dom/root.js.map +2 -2
- package/dist/dom/test-utils.js +1 -1
- package/dist/react/activity.d.ts +7 -0
- package/dist/react/activity.js +8 -0
- package/dist/react/activity.js.map +7 -0
- package/dist/react/children.d.ts +1 -1
- package/dist/react/children.js +3 -3
- package/dist/react/children.js.map +1 -1
- package/dist/react/class.d.ts +1 -1
- package/dist/react/class.js +3 -3
- package/dist/react/class.js.map +1 -1
- package/dist/react/compiler-runtime.js +2 -2
- package/dist/react/context.d.ts +1 -1
- package/dist/react/context.js +3 -3
- package/dist/react/context.js.map +1 -1
- package/dist/react/element.d.ts +6 -3
- package/dist/react/element.js +2 -2
- package/dist/react/element.js.map +2 -2
- package/dist/react/hooks.d.ts +26 -7
- package/dist/react/hooks.js +13 -3
- package/dist/react/hooks.js.map +2 -2
- package/dist/react/index.d.ts +39 -24
- package/dist/react/index.js +39 -19
- package/dist/react/index.js.map +3 -3
- package/dist/react/jsx-runtime.d.ts +2 -2
- package/dist/react/jsx-runtime.js +3 -3
- package/dist/react/memo.d.ts +1 -1
- package/dist/react/memo.js +1 -1
- package/dist/react/portal.js +1 -1
- package/dist/react/shared-internals.d.ts +15 -5
- package/dist/react/shared-internals.js +2 -3
- package/dist/react/shared-internals.js.map +2 -2
- package/dist/react/suspense.js +1 -1
- package/dist/react/view-transition.d.ts +32 -0
- package/dist/react/view-transition.js +13 -0
- package/dist/react/view-transition.js.map +7 -0
- package/dist/scheduler/index.js +1 -1
- package/dist/server/bootstrap-script.d.ts +1 -23
- package/dist/server/bootstrap-script.js +7 -6
- package/dist/server/bootstrap-script.js.map +2 -2
- package/dist/server/dispatcher.d.ts +28 -6
- package/dist/server/dispatcher.js +33 -15
- package/dist/server/dispatcher.js.map +2 -2
- package/dist/server/escape.js +16 -15
- package/dist/server/escape.js.map +2 -2
- package/dist/server/index.d.ts +6 -6
- package/dist/server/index.js +7 -7
- package/dist/server/renderToString.d.ts +1 -1
- package/dist/server/renderToString.js +12 -8
- package/dist/server/renderToString.js.map +2 -2
- package/dist/server/resource-hints.d.ts +22 -0
- package/dist/server/resource-hints.js +148 -0
- package/dist/server/resource-hints.js.map +7 -0
- package/dist/server/stream.d.ts +15 -2
- package/dist/server/stream.js +155 -63
- package/dist/server/stream.js.map +2 -2
- package/dist/server/walk.d.ts +15 -2
- package/dist/server/walk.js +143 -96
- package/dist/server/walk.js.map +2 -2
- package/dist/vite/index.d.ts +6 -0
- package/dist/vite/index.js +22 -6
- package/dist/vite/index.js.map +2 -2
- package/package.json +1 -1
- package/src/core/attributes.ts +1 -0
- package/src/core/browser.ts +33 -0
- package/src/core/internal.ts +24 -6
- package/src/core/resource-hints.ts +36 -0
- package/src/dom/_all.ts +1 -7
- package/src/dom/commit.ts +186 -0
- package/src/dom/dispatcher.ts +190 -134
- package/src/dom/dom.ts +70 -54
- package/src/dom/error-info.ts +15 -0
- package/src/dom/features/activity/full.ts +166 -0
- package/src/dom/features/activity/index.ts +1 -0
- package/src/dom/features/activity/stub.ts +14 -0
- package/src/dom/features/class/full.ts +72 -21
- package/src/dom/features/context/full.ts +66 -4
- package/src/dom/features/context/stub.ts +6 -0
- package/src/dom/features/forward-ref/full.ts +9 -19
- package/src/dom/features/fragment-refs/index.ts +1 -0
- package/src/dom/features/fragment-refs/stub.ts +3 -0
- package/src/dom/features/hydration/full.ts +84 -82
- package/src/dom/features/hydration/stub.ts +1 -1
- package/src/dom/features/index.ts +1 -0
- package/src/dom/features/memo/full.ts +4 -3
- package/src/dom/features/suspense/full.ts +187 -50
- package/src/dom/features/view-transition/full.ts +288 -0
- package/src/dom/features/view-transition/index.ts +1 -0
- package/src/dom/features/view-transition/resources.ts +107 -0
- package/src/dom/features/view-transition/stub.ts +7 -0
- package/src/dom/features/view-transition/visual.ts +406 -0
- package/src/dom/fragment-instance.ts +337 -0
- package/src/dom/index.ts +6 -7
- package/src/dom/portal.ts +1 -1
- package/src/dom/reconcile.ts +691 -244
- package/src/dom/resource-hints.ts +115 -0
- package/src/dom/resource-store.ts +52 -0
- package/src/dom/resources.ts +39 -0
- package/src/dom/retained-effects.ts +38 -0
- package/src/dom/root-internal.ts +4 -4
- package/src/dom/root.ts +12 -14
- package/src/react/activity.ts +10 -0
- package/src/react/element.ts +6 -2
- package/src/react/hooks.ts +12 -3
- package/src/react/index.ts +18 -0
- package/src/react/shared-internals.ts +3 -3
- package/src/react/view-transition.ts +41 -0
- package/src/server/bootstrap-script.ts +36 -5
- package/src/server/dispatcher.ts +35 -13
- package/src/server/escape.ts +15 -12
- package/src/server/renderToString.ts +7 -5
- package/src/server/resource-hints.ts +165 -0
- package/src/server/stream.ts +154 -62
- package/src/server/walk.ts +72 -11
- package/src/vite/index.ts +30 -13
package/dist/server/walk.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
//
|
|
1
|
+
// src/server/walk.ts
|
|
2
2
|
import {
|
|
3
3
|
REACT_ELEMENT_TYPE,
|
|
4
4
|
REACT_LEGACY_ELEMENT_TYPE,
|
|
5
5
|
REACT_FRAGMENT_TYPE
|
|
6
|
-
} from "../core";
|
|
6
|
+
} from "../core/index.js";
|
|
7
7
|
import {
|
|
8
8
|
REACT_SUSPENSE_TYPE,
|
|
9
9
|
REACT_PROVIDER_TYPE,
|
|
@@ -13,20 +13,26 @@ import {
|
|
|
13
13
|
REACT_LAZY_TYPE,
|
|
14
14
|
REACT_STRICT_MODE_TYPE,
|
|
15
15
|
REACT_PROFILER_TYPE,
|
|
16
|
-
REACT_PORTAL_TYPE
|
|
17
|
-
|
|
16
|
+
REACT_PORTAL_TYPE,
|
|
17
|
+
REACT_ACTIVITY_TYPE,
|
|
18
|
+
REACT_VIEW_TRANSITION_TYPE
|
|
19
|
+
} from "../react/index.js";
|
|
18
20
|
import {
|
|
19
21
|
attrToHtml,
|
|
20
22
|
escapeText,
|
|
21
23
|
escapeScript,
|
|
22
24
|
VOID_ELEMENTS,
|
|
23
25
|
RAW_TEXT_ELEMENTS
|
|
24
|
-
} from "./escape";
|
|
26
|
+
} from "./escape.js";
|
|
25
27
|
import {
|
|
26
28
|
pushContext,
|
|
27
29
|
popContext,
|
|
28
|
-
snapshotContexts
|
|
29
|
-
|
|
30
|
+
snapshotContexts,
|
|
31
|
+
recordHostResource,
|
|
32
|
+
currentSSRFrame
|
|
33
|
+
} from "./dispatcher.js";
|
|
34
|
+
import { isBrowserError } from "../core/browser.js";
|
|
35
|
+
import { resourceKind } from "../core/resource-hints.js";
|
|
30
36
|
function walk(node, opts) {
|
|
31
37
|
if (!opts.textState) opts = { ...opts, textState: { lastWasText: false } };
|
|
32
38
|
walkNode(node, opts);
|
|
@@ -94,6 +100,14 @@ function walkElement(el, opts) {
|
|
|
94
100
|
walkSuspense(props, opts);
|
|
95
101
|
return;
|
|
96
102
|
}
|
|
103
|
+
if (type === REACT_ACTIVITY_TYPE) {
|
|
104
|
+
if (props.mode !== "hidden") walkNode(props.children, opts);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (type === REACT_VIEW_TRANSITION_TYPE) {
|
|
108
|
+
walkNode(props.children, opts);
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
97
111
|
if (typeof type === "string") {
|
|
98
112
|
walkHost(type, props, opts);
|
|
99
113
|
return;
|
|
@@ -124,8 +138,7 @@ function walkElement(el, opts) {
|
|
|
124
138
|
const render = type.render;
|
|
125
139
|
const ref = props.ref ?? null;
|
|
126
140
|
const { ref: _omit, ...rest } = props;
|
|
127
|
-
|
|
128
|
-
walkNode(rendered, opts);
|
|
141
|
+
walkComponent(render, rest, opts, ref);
|
|
129
142
|
return;
|
|
130
143
|
}
|
|
131
144
|
if (marker === REACT_MEMO_TYPE) {
|
|
@@ -153,6 +166,7 @@ function walkElement(el, opts) {
|
|
|
153
166
|
}
|
|
154
167
|
function walkHost(tag, props, opts) {
|
|
155
168
|
const isSvg = opts.isSvg || tag === "svg";
|
|
169
|
+
if (!isSvg && resourceKind(tag, props) && recordHostResource(tag, props, opts.resourceScope)) return;
|
|
156
170
|
const isTextarea = tag === "textarea";
|
|
157
171
|
const textareaValue = isTextarea ? props.value != null ? props.value : props.defaultValue : void 0;
|
|
158
172
|
const isInput = tag === "input";
|
|
@@ -164,76 +178,82 @@ function walkHost(tag, props, opts) {
|
|
|
164
178
|
pushSelectContext(val);
|
|
165
179
|
}
|
|
166
180
|
const isOption = tag === "option";
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
181
|
+
try {
|
|
182
|
+
if (tag === "html") opts.emit("<!DOCTYPE html>");
|
|
183
|
+
opts.emit("<" + tag);
|
|
184
|
+
for (const k in props) {
|
|
185
|
+
if (isTextarea && (k === "value" || k === "defaultValue")) continue;
|
|
186
|
+
if (isInput && (k === "defaultValue" || k === "defaultChecked")) continue;
|
|
187
|
+
if (isSelect && (k === "value" || k === "defaultValue")) continue;
|
|
188
|
+
if (isOption && k === "selected") continue;
|
|
189
|
+
opts.emit(attrToHtml(k, props[k], isSvg));
|
|
190
|
+
}
|
|
191
|
+
if (inputValueAttr !== void 0) {
|
|
192
|
+
opts.emit(attrToHtml("value", inputValueAttr, isSvg));
|
|
193
|
+
}
|
|
194
|
+
if (inputCheckedAttr !== void 0) {
|
|
195
|
+
opts.emit(attrToHtml("checked", inputCheckedAttr, isSvg));
|
|
196
|
+
}
|
|
197
|
+
if (isOption) {
|
|
198
|
+
const selectVal = currentSelectValue();
|
|
199
|
+
if (selectVal !== void 0) {
|
|
200
|
+
const optionValue = props.value != null ? props.value : optionChildText(props.children);
|
|
201
|
+
const matches = Array.isArray(selectVal) ? selectVal.some((v) => "" + v === "" + optionValue) : "" + selectVal === "" + optionValue;
|
|
202
|
+
if (matches) opts.emit(' selected=""');
|
|
203
|
+
} else if (props.selected) {
|
|
204
|
+
opts.emit(' selected=""');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
if (VOID_ELEMENTS.has(tag)) {
|
|
208
|
+
opts.emit("/>");
|
|
209
|
+
if (opts.textState) opts.textState.lastWasText = false;
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
opts.emit(">");
|
|
213
|
+
if (tag === "head") opts.onHead?.();
|
|
214
|
+
const parentTextState = opts.textState;
|
|
215
|
+
const childOpts = {
|
|
216
|
+
...opts,
|
|
217
|
+
isSvg: isSvg && tag !== "foreignObject",
|
|
218
|
+
textState: { lastWasText: false }
|
|
219
|
+
};
|
|
220
|
+
if (tag === "html" && !hasHeadChild(props.children)) {
|
|
221
|
+
opts.emit("<head>");
|
|
222
|
+
opts.onHead?.();
|
|
223
|
+
opts.emit("</head>");
|
|
224
|
+
}
|
|
225
|
+
const dangerouslyHtml = props.dangerouslySetInnerHTML?.__html;
|
|
226
|
+
if (isTextarea && textareaValue != null) {
|
|
227
|
+
opts.emit(escapeText(String(textareaValue)));
|
|
228
|
+
opts.emit(`</${tag}>`);
|
|
229
|
+
if (parentTextState) parentTextState.lastWasText = false;
|
|
230
|
+
return;
|
|
231
|
+
}
|
|
232
|
+
if (RAW_TEXT_ELEMENTS.has(tag)) {
|
|
233
|
+
if (dangerouslyHtml != null) {
|
|
234
|
+
opts.emit(escapeScript(String(dangerouslyHtml)));
|
|
235
|
+
} else {
|
|
236
|
+
const children = props.children;
|
|
237
|
+
if (typeof children === "string" || typeof children === "number") {
|
|
238
|
+
opts.emit(escapeScript(String(children)));
|
|
239
|
+
} else if (Array.isArray(children)) {
|
|
240
|
+
opts.emit(escapeScript(children.filter((c) => c != null).join("")));
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
opts.emit(`</${tag}>`);
|
|
244
|
+
if (parentTextState) parentTextState.lastWasText = false;
|
|
245
|
+
return;
|
|
190
246
|
}
|
|
191
|
-
}
|
|
192
|
-
if (VOID_ELEMENTS.has(tag)) {
|
|
193
|
-
opts.emit("/>");
|
|
194
|
-
if (opts.textState) opts.textState.lastWasText = false;
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
opts.emit(">");
|
|
198
|
-
const parentTextState = opts.textState;
|
|
199
|
-
const childOpts = {
|
|
200
|
-
...opts,
|
|
201
|
-
isSvg: isSvg && tag !== "foreignObject",
|
|
202
|
-
textState: { lastWasText: false }
|
|
203
|
-
};
|
|
204
|
-
if (tag === "html" && !hasHeadChild(props.children)) {
|
|
205
|
-
opts.emit("<head></head>");
|
|
206
|
-
}
|
|
207
|
-
const dangerouslyHtml = props.dangerouslySetInnerHTML?.__html;
|
|
208
|
-
if (isTextarea && textareaValue != null) {
|
|
209
|
-
opts.emit(escapeText(String(textareaValue)));
|
|
210
|
-
opts.emit(`</${tag}>`);
|
|
211
|
-
if (parentTextState) parentTextState.lastWasText = false;
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
if (RAW_TEXT_ELEMENTS.has(tag)) {
|
|
215
247
|
if (dangerouslyHtml != null) {
|
|
216
|
-
opts.emit(
|
|
248
|
+
opts.emit(String(dangerouslyHtml));
|
|
217
249
|
} else {
|
|
218
|
-
|
|
219
|
-
if (typeof children === "string" || typeof children === "number") {
|
|
220
|
-
opts.emit(escapeScript(String(children)));
|
|
221
|
-
} else if (Array.isArray(children)) {
|
|
222
|
-
opts.emit(escapeScript(children.filter((c) => c != null).join("")));
|
|
223
|
-
}
|
|
250
|
+
walkNode(props.children, childOpts);
|
|
224
251
|
}
|
|
225
252
|
opts.emit(`</${tag}>`);
|
|
226
253
|
if (parentTextState) parentTextState.lastWasText = false;
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
if (dangerouslyHtml != null) {
|
|
230
|
-
opts.emit(String(dangerouslyHtml));
|
|
231
|
-
} else {
|
|
232
|
-
walkNode(props.children, childOpts);
|
|
254
|
+
} finally {
|
|
255
|
+
if (isSelect) popSelectContext();
|
|
233
256
|
}
|
|
234
|
-
opts.emit(`</${tag}>`);
|
|
235
|
-
if (isSelect) popSelectContext();
|
|
236
|
-
if (parentTextState) parentTextState.lastWasText = false;
|
|
237
257
|
}
|
|
238
258
|
function hasHeadChild(children) {
|
|
239
259
|
if (children == null || typeof children === "boolean") return false;
|
|
@@ -253,62 +273,89 @@ function isElementOfType(value, type) {
|
|
|
253
273
|
function isIterable(value) {
|
|
254
274
|
return !!value && typeof value[Symbol.iterator] === "function";
|
|
255
275
|
}
|
|
256
|
-
function walkComponent(fn, props, opts) {
|
|
257
|
-
if (
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
|
|
276
|
+
function walkComponent(fn, props, opts, ref) {
|
|
277
|
+
if (opts.onBrowserBailout) {
|
|
278
|
+
opts = { ...opts, componentStack: `
|
|
279
|
+
at ${fn.displayName || fn.name || "Anonymous"}${opts.componentStack || ""}` };
|
|
280
|
+
}
|
|
281
|
+
try {
|
|
282
|
+
if (fn.prototype?.isReactComponent) {
|
|
283
|
+
const ctxType = fn.contextType;
|
|
284
|
+
const ctxValue = ctxType ? ctxType._currentValue : void 0;
|
|
285
|
+
const instance = new fn(props, ctxValue);
|
|
286
|
+
instance.props = props;
|
|
287
|
+
instance.context = ctxValue;
|
|
288
|
+
if (fn.getDerivedStateFromProps) {
|
|
289
|
+
const d = fn.getDerivedStateFromProps(props, instance.state);
|
|
290
|
+
if (d) instance.state = { ...instance.state, ...d };
|
|
291
|
+
}
|
|
292
|
+
walkNode(instance.render(), opts);
|
|
293
|
+
return;
|
|
266
294
|
}
|
|
267
|
-
|
|
268
|
-
|
|
295
|
+
const rendered = fn(props, ref);
|
|
296
|
+
walkNode(rendered, opts);
|
|
297
|
+
} catch (error) {
|
|
298
|
+
if (opts.thrownInfo && !opts.thrownInfo.componentStack) opts.thrownInfo.componentStack = opts.componentStack;
|
|
299
|
+
if (isBrowserError(error) && !error.componentStack) {
|
|
300
|
+
Object.defineProperty(error, "componentStack", { value: opts.componentStack });
|
|
301
|
+
}
|
|
302
|
+
throw error;
|
|
269
303
|
}
|
|
270
|
-
const rendered = fn(props);
|
|
271
|
-
walkNode(rendered, opts);
|
|
272
304
|
}
|
|
273
305
|
function walkSuspense(props, opts) {
|
|
274
306
|
const id = opts.nextBoundaryId();
|
|
275
307
|
const contextSnapshot = snapshotContexts();
|
|
276
308
|
const childParts = [];
|
|
309
|
+
const nested = [];
|
|
310
|
+
const thrownInfo = {};
|
|
277
311
|
const childEmit = (s) => childParts.push(s);
|
|
312
|
+
const resourceScope = currentSSRFrame().shellFlushed ? {} : void 0;
|
|
278
313
|
try {
|
|
279
314
|
walkNode(props.children, {
|
|
315
|
+
...opts,
|
|
316
|
+
resourceScope,
|
|
317
|
+
thrownInfo,
|
|
280
318
|
emit: childEmit,
|
|
281
|
-
onSuspend: opts.onSuspend,
|
|
319
|
+
onSuspend: opts.onSuspend ? (boundary) => nested.push(boundary) : void 0,
|
|
282
320
|
nextBoundaryId: opts.nextBoundaryId
|
|
283
321
|
});
|
|
284
322
|
} catch (thenable) {
|
|
285
|
-
|
|
323
|
+
nested.length = 0;
|
|
324
|
+
if (isThenable(thenable) || isBrowserError(thenable)) {
|
|
286
325
|
const fallbackParts = [];
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
326
|
+
walkNode(props.fallback, {
|
|
327
|
+
...opts,
|
|
328
|
+
emit: (s) => fallbackParts.push(s),
|
|
329
|
+
onSuspend: opts.onSuspend ? (boundary) => nested.push(boundary) : void 0,
|
|
330
|
+
nextBoundaryId: opts.nextBoundaryId
|
|
331
|
+
});
|
|
332
|
+
if (isBrowserError(thenable)) {
|
|
333
|
+
opts.onBrowserBailout?.(thenable, { componentStack: thenable.componentStack || opts.componentStack || "" });
|
|
334
|
+
opts.emit(`<!--$!${id}-->${fallbackParts.join("")}<!--/$-->`);
|
|
335
|
+
for (const boundary of nested) opts.onSuspend?.(boundary);
|
|
336
|
+
return;
|
|
294
337
|
}
|
|
295
338
|
emitBoundary(opts, id, fallbackParts.join(""));
|
|
339
|
+
for (const boundary of nested) opts.onSuspend?.(boundary);
|
|
296
340
|
if (opts.onSuspend) {
|
|
297
341
|
opts.onSuspend({
|
|
298
342
|
id,
|
|
299
343
|
fallbackHTML: fallbackParts.join(""),
|
|
300
344
|
children: props.children,
|
|
301
345
|
thenable,
|
|
302
|
-
contextSnapshot
|
|
346
|
+
contextSnapshot,
|
|
347
|
+
componentStack: thrownInfo.componentStack || opts.componentStack || ""
|
|
303
348
|
});
|
|
304
349
|
}
|
|
305
350
|
return;
|
|
306
351
|
}
|
|
307
352
|
throw thenable;
|
|
308
353
|
}
|
|
354
|
+
if (resourceScope) currentSSRFrame().resources?.mergeScope(resourceScope, opts.resourceScope);
|
|
309
355
|
opts.emit(`<!--$${id}-->`);
|
|
310
356
|
opts.emit(childParts.join(""));
|
|
311
357
|
opts.emit(`<!--/$-->`);
|
|
358
|
+
for (const boundary of nested) opts.onSuspend?.(boundary);
|
|
312
359
|
}
|
|
313
360
|
function emitBoundary(opts, id, fallbackHTML) {
|
|
314
361
|
opts.emit(`<!--$?${id}--><div id="B:${id}">`);
|
package/dist/server/walk.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/server/walk.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n REACT_ELEMENT_TYPE,\n REACT_LEGACY_ELEMENT_TYPE,\n REACT_FRAGMENT_TYPE,\n type ReactNode,\n type ReactElement,\n} from '../core'\nimport {\n REACT_SUSPENSE_TYPE,\n REACT_PROVIDER_TYPE,\n REACT_CONSUMER_TYPE,\n REACT_FORWARD_REF_TYPE,\n REACT_MEMO_TYPE,\n REACT_LAZY_TYPE,\n REACT_STRICT_MODE_TYPE,\n REACT_PROFILER_TYPE,\n REACT_PORTAL_TYPE,\n} from '../react'\nimport {\n attrToHtml,\n escapeText,\n escapeScript,\n VOID_ELEMENTS,\n RAW_TEXT_ELEMENTS,\n} from './escape'\nimport {\n pushContext,\n popContext,\n snapshotContexts,\n type ContextSnapshot,\n} from './dispatcher'\n\nexport interface SuspendedBoundary {\n id: number\n fallbackHTML: string\n children: ReactNode\n thenable: Promise<any>\n contextSnapshot: ContextSnapshot\n}\n\nexport interface WalkOptions {\n emit: (chunk: string) => void\n onSuspend?: ((boundary: SuspendedBoundary) => void) | undefined\n nextBoundaryId: () => number\n bootstrapped?: boolean | undefined\n isBoundaryResolution?: boolean | undefined\n isSvg?: boolean | undefined\n /**\n * Tracks whether the most recent emission within the *current text flow*\n * ended with a text node. When the next emission is also text, we emit a\n * `<!-- -->` separator so the browser's HTML parser doesn't merge them\n * into a single text node \u2014 required for hydration to line up text\n * boundaries with the React tree. Reset to `false` whenever we enter a\n * new host element (`<tag>` opens a fresh text flow).\n */\n textState?: { lastWasText: boolean }\n}\n\n/**\n * Synchronously walk a React node and emit HTML string pieces to `opts.emit`.\n * Suspended boundaries are emitted as fallbacks with marker IDs; if `opts.onSuspend`\n * is provided, the suspension is recorded for later streaming.\n */\nexport function walk(node: ReactNode, opts: WalkOptions): void {\n // Seed a text state if the caller didn't provide one so the separator logic\n // is active for the whole tree.\n if (!opts.textState) opts = { ...opts, textState: { lastWasText: false } }\n walkNode(node, opts)\n}\n\n// --- <select> selection context ----------------------------------------------\n// Stack of active select values (or `undefined` when the current select has\n// no controlled value). `<option>` walks read the top of stack to decide\n// whether to emit `selected=\"\"`.\nconst selectValueStack: unknown[] = []\nfunction pushSelectContext(value: unknown): void {\n selectValueStack.push(value)\n}\nfunction popSelectContext(): void {\n selectValueStack.pop()\n}\nfunction currentSelectValue(): unknown {\n return selectValueStack.length ? selectValueStack[selectValueStack.length - 1] : undefined\n}\n\nfunction optionChildText(children: unknown): string {\n // `<option>Text</option>` \u2014 if no `value` prop, the option's value is its\n // flat string/number child content. Matches DOM semantics (`option.value`\n // defaults to `textContent` when no attribute is set).\n if (children == null) return ''\n if (typeof children === 'string' || typeof children === 'number') return '' + children\n if (Array.isArray(children)) return children.map(optionChildText).join('')\n return ''\n}\n\nfunction emitText(text: string, opts: WalkOptions): void {\n // Empty string renders no text node and doesn't start/extend a text flow \u2014\n // skip entirely so sibling text isn't separated by a stray `<!-- -->`.\n if (text === '') return\n if (opts.textState?.lastWasText) opts.emit('<!-- -->')\n opts.emit(escapeText(text))\n if (opts.textState) opts.textState.lastWasText = true\n}\n\nfunction walkNode(node: ReactNode, opts: WalkOptions): void {\n if (node == null || node === false || node === true) return\n\n if (typeof node === 'string') {\n emitText(node, opts)\n return\n }\n if (typeof node === 'number') {\n emitText(String(node), opts)\n return\n }\n if (Array.isArray(node)) {\n for (const c of node) walkNode(c, opts)\n return\n }\n if (typeof (node as any)[Symbol.iterator] === 'function') {\n for (const item of node as Iterable<ReactNode>) walkNode(item, opts)\n return\n }\n\n if (typeof node !== 'object') return\n const t = (node as any).$$typeof\n\n // Raw React.lazy in the tree (RSC Flight encodes 'use client' components \u2014\n // CodeBlock, CodeExplorer, etc. \u2014 as bare Lazy objects directly in the\n // tree, not wrapped in REACT_ELEMENT_TYPE). SSR previously dropped these\n // here, so code snippets never made it into the server HTML. The RSC\n // decoder server-side awaits payloads before rendering, so status is\n // 'fulfilled' and `_init()` returns the resolved element synchronously.\n // If still pending (shouldn't happen post-awaitLazyElements), throw the\n // thenable so streaming SSR suspends the current boundary and retries.\n if (t === REACT_LAZY_TYPE) {\n const lazy = node as any\n const resolved = lazy._init(lazy._payload)\n walkNode(resolved, opts)\n return\n }\n\n if (t !== REACT_ELEMENT_TYPE && t !== REACT_LEGACY_ELEMENT_TYPE) return\n\n const el = node as ReactElement\n walkElement(el, opts)\n}\n\nfunction walkElement(el: ReactElement, opts: WalkOptions): void {\n const type = el.type\n const props = el.props ?? {}\n\n if (type === REACT_FRAGMENT_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_PROFILER_TYPE) {\n walkNode(props.children, opts)\n return\n }\n\n if (type === REACT_SUSPENSE_TYPE) {\n walkSuspense(props, opts)\n return\n }\n\n if (typeof type === 'string') {\n walkHost(type, props, opts)\n return\n }\n\n const marker = (type as any)?.$$typeof\n\n if (marker === REACT_PORTAL_TYPE) {\n // Portals don't render to the main HTML output on the server.\n return\n }\n\n if (marker === REACT_PROVIDER_TYPE) {\n const ctx = (type as any)._context\n pushContext(ctx, props.value)\n try {\n walkNode(props.children, opts)\n } finally {\n popContext(ctx)\n }\n return\n }\n\n if (marker === REACT_CONSUMER_TYPE) {\n const ctx = (type as any)._context\n const render = props.children\n if (typeof render === 'function') {\n walkNode(render(ctx._currentValue), opts)\n }\n return\n }\n\n if (marker === REACT_FORWARD_REF_TYPE) {\n const render = (type as any).render\n const ref = (props as any).ref ?? null\n const { ref: _omit, ...rest } = props as any\n const rendered = render(rest, ref)\n walkNode(rendered, opts)\n return\n }\n\n if (marker === REACT_MEMO_TYPE) {\n const inner = (type as any).type\n walkElement({ ...el, type: inner } as ReactElement, opts)\n return\n }\n\n if (marker === REACT_LAZY_TYPE) {\n const { _payload, _init } = type as any\n try {\n const resolved = _init(_payload)\n walkElement({ ...el, type: resolved } as ReactElement, opts)\n } catch (thenable: any) {\n if (isThenable(thenable)) {\n // Suspend this point\n throw thenable\n }\n throw thenable\n }\n return\n }\n\n if (typeof type === 'function') {\n walkComponent(type, props, opts)\n return\n }\n}\n\nfunction walkHost(\n tag: string,\n props: Record<string, any>,\n opts: WalkOptions,\n): void {\n const isSvg = opts.isSvg || tag === 'svg'\n // <textarea value=\"...\"> serializes its value as a TEXT CHILD, not an\n // attribute. `defaultValue` is the fallback when `value` is absent. This\n // matches React and the HTML spec \u2014 `<textarea value=\"x\">` is not valid\n // HTML; the value is the element's textContent.\n const isTextarea = tag === 'textarea'\n const textareaValue = isTextarea\n ? props.value != null\n ? props.value\n : props.defaultValue\n : undefined\n\n // <input defaultValue=\"...\"> should parse with that value \u2014 emit it as a\n // `value` attribute. Similarly `defaultChecked` becomes `checked`. This\n // keeps hydration consistent: the browser parser sees the initial value,\n // and on client commit our setProp seeds `.defaultValue`/`.defaultChecked`\n // without stomping the user-typed value.\n const isInput = tag === 'input'\n const inputValueAttr =\n isInput && props.value == null && props.defaultValue != null\n ? props.defaultValue\n : undefined\n const inputCheckedAttr =\n isInput && props.checked == null && props.defaultChecked != null\n ? props.defaultChecked\n : undefined\n\n // <select value=\"...\"> does NOT become an attribute on `<select>` \u2014 the\n // HTML spec has no such attribute. React resolves the selection by stamping\n // `selected` on the matching `<option>` children during render. Stash the\n // target value(s) on the walk state and the child `<option>` walk reads it.\n const isSelect = tag === 'select'\n if (isSelect) {\n const val = props.value != null ? props.value : props.defaultValue\n pushSelectContext(val)\n }\n const isOption = tag === 'option'\n\n // Prepend the HTML5 doctype to the stream when rendering an <html> root.\n // Without it the browser parses the document in quirks mode, which breaks\n // CSS sizing (documentElement.clientHeight returns the content height, not\n // the viewport) \u2014 and Floating-UI-based libraries (Radix dropdowns etc.)\n // then compute off-screen positions for overlays.\n if (tag === 'html') opts.emit('<!DOCTYPE html>')\n\n opts.emit('<' + tag)\n for (const k in props) {\n if (isTextarea && (k === 'value' || k === 'defaultValue')) continue\n if (isInput && (k === 'defaultValue' || k === 'defaultChecked')) continue\n if (isSelect && (k === 'value' || k === 'defaultValue')) continue\n if (isOption && k === 'selected') continue\n opts.emit(attrToHtml(k, props[k], isSvg))\n }\n if (inputValueAttr !== undefined) {\n opts.emit(attrToHtml('value', inputValueAttr, isSvg))\n }\n if (inputCheckedAttr !== undefined) {\n opts.emit(attrToHtml('checked', inputCheckedAttr, isSvg))\n }\n if (isOption) {\n const selectVal = currentSelectValue()\n if (selectVal !== undefined) {\n const optionValue =\n props.value != null ? props.value : optionChildText(props.children)\n const matches = Array.isArray(selectVal)\n ? selectVal.some((v) => '' + v === '' + optionValue)\n : '' + selectVal === '' + optionValue\n if (matches) opts.emit(' selected=\"\"')\n } else if (props.selected) {\n opts.emit(' selected=\"\"')\n }\n }\n\n if (VOID_ELEMENTS.has(tag)) {\n opts.emit('/>')\n if (opts.textState) opts.textState.lastWasText = false\n return\n }\n opts.emit('>')\n // Opening a host element starts a fresh text flow context for its children.\n // Children's text separator tracking is independent of the outer context.\n const parentTextState = opts.textState\n const childOpts: WalkOptions = {\n ...opts,\n isSvg: isSvg && tag !== 'foreignObject',\n textState: { lastWasText: false },\n }\n\n if (tag === 'html' && !hasHeadChild(props.children)) {\n opts.emit('<head></head>')\n }\n\n const dangerouslyHtml = props.dangerouslySetInnerHTML?.__html\n\n if (isTextarea && textareaValue != null) {\n opts.emit(escapeText(String(textareaValue)))\n opts.emit(`</${tag}>`)\n if (parentTextState) parentTextState.lastWasText = false\n return\n }\n\n if (RAW_TEXT_ELEMENTS.has(tag)) {\n // script/style: raw-text. React allows either a string/number child or\n // dangerouslySetInnerHTML \u2014 some libs (Start's Scripts) use the latter.\n if (dangerouslyHtml != null) {\n opts.emit(escapeScript(String(dangerouslyHtml)))\n } else {\n const children = props.children\n if (typeof children === 'string' || typeof children === 'number') {\n opts.emit(escapeScript(String(children)))\n } else if (Array.isArray(children)) {\n opts.emit(escapeScript(children.filter((c) => c != null).join('')))\n }\n }\n opts.emit(`</${tag}>`)\n if (parentTextState) parentTextState.lastWasText = false\n return\n }\n\n if (dangerouslyHtml != null) {\n opts.emit(String(dangerouslyHtml))\n } else {\n walkNode(props.children, childOpts)\n }\n opts.emit(`</${tag}>`)\n if (isSelect) popSelectContext()\n // Host element closing resets outer flow \u2014 next sibling text starts fresh.\n if (parentTextState) parentTextState.lastWasText = false\n}\n\nfunction hasHeadChild(children: unknown): boolean {\n if (children == null || typeof children === 'boolean') return false\n if (Array.isArray(children)) return children.some(hasHeadChild)\n if (typeof children !== 'string' && isIterable(children)) {\n for (const child of children as Iterable<unknown>) {\n if (hasHeadChild(child)) return true\n }\n return false\n }\n return isElementOfType(children, 'head')\n}\n\nfunction isElementOfType(value: unknown, type: string): value is ReactElement {\n const marker = (value as ReactElement | null)?.$$typeof as unknown\n return (\n !!value &&\n typeof value === 'object' &&\n (marker === REACT_ELEMENT_TYPE || marker === REACT_LEGACY_ELEMENT_TYPE) &&\n (value as ReactElement).type === type\n )\n}\n\nfunction isIterable(value: unknown): value is Iterable<unknown> {\n return !!value && typeof (value as { [Symbol.iterator]?: unknown })[Symbol.iterator] === 'function'\n}\n\nfunction walkComponent(\n fn: Function,\n props: Record<string, any>,\n opts: WalkOptions,\n): void {\n if ((fn as any).prototype?.isReactComponent) {\n const ctxType = (fn as any).contextType\n const ctxValue = ctxType ? ctxType._currentValue : undefined\n const instance = new (fn as any)(props, ctxValue)\n instance.props = props\n instance.context = ctxValue\n if ((fn as any).getDerivedStateFromProps) {\n const d = (fn as any).getDerivedStateFromProps(props, instance.state)\n if (d) instance.state = { ...instance.state, ...d }\n }\n walkNode(instance.render(), opts)\n return\n }\n const rendered = (fn as any)(props)\n walkNode(rendered, opts)\n}\n\nfunction walkSuspense(\n props: Record<string, any>,\n opts: WalkOptions,\n): void {\n const id = opts.nextBoundaryId()\n // Snapshot contexts BEFORE attempting children, so if a descendant suspends\n // we can replay the same provider stack when re-rendering the boundary.\n const contextSnapshot = snapshotContexts()\n\n // Try to render the children synchronously. If a thenable is thrown,\n // record the boundary and emit the fallback.\n const childParts: string[] = []\n const childEmit = (s: string) => childParts.push(s)\n try {\n walkNode(props.children, {\n emit: childEmit,\n onSuspend: opts.onSuspend,\n nextBoundaryId: opts.nextBoundaryId,\n })\n } catch (thenable: any) {\n if (isThenable(thenable)) {\n const fallbackParts: string[] = []\n try {\n walkNode(props.fallback, {\n emit: (s) => fallbackParts.push(s),\n onSuspend: opts.onSuspend,\n nextBoundaryId: opts.nextBoundaryId,\n })\n } catch {\n // Fallback suspending is unsupported; emit nothing\n }\n emitBoundary(opts, id, fallbackParts.join(''))\n\n if (opts.onSuspend) {\n opts.onSuspend({\n id,\n fallbackHTML: fallbackParts.join(''),\n children: props.children,\n thenable,\n contextSnapshot,\n })\n }\n return\n }\n throw thenable\n }\n\n // Children rendered fully \u2014 emit them wrapped in resolved-boundary markers\n // (`<!--$N-->` / `<!--/$-->`). Without markers, the client hydrator has no\n // way to know this subtree is inside a Suspense, so if the client version\n // of a descendant (e.g. `React.lazy`) suspends it can't pinpoint which DOM\n // range to adopt on resolve \u2014 it creates fresh DOM next to the SSR content,\n // producing visible duplicates (e.g. double navbar logos). Markers let the\n // client treat this as a resolved boundary and hydrate in-place.\n opts.emit(`<!--$${id}-->`)\n opts.emit(childParts.join(''))\n opts.emit(`<!--/$-->`)\n}\n\nfunction emitBoundary(opts: WalkOptions, id: number, fallbackHTML: string): void {\n // Visible div wrapper so the fallback UI shows; B: id lets $RC locate it on\n // reveal. The leading/trailing comments let hydration detect a pending\n // boundary and register a reveal callback.\n opts.emit(`<!--$?${id}--><div id=\"B:${id}\">`)\n opts.emit(fallbackHTML)\n opts.emit(`</div><!--/$-->`)\n}\n\nfunction isThenable(x: any): x is Promise<any> {\n return x != null && typeof x.then === 'function'\n}\n"],
|
|
5
|
-
"mappings": ";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAEK;
|
|
4
|
+
"sourcesContent": ["import {\n REACT_ELEMENT_TYPE,\n REACT_LEGACY_ELEMENT_TYPE,\n REACT_FRAGMENT_TYPE,\n type ReactNode,\n type ReactElement,\n} from '../core'\nimport {\n REACT_SUSPENSE_TYPE,\n REACT_PROVIDER_TYPE,\n REACT_CONSUMER_TYPE,\n REACT_FORWARD_REF_TYPE,\n REACT_MEMO_TYPE,\n REACT_LAZY_TYPE,\n REACT_STRICT_MODE_TYPE,\n REACT_PROFILER_TYPE,\n REACT_PORTAL_TYPE,\n REACT_ACTIVITY_TYPE,\n REACT_VIEW_TRANSITION_TYPE,\n} from '../react'\nimport {\n attrToHtml,\n escapeText,\n escapeScript,\n VOID_ELEMENTS,\n RAW_TEXT_ELEMENTS,\n} from './escape'\nimport {\n pushContext,\n popContext,\n snapshotContexts,\n recordHostResource,\n currentSSRFrame,\n type ContextSnapshot,\n} from './dispatcher'\nimport { isBrowserError } from '../core/browser'\nimport { resourceKind } from '../core/resource-hints'\nimport type { ResourceScope } from './resource-hints'\n\nexport interface ServerErrorInfo {\n componentStack: string\n}\n\nexport type BrowserBailoutCallback = (error: Error, errorInfo: ServerErrorInfo) => void\n\nexport interface SuspendedBoundary {\n id: number\n fallbackHTML: string\n children: ReactNode\n thenable: Promise<any>\n contextSnapshot: ContextSnapshot\n componentStack: string\n}\n\nexport interface WalkOptions {\n emit: (chunk: string) => void\n onHead?: () => void\n onSuspend?: ((boundary: SuspendedBoundary) => void) | undefined\n onBrowserBailout?: BrowserBailoutCallback | undefined\n componentStack?: string | undefined\n thrownInfo?: { componentStack?: string | undefined }\n nextBoundaryId: () => number\n bootstrapped?: boolean | undefined\n isBoundaryResolution?: boolean | undefined\n isSvg?: boolean | undefined\n resourceScope?: ResourceScope | undefined\n /**\n * Tracks whether the most recent emission within the *current text flow*\n * ended with a text node. When the next emission is also text, we emit a\n * `<!-- -->` separator so the browser's HTML parser doesn't merge them\n * into a single text node \u2014 required for hydration to line up text\n * boundaries with the React tree. Reset to `false` whenever we enter a\n * new host element (`<tag>` opens a fresh text flow).\n */\n textState?: { lastWasText: boolean }\n}\n\n/**\n * Synchronously walk a React node and emit HTML string pieces to `opts.emit`.\n * Suspended boundaries are emitted as fallbacks with marker IDs; if `opts.onSuspend`\n * is provided, the suspension is recorded for later streaming.\n */\nexport function walk(node: ReactNode, opts: WalkOptions): void {\n // Seed a text state if the caller didn't provide one so the separator logic\n // is active for the whole tree.\n if (!opts.textState) opts = { ...opts, textState: { lastWasText: false } }\n walkNode(node, opts)\n}\n\n// --- <select> selection context ----------------------------------------------\n// Stack of active select values (or `undefined` when the current select has\n// no controlled value). `<option>` walks read the top of stack to decide\n// whether to emit `selected=\"\"`.\nconst selectValueStack: unknown[] = []\nfunction pushSelectContext(value: unknown): void {\n selectValueStack.push(value)\n}\nfunction popSelectContext(): void {\n selectValueStack.pop()\n}\nfunction currentSelectValue(): unknown {\n return selectValueStack.length ? selectValueStack[selectValueStack.length - 1] : undefined\n}\n\nfunction optionChildText(children: unknown): string {\n // `<option>Text</option>` \u2014 if no `value` prop, the option's value is its\n // flat string/number child content. Matches DOM semantics (`option.value`\n // defaults to `textContent` when no attribute is set).\n if (children == null) return ''\n if (typeof children === 'string' || typeof children === 'number') return '' + children\n if (Array.isArray(children)) return children.map(optionChildText).join('')\n return ''\n}\n\nfunction emitText(text: string, opts: WalkOptions): void {\n // Empty string renders no text node and doesn't start/extend a text flow \u2014\n // skip entirely so sibling text isn't separated by a stray `<!-- -->`.\n if (text === '') return\n if (opts.textState?.lastWasText) opts.emit('<!-- -->')\n opts.emit(escapeText(text))\n if (opts.textState) opts.textState.lastWasText = true\n}\n\nfunction walkNode(node: ReactNode, opts: WalkOptions): void {\n if (node == null || node === false || node === true) return\n\n if (typeof node === 'string') {\n emitText(node, opts)\n return\n }\n if (typeof node === 'number') {\n emitText(String(node), opts)\n return\n }\n if (Array.isArray(node)) {\n for (const c of node) walkNode(c, opts)\n return\n }\n if (typeof (node as any)[Symbol.iterator] === 'function') {\n for (const item of node as Iterable<ReactNode>) walkNode(item, opts)\n return\n }\n\n if (typeof node !== 'object') return\n const t = (node as any).$$typeof\n\n // Raw React.lazy in the tree (RSC Flight encodes 'use client' components \u2014\n // CodeBlock, CodeExplorer, etc. \u2014 as bare Lazy objects directly in the\n // tree, not wrapped in REACT_ELEMENT_TYPE). SSR previously dropped these\n // here, so code snippets never made it into the server HTML. The RSC\n // decoder server-side awaits payloads before rendering, so status is\n // 'fulfilled' and `_init()` returns the resolved element synchronously.\n // If still pending (shouldn't happen post-awaitLazyElements), throw the\n // thenable so streaming SSR suspends the current boundary and retries.\n if (t === REACT_LAZY_TYPE) {\n const lazy = node as any\n const resolved = lazy._init(lazy._payload)\n walkNode(resolved, opts)\n return\n }\n\n if (t !== REACT_ELEMENT_TYPE && t !== REACT_LEGACY_ELEMENT_TYPE) return\n\n const el = node as ReactElement\n walkElement(el, opts)\n}\n\nfunction walkElement(el: ReactElement, opts: WalkOptions): void {\n const type = el.type\n const props = el.props ?? {}\n\n if (type === REACT_FRAGMENT_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_PROFILER_TYPE) {\n walkNode(props.children, opts)\n return\n }\n\n if (type === REACT_SUSPENSE_TYPE) {\n walkSuspense(props, opts)\n return\n }\n\n if (type === REACT_ACTIVITY_TYPE) {\n if (props.mode !== 'hidden') walkNode(props.children, opts)\n return\n }\n if (type === REACT_VIEW_TRANSITION_TYPE) {\n walkNode(props.children, opts)\n return\n }\n\n if (typeof type === 'string') {\n walkHost(type, props, opts)\n return\n }\n\n const marker = (type as any)?.$$typeof\n\n if (marker === REACT_PORTAL_TYPE) {\n // Portals don't render to the main HTML output on the server.\n return\n }\n\n if (marker === REACT_PROVIDER_TYPE) {\n const ctx = (type as any)._context\n pushContext(ctx, props.value)\n try {\n walkNode(props.children, opts)\n } finally {\n popContext(ctx)\n }\n return\n }\n\n if (marker === REACT_CONSUMER_TYPE) {\n const ctx = (type as any)._context\n const render = props.children\n if (typeof render === 'function') {\n walkNode(render(ctx._currentValue), opts)\n }\n return\n }\n\n if (marker === REACT_FORWARD_REF_TYPE) {\n const render = (type as any).render\n const ref = (props as any).ref ?? null\n const { ref: _omit, ...rest } = props as any\n walkComponent(render, rest, opts, ref)\n return\n }\n\n if (marker === REACT_MEMO_TYPE) {\n const inner = (type as any).type\n walkElement({ ...el, type: inner } as ReactElement, opts)\n return\n }\n\n if (marker === REACT_LAZY_TYPE) {\n const { _payload, _init } = type as any\n try {\n const resolved = _init(_payload)\n walkElement({ ...el, type: resolved } as ReactElement, opts)\n } catch (thenable: any) {\n if (isThenable(thenable)) {\n // Suspend this point\n throw thenable\n }\n throw thenable\n }\n return\n }\n\n if (typeof type === 'function') {\n walkComponent(type, props, opts)\n return\n }\n}\n\nfunction walkHost(\n tag: string,\n props: Record<string, any>,\n opts: WalkOptions,\n): void {\n const isSvg = opts.isSvg || tag === 'svg'\n if (!isSvg && resourceKind(tag, props) && recordHostResource(tag, props, opts.resourceScope)) return\n // <textarea value=\"...\"> serializes its value as a TEXT CHILD, not an\n // attribute. `defaultValue` is the fallback when `value` is absent. This\n // matches React and the HTML spec \u2014 `<textarea value=\"x\">` is not valid\n // HTML; the value is the element's textContent.\n const isTextarea = tag === 'textarea'\n const textareaValue = isTextarea\n ? props.value != null\n ? props.value\n : props.defaultValue\n : undefined\n\n // <input defaultValue=\"...\"> should parse with that value \u2014 emit it as a\n // `value` attribute. Similarly `defaultChecked` becomes `checked`. This\n // keeps hydration consistent: the browser parser sees the initial value,\n // and on client commit our setProp seeds `.defaultValue`/`.defaultChecked`\n // without stomping the user-typed value.\n const isInput = tag === 'input'\n const inputValueAttr =\n isInput && props.value == null && props.defaultValue != null\n ? props.defaultValue\n : undefined\n const inputCheckedAttr =\n isInput && props.checked == null && props.defaultChecked != null\n ? props.defaultChecked\n : undefined\n\n // <select value=\"...\"> does NOT become an attribute on `<select>` \u2014 the\n // HTML spec has no such attribute. React resolves the selection by stamping\n // `selected` on the matching `<option>` children during render. Stash the\n // target value(s) on the walk state and the child `<option>` walk reads it.\n const isSelect = tag === 'select'\n if (isSelect) {\n const val = props.value != null ? props.value : props.defaultValue\n pushSelectContext(val)\n }\n const isOption = tag === 'option'\n try {\n\n // Prepend the HTML5 doctype to the stream when rendering an <html> root.\n // Without it the browser parses the document in quirks mode, which breaks\n // CSS sizing (documentElement.clientHeight returns the content height, not\n // the viewport) \u2014 and Floating-UI-based libraries (Radix dropdowns etc.)\n // then compute off-screen positions for overlays.\n if (tag === 'html') opts.emit('<!DOCTYPE html>')\n\n opts.emit('<' + tag)\n for (const k in props) {\n if (isTextarea && (k === 'value' || k === 'defaultValue')) continue\n if (isInput && (k === 'defaultValue' || k === 'defaultChecked')) continue\n if (isSelect && (k === 'value' || k === 'defaultValue')) continue\n if (isOption && k === 'selected') continue\n opts.emit(attrToHtml(k, props[k], isSvg))\n }\n if (inputValueAttr !== undefined) {\n opts.emit(attrToHtml('value', inputValueAttr, isSvg))\n }\n if (inputCheckedAttr !== undefined) {\n opts.emit(attrToHtml('checked', inputCheckedAttr, isSvg))\n }\n if (isOption) {\n const selectVal = currentSelectValue()\n if (selectVal !== undefined) {\n const optionValue =\n props.value != null ? props.value : optionChildText(props.children)\n const matches = Array.isArray(selectVal)\n ? selectVal.some((v) => '' + v === '' + optionValue)\n : '' + selectVal === '' + optionValue\n if (matches) opts.emit(' selected=\"\"')\n } else if (props.selected) {\n opts.emit(' selected=\"\"')\n }\n }\n\n if (VOID_ELEMENTS.has(tag)) {\n opts.emit('/>')\n if (opts.textState) opts.textState.lastWasText = false\n return\n }\n opts.emit('>')\n if (tag === 'head') opts.onHead?.()\n // Opening a host element starts a fresh text flow context for its children.\n // Children's text separator tracking is independent of the outer context.\n const parentTextState = opts.textState\n const childOpts: WalkOptions = {\n ...opts,\n isSvg: isSvg && tag !== 'foreignObject',\n textState: { lastWasText: false },\n }\n\n if (tag === 'html' && !hasHeadChild(props.children)) {\n opts.emit('<head>')\n opts.onHead?.()\n opts.emit('</head>')\n }\n\n const dangerouslyHtml = props.dangerouslySetInnerHTML?.__html\n\n if (isTextarea && textareaValue != null) {\n opts.emit(escapeText(String(textareaValue)))\n opts.emit(`</${tag}>`)\n if (parentTextState) parentTextState.lastWasText = false\n return\n }\n\n if (RAW_TEXT_ELEMENTS.has(tag)) {\n // script/style: raw-text. React allows either a string/number child or\n // dangerouslySetInnerHTML \u2014 some libs (Start's Scripts) use the latter.\n if (dangerouslyHtml != null) {\n opts.emit(escapeScript(String(dangerouslyHtml)))\n } else {\n const children = props.children\n if (typeof children === 'string' || typeof children === 'number') {\n opts.emit(escapeScript(String(children)))\n } else if (Array.isArray(children)) {\n opts.emit(escapeScript(children.filter((c) => c != null).join('')))\n }\n }\n opts.emit(`</${tag}>`)\n if (parentTextState) parentTextState.lastWasText = false\n return\n }\n\n if (dangerouslyHtml != null) {\n opts.emit(String(dangerouslyHtml))\n } else {\n walkNode(props.children, childOpts)\n }\n opts.emit(`</${tag}>`)\n // Host element closing resets outer flow \u2014 next sibling text starts fresh.\n if (parentTextState) parentTextState.lastWasText = false\n } finally {\n if (isSelect) popSelectContext()\n }\n}\n\nfunction hasHeadChild(children: unknown): boolean {\n if (children == null || typeof children === 'boolean') return false\n if (Array.isArray(children)) return children.some(hasHeadChild)\n if (typeof children !== 'string' && isIterable(children)) {\n for (const child of children as Iterable<unknown>) {\n if (hasHeadChild(child)) return true\n }\n return false\n }\n return isElementOfType(children, 'head')\n}\n\nfunction isElementOfType(value: unknown, type: string): value is ReactElement {\n const marker = (value as ReactElement | null)?.$$typeof as unknown\n return (\n !!value &&\n typeof value === 'object' &&\n (marker === REACT_ELEMENT_TYPE || marker === REACT_LEGACY_ELEMENT_TYPE) &&\n (value as ReactElement).type === type\n )\n}\n\nfunction isIterable(value: unknown): value is Iterable<unknown> {\n return !!value && typeof (value as { [Symbol.iterator]?: unknown })[Symbol.iterator] === 'function'\n}\n\nfunction walkComponent(\n fn: Function,\n props: Record<string, any>,\n opts: WalkOptions,\n ref?: unknown,\n): void {\n if (opts.onBrowserBailout) {\n opts = { ...opts, componentStack: `\\n at ${(fn as any).displayName || fn.name || 'Anonymous'}${opts.componentStack || ''}` }\n }\n try {\n if ((fn as any).prototype?.isReactComponent) {\n const ctxType = (fn as any).contextType\n const ctxValue = ctxType ? ctxType._currentValue : undefined\n const instance = new (fn as any)(props, ctxValue)\n instance.props = props\n instance.context = ctxValue\n if ((fn as any).getDerivedStateFromProps) {\n const d = (fn as any).getDerivedStateFromProps(props, instance.state)\n if (d) instance.state = { ...instance.state, ...d }\n }\n walkNode(instance.render(), opts)\n return\n }\n const rendered = (fn as any)(props, ref)\n walkNode(rendered, opts)\n } catch (error) {\n if (opts.thrownInfo && !opts.thrownInfo.componentStack) opts.thrownInfo.componentStack = opts.componentStack\n if (isBrowserError(error) && !(error as any).componentStack) {\n Object.defineProperty(error, 'componentStack', { value: opts.componentStack })\n }\n throw error\n }\n}\n\nfunction walkSuspense(\n props: Record<string, any>,\n opts: WalkOptions,\n): void {\n const id = opts.nextBoundaryId()\n // Snapshot contexts BEFORE attempting children, so if a descendant suspends\n // we can replay the same provider stack when re-rendering the boundary.\n const contextSnapshot = snapshotContexts()\n\n // Try to render the children synchronously. If a thenable is thrown,\n // record the boundary and emit the fallback.\n const childParts: string[] = []\n const nested: SuspendedBoundary[] = []\n const thrownInfo: { componentStack?: string | undefined } = {}\n const childEmit = (s: string) => childParts.push(s)\n const resourceScope: ResourceScope | undefined = currentSSRFrame().shellFlushed ? {} : undefined\n try {\n walkNode(props.children, {\n ...opts,\n resourceScope,\n thrownInfo,\n emit: childEmit,\n onSuspend: opts.onSuspend ? (boundary) => nested.push(boundary) : undefined,\n nextBoundaryId: opts.nextBoundaryId,\n })\n } catch (thenable: any) {\n nested.length = 0\n if (isThenable(thenable) || isBrowserError(thenable)) {\n const fallbackParts: string[] = []\n walkNode(props.fallback, {\n ...opts,\n emit: (s) => fallbackParts.push(s),\n onSuspend: opts.onSuspend ? (boundary) => nested.push(boundary) : undefined,\n nextBoundaryId: opts.nextBoundaryId,\n })\n if (isBrowserError(thenable)) {\n opts.onBrowserBailout?.(thenable, { componentStack: (thenable as any).componentStack || opts.componentStack || '' })\n opts.emit(`<!--$!${id}-->${fallbackParts.join('')}<!--/$-->`)\n for (const boundary of nested) opts.onSuspend?.(boundary)\n return\n }\n emitBoundary(opts, id, fallbackParts.join(''))\n for (const boundary of nested) opts.onSuspend?.(boundary)\n\n if (opts.onSuspend) {\n opts.onSuspend({\n id,\n fallbackHTML: fallbackParts.join(''),\n children: props.children,\n thenable,\n contextSnapshot,\n componentStack: thrownInfo.componentStack || opts.componentStack || '',\n })\n }\n return\n }\n throw thenable\n }\n\n if (resourceScope) currentSSRFrame().resources?.mergeScope(resourceScope, opts.resourceScope)\n\n // Children rendered fully \u2014 emit them wrapped in resolved-boundary markers\n // (`<!--$N-->` / `<!--/$-->`). Without markers, the client hydrator has no\n // way to know this subtree is inside a Suspense, so if the client version\n // of a descendant (e.g. `React.lazy`) suspends it can't pinpoint which DOM\n // range to adopt on resolve \u2014 it creates fresh DOM next to the SSR content,\n // producing visible duplicates (e.g. double navbar logos). Markers let the\n // client treat this as a resolved boundary and hydrate in-place.\n opts.emit(`<!--$${id}-->`)\n opts.emit(childParts.join(''))\n opts.emit(`<!--/$-->`)\n for (const boundary of nested) opts.onSuspend?.(boundary)\n}\n\nfunction emitBoundary(opts: WalkOptions, id: number, fallbackHTML: string): void {\n // Visible div wrapper so the fallback UI shows; B: id lets $RC locate it on\n // reveal. The leading/trailing comments let hydration detect a pending\n // boundary and register a reveal callback.\n opts.emit(`<!--$?${id}--><div id=\"B:${id}\">`)\n opts.emit(fallbackHTML)\n opts.emit(`</div><!--/$-->`)\n}\n\nfunction isThenable(x: any): x is Promise<any> {\n return x != null && typeof x.then === 'function'\n}\n"],
|
|
5
|
+
"mappings": ";AAAA;AAAA,EACE;AAAA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K;AAAA,MACvB,CAAC;AACH,UAAI,eAAe,QAAQ,GAAG;AAC5B,aAAK,mBAAmB,UAAU,EAAE,gBAAiB,SAAiB,kBAAkB,KAAK,kBAAkB,GAAG,CAAC;AACnH,aAAK,KAAK,SAAS,EAAE,MAAM,cAAc,KAAK,EAAE,CAAC,WAAW;AAC5D,mBAAW,YAAY,OAAQ,MAAK,YAAY,QAAQ;AACxD;AAAA,MACF;AACA,mBAAa,MAAM,IAAI,cAAc,KAAK,EAAE,CAAC;AAC7C,iBAAW,YAAY,OAAQ,MAAK,YAAY,QAAQ;AAExD,UAAI,KAAK,WAAW;AAClB,aAAK,UAAU;AAAA,UACb;AAAA,UACA,cAAc,cAAc,KAAK,EAAE;AAAA,UACnC,UAAU,MAAM;AAAA,UAChB;AAAA,UACA;AAAA,UACA,gBAAgB,WAAW,kBAAkB,KAAK,kBAAkB;AAAA,QACtE,CAAC;AAAA,MACH;AACA;AAAA,IACF;AACA,UAAM;AAAA,EACR;AAEA,MAAI,cAAe,iBAAgB,EAAE,WAAW,WAAW,eAAe,KAAK,aAAa;AAS5F,OAAK,KAAK,QAAQ,EAAE,KAAK;AACzB,OAAK,KAAK,WAAW,KAAK,EAAE,CAAC;AAC7B,OAAK,KAAK,WAAW;AACrB,aAAW,YAAY,OAAQ,MAAK,YAAY,QAAQ;AAC1D;AAEA,SAAS,aAAa,MAAmB,IAAY,cAA4B;AAI/E,OAAK,KAAK,SAAS,EAAE,iBAAiB,EAAE,IAAI;AAC5C,OAAK,KAAK,YAAY;AACtB,OAAK,KAAK,iBAAiB;AAC7B;AAEA,SAAS,WAAW,GAA2B;AAC7C,SAAO,KAAK,QAAQ,OAAO,EAAE,SAAS;AACxC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/vite/index.d.ts
CHANGED
|
@@ -7,6 +7,12 @@ export type RedactPreset = 'nano' | 'full';
|
|
|
7
7
|
* configs as autocompleted options.
|
|
8
8
|
*/
|
|
9
9
|
export interface RedactFeatures {
|
|
10
|
+
/** Activity visibility, retained state and disconnected effects. */
|
|
11
|
+
activity?: boolean;
|
|
12
|
+
/** DOM instances, events, focus, layout and observers for Fragment refs. */
|
|
13
|
+
fragmentRefs?: boolean;
|
|
14
|
+
/** Experimental native ViewTransition animations. Opt-in until snapshot parity is complete. */
|
|
15
|
+
viewTransitions?: boolean;
|
|
10
16
|
/**
|
|
11
17
|
* `createPortal`. When `false`, portal elements render in place as a
|
|
12
18
|
* Fragment (the `container` prop is ignored). `renderPortal` and its
|
package/dist/vite/index.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
//
|
|
1
|
+
// src/vite/index.ts
|
|
2
2
|
import { existsSync, readFileSync, realpathSync } from "node:fs";
|
|
3
3
|
import { dirname, resolve as resolvePath } from "node:path";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
|
5
5
|
var PRESET_DEFAULTS = {
|
|
6
6
|
// Opt-in: everything off. Turn individual features on via `features`.
|
|
7
7
|
nano: {
|
|
8
|
+
activity: false,
|
|
9
|
+
fragmentRefs: false,
|
|
10
|
+
viewTransitions: false,
|
|
8
11
|
portal: false,
|
|
9
12
|
context: false,
|
|
10
13
|
suspense: false,
|
|
@@ -16,6 +19,9 @@ var PRESET_DEFAULTS = {
|
|
|
16
19
|
},
|
|
17
20
|
// Opt-out: everything on (drop-in React parity). Turn features off via `features`.
|
|
18
21
|
full: {
|
|
22
|
+
activity: true,
|
|
23
|
+
fragmentRefs: true,
|
|
24
|
+
viewTransitions: false,
|
|
19
25
|
portal: true,
|
|
20
26
|
context: true,
|
|
21
27
|
suspense: true,
|
|
@@ -29,6 +35,9 @@ var PRESET_DEFAULTS = {
|
|
|
29
35
|
function resolveFeatures(preset, overrides) {
|
|
30
36
|
const p = PRESET_DEFAULTS[preset];
|
|
31
37
|
return {
|
|
38
|
+
activity: overrides.activity ?? p.activity,
|
|
39
|
+
fragmentRefs: overrides.fragmentRefs ?? p.fragmentRefs,
|
|
40
|
+
viewTransitions: overrides.viewTransitions ?? p.viewTransitions,
|
|
32
41
|
portal: overrides.portal ?? p.portal,
|
|
33
42
|
context: overrides.context ?? p.context,
|
|
34
43
|
suspense: overrides.suspense ?? p.suspense,
|
|
@@ -52,7 +61,10 @@ var ALIASES = {
|
|
|
52
61
|
"react/jsx-dev-runtime": "@tanstack/redact/jsx-dev-runtime",
|
|
53
62
|
"react/compiler-runtime": "@tanstack/redact/compiler-runtime",
|
|
54
63
|
"react-dom/client": "@tanstack/redact/dom-client",
|
|
64
|
+
"react-dom/server.browser": "@tanstack/redact/server",
|
|
65
|
+
"react-dom/server.bun": "@tanstack/redact/server",
|
|
55
66
|
"react-dom/server.edge": "@tanstack/redact/server",
|
|
67
|
+
"react-dom/server.node": "@tanstack/redact/server",
|
|
56
68
|
"react-dom/static.edge": "@tanstack/redact/server",
|
|
57
69
|
"react-dom/server": "@tanstack/redact/server",
|
|
58
70
|
"react-dom/test-utils": "@tanstack/redact/dom-test-utils",
|
|
@@ -196,11 +208,12 @@ function redact(options = {}) {
|
|
|
196
208
|
const envName = this?.environment?.name;
|
|
197
209
|
if (envName === "rsc") return null;
|
|
198
210
|
if (importer && /[\\/]features[\\/]index\.[jt]sx?$/.test(importer)) {
|
|
199
|
-
const m = id.match(/^\.\/([a-z-]+)
|
|
211
|
+
const m = id.match(/^\.\/([a-z-]+)(\/index\.js)?$/);
|
|
200
212
|
if (m) {
|
|
201
|
-
const
|
|
213
|
+
const dir = m[1];
|
|
214
|
+
const name = dir === "forward-ref" ? "forwardRef" : dir === "fragment-refs" ? "fragmentRefs" : dir === "view-transition" ? "viewTransitions" : dir === "class" ? "classComponents" : dir;
|
|
202
215
|
if (name in features && !features[name]) {
|
|
203
|
-
const r = await this.resolve(`./${
|
|
216
|
+
const r = await this.resolve(`./${dir}/stub${m[2] ? ".js" : ""}`, importer, {
|
|
204
217
|
...opts,
|
|
205
218
|
skipSelf: true
|
|
206
219
|
});
|
|
@@ -208,9 +221,12 @@ function redact(options = {}) {
|
|
|
208
221
|
}
|
|
209
222
|
}
|
|
210
223
|
}
|
|
211
|
-
|
|
224
|
+
const peer = id.match(/[\\/](context|hydration|fragment-refs|view-transition)(?:[\\/]index\.js)?$/);
|
|
225
|
+
const peerKey = peer?.[1] === "fragment-refs" ? "fragmentRefs" : peer?.[1] === "view-transition" ? "viewTransitions" : peer?.[1];
|
|
226
|
+
if (importer && peer && peerKey && !features[peerKey]) {
|
|
212
227
|
const r = await this.resolve(id, importer, { ...opts, skipSelf: true });
|
|
213
|
-
|
|
228
|
+
const resolvedFeature = r?.id.match(/features[\\/](context|hydration|fragment-refs|view-transition)[\\/]index\.(ts|js)$/);
|
|
229
|
+
if (resolvedFeature?.[1] === peer[1]) {
|
|
214
230
|
return r.id.replace(/index\.(ts|js)$/, "stub.$1");
|
|
215
231
|
}
|
|
216
232
|
}
|