@tanstack/redact 0.0.21 → 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 -27
- 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 -77
- 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 +197 -52
- 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 +689 -221
- 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 -28
- 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 -85
- 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 +192 -55
- 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 +695 -242
- 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
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
export
|
|
1
|
+
import { createResourceHints, type ResourceScope } from "./resource-hints.js";
|
|
2
|
+
export interface SSRFrame {
|
|
3
|
+
idCounter: number;
|
|
4
|
+
identifierPrefix: string;
|
|
5
|
+
contextStack: Array<{
|
|
6
|
+
context: any;
|
|
7
|
+
prev: any;
|
|
8
|
+
}>;
|
|
9
|
+
resources?: ReturnType<typeof createResourceHints>;
|
|
10
|
+
shellFlushed?: boolean;
|
|
11
|
+
styleNonce?: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
export declare function beginSSR(identifierPrefix?: string, nextFrame?: SSRFrame): {
|
|
14
|
+
frame: SSRFrame;
|
|
15
|
+
dispatcher: import("../react/shared-internals.js").Dispatcher;
|
|
16
|
+
};
|
|
17
|
+
export declare function currentSSRFrame(): SSRFrame;
|
|
18
|
+
export declare function recordHostResource(type: string, props: any, scope?: ResourceScope): boolean;
|
|
19
|
+
export declare function endSSR(previous?: ReturnType<typeof beginSSR>): void;
|
|
3
20
|
export declare function pushContext(context: any, value: any): void;
|
|
4
21
|
export declare function popContext(context: any): void;
|
|
5
22
|
export type ContextSnapshot = Array<{
|
|
@@ -14,7 +31,11 @@ export declare function snapshotContexts(): ContextSnapshot;
|
|
|
14
31
|
*/
|
|
15
32
|
export declare function applyContextSnapshot(snapshot: ContextSnapshot): () => void;
|
|
16
33
|
export declare const ssrDispatcher: {
|
|
17
|
-
|
|
34
|
+
useCacheRefresh(): () => never;
|
|
35
|
+
useState<S>(initial: S | (() => S)): [
|
|
36
|
+
S,
|
|
37
|
+
any
|
|
38
|
+
];
|
|
18
39
|
useReducer<S, A>(_reducer: (s: S, a: A) => S, initialArg: any, init?: (a: any) => S): any[];
|
|
19
40
|
useEffect(): void;
|
|
20
41
|
useLayoutEffect(): void;
|
|
@@ -28,10 +49,11 @@ export declare const ssrDispatcher: {
|
|
|
28
49
|
useImperativeHandle(): void;
|
|
29
50
|
useDebugValue(): void;
|
|
30
51
|
useId(): string;
|
|
31
|
-
useTransition(): [
|
|
52
|
+
useTransition(): [
|
|
53
|
+
boolean,
|
|
54
|
+
(fn: () => void) => void
|
|
55
|
+
];
|
|
32
56
|
useDeferredValue<T>(v: T): T;
|
|
33
57
|
useSyncExternalStore<T>(_subscribe: (cb: () => void) => () => void, getSnapshot: () => T, getServerSnapshot?: () => T): T;
|
|
34
58
|
use<T>(resource: any): T;
|
|
35
59
|
};
|
|
36
|
-
export declare function installSSRDispatcher(): void;
|
|
37
|
-
export declare function uninstallSSRDispatcher(): void;
|
|
@@ -1,17 +1,35 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { ReactSharedInternals, REACT_CONTEXT_TYPE } from "../react";
|
|
1
|
+
// src/server/dispatcher.ts
|
|
2
|
+
import { ReactSharedInternals, REACT_CONTEXT_TYPE } from "../react/index.js";
|
|
3
|
+
import { isBrowserToken, browserError } from "../core/browser.js";
|
|
4
|
+
import { resourceHintDispatcher } from "../core/resource-hints.js";
|
|
5
|
+
import { createResourceHints } from "./resource-hints.js";
|
|
3
6
|
var frame = null;
|
|
4
|
-
|
|
5
|
-
frame
|
|
7
|
+
resourceHintDispatcher.emit = (kind, href, options) => {
|
|
8
|
+
if (!frame) return false;
|
|
9
|
+
(frame.resources ||= createResourceHints(!!frame.shellFlushed, frame.styleNonce)).add(kind, href, options);
|
|
10
|
+
return true;
|
|
11
|
+
};
|
|
12
|
+
function beginSSR(identifierPrefix = ":R", nextFrame) {
|
|
13
|
+
const previous = { frame, dispatcher: ReactSharedInternals.H };
|
|
14
|
+
frame = nextFrame ?? { idCounter: 0, identifierPrefix, contextStack: [] };
|
|
15
|
+
ReactSharedInternals.H = ssrDispatcher;
|
|
16
|
+
return previous;
|
|
17
|
+
}
|
|
18
|
+
function currentSSRFrame() {
|
|
19
|
+
return frame;
|
|
20
|
+
}
|
|
21
|
+
function recordHostResource(type, props, scope) {
|
|
22
|
+
return !!frame && (frame.resources ||= createResourceHints(!!frame.shellFlushed, frame.styleNonce)).addHost(type, props, scope);
|
|
6
23
|
}
|
|
7
|
-
function endSSR() {
|
|
24
|
+
function endSSR(previous) {
|
|
8
25
|
if (frame) {
|
|
9
26
|
for (let i = frame.contextStack.length - 1; i >= 0; i--) {
|
|
10
27
|
const { context, prev } = frame.contextStack[i];
|
|
11
28
|
context._currentValue = prev;
|
|
12
29
|
}
|
|
13
30
|
}
|
|
14
|
-
|
|
31
|
+
ReactSharedInternals.H = previous?.dispatcher ?? null;
|
|
32
|
+
frame = previous?.frame ?? null;
|
|
15
33
|
}
|
|
16
34
|
function pushContext(context, value) {
|
|
17
35
|
if (!frame) throw new Error("pushContext called outside SSR");
|
|
@@ -38,6 +56,11 @@ function applyContextSnapshot(snapshot) {
|
|
|
38
56
|
};
|
|
39
57
|
}
|
|
40
58
|
var ssrDispatcher = {
|
|
59
|
+
useCacheRefresh() {
|
|
60
|
+
return () => {
|
|
61
|
+
throw new Error("Refreshing the cache is not supported during server rendering.");
|
|
62
|
+
};
|
|
63
|
+
},
|
|
41
64
|
useState(initial) {
|
|
42
65
|
const v = typeof initial === "function" ? initial() : initial;
|
|
43
66
|
return [v, (() => {
|
|
@@ -85,6 +108,7 @@ var ssrDispatcher = {
|
|
|
85
108
|
},
|
|
86
109
|
use(resource) {
|
|
87
110
|
if (resource == null) throw new Error("use() received null or undefined");
|
|
111
|
+
if (isBrowserToken(resource)) throw browserError(resource);
|
|
88
112
|
if (resource.$$typeof === REACT_CONTEXT_TYPE) {
|
|
89
113
|
return resource._currentValue;
|
|
90
114
|
}
|
|
@@ -120,21 +144,15 @@ var ssrDispatcher = {
|
|
|
120
144
|
throw new Error("use() expected a Promise or Context");
|
|
121
145
|
}
|
|
122
146
|
};
|
|
123
|
-
function installSSRDispatcher() {
|
|
124
|
-
ReactSharedInternals.H = ssrDispatcher;
|
|
125
|
-
}
|
|
126
|
-
function uninstallSSRDispatcher() {
|
|
127
|
-
ReactSharedInternals.H = null;
|
|
128
|
-
}
|
|
129
147
|
export {
|
|
130
148
|
applyContextSnapshot,
|
|
131
149
|
beginSSR,
|
|
150
|
+
currentSSRFrame,
|
|
132
151
|
endSSR,
|
|
133
|
-
installSSRDispatcher,
|
|
134
152
|
popContext,
|
|
135
153
|
pushContext,
|
|
154
|
+
recordHostResource,
|
|
136
155
|
snapshotContexts,
|
|
137
|
-
ssrDispatcher
|
|
138
|
-
uninstallSSRDispatcher
|
|
156
|
+
ssrDispatcher
|
|
139
157
|
};
|
|
140
158
|
//# sourceMappingURL=dispatcher.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/server/dispatcher.ts"],
|
|
4
|
-
"sourcesContent": ["import { ReactSharedInternals, REACT_CONTEXT_TYPE } from '../react'\n\
|
|
5
|
-
"mappings": ";AAAA,SAAS,sBAAsB,0BAA0B;
|
|
4
|
+
"sourcesContent": ["import { ReactSharedInternals, REACT_CONTEXT_TYPE } from '../react'\nimport { isBrowserToken, browserError } from '../core/browser'\nimport { resourceHintDispatcher } from '../core/resource-hints'\nimport { createResourceHints, type ResourceScope } from './resource-hints'\n\nexport interface SSRFrame {\n idCounter: number\n identifierPrefix: string\n contextStack: Array<{ context: any; prev: any }>\n resources?: ReturnType<typeof createResourceHints>\n shellFlushed?: boolean\n styleNonce?: string | undefined\n}\n\nlet frame: SSRFrame | null = null\n\nresourceHintDispatcher.emit = (kind, href, options) => {\n if (!frame) return false\n ;(frame.resources ||= createResourceHints(!!frame.shellFlushed, frame.styleNonce)).add(kind, href, options)\n return true\n}\n\nexport function beginSSR(identifierPrefix = ':R', nextFrame?: SSRFrame) {\n const previous = { frame, dispatcher: ReactSharedInternals.H }\n frame = nextFrame ?? { idCounter: 0, identifierPrefix, contextStack: [] }\n ReactSharedInternals.H = ssrDispatcher as any\n return previous\n}\n\nexport function currentSSRFrame(): SSRFrame {\n return frame!\n}\n\nexport function recordHostResource(type: string, props: any, scope?: ResourceScope): boolean {\n return !!frame && (frame.resources ||= createResourceHints(!!frame.shellFlushed, frame.styleNonce)).addHost(type, props, scope)\n}\n\nexport function endSSR(previous?: ReturnType<typeof beginSSR>): void {\n // Restore any remaining pushed contexts (defensive)\n if (frame) {\n for (let i = frame.contextStack.length - 1; i >= 0; i--) {\n const { context, prev } = frame.contextStack[i]!\n context._currentValue = prev\n }\n }\n // Only synchronous renders restore their caller. A stream can finish\n // after its caller has returned, so it must not reinstall that dispatcher.\n ReactSharedInternals.H = previous?.dispatcher ?? null\n frame = previous?.frame ?? null\n}\n\nexport function pushContext(context: any, value: any): void {\n if (!frame) throw new Error('pushContext called outside SSR')\n frame.contextStack.push({ context, prev: context._currentValue })\n context._currentValue = value\n}\n\nexport function popContext(context: any): void {\n if (!frame) return\n const top = frame.contextStack.pop()\n if (top && top.context === context) context._currentValue = top.prev\n}\n\nexport type ContextSnapshot = Array<{ context: any; value: any }>\n\nexport function snapshotContexts(): ContextSnapshot {\n if (!frame) return []\n const out: ContextSnapshot = []\n for (const entry of frame.contextStack) {\n out.push({ context: entry.context, value: entry.context._currentValue })\n }\n return out\n}\n\n/**\n * Push snapshot values and return a function that pops them.\n * Called when we re-render a suspended boundary so it sees the same provider\n * values that were active at suspension time.\n */\nexport function applyContextSnapshot(snapshot: ContextSnapshot): () => void {\n for (const { context, value } of snapshot) pushContext(context, value)\n return () => {\n for (let i = snapshot.length - 1; i >= 0; i--) popContext(snapshot[i]!.context)\n }\n}\n\nexport const ssrDispatcher = {\n useCacheRefresh() {\n return () => { throw new Error('Refreshing the cache is not supported during server rendering.') }\n },\n useState<S>(initial: S | (() => S)) {\n const v = typeof initial === 'function' ? (initial as () => S)() : initial\n return [v, (() => {}) as any] as [S, any]\n },\n useReducer<S, A>(_reducer: (s: S, a: A) => S, initialArg: any, init?: (a: any) => S) {\n const v = init ? init(initialArg) : initialArg\n return [v, (() => {}) as any]\n },\n useEffect() {\n // noop on server\n },\n useLayoutEffect() {\n // noop on server\n },\n useInsertionEffect() {\n // noop on server\n },\n useRef<T>(initial: T) {\n return { current: initial }\n },\n useMemo<T>(factory: () => T) {\n return factory()\n },\n useCallback<T extends Function>(fn: T) {\n return fn\n },\n useContext<T>(ctx: any): T {\n return ctx._currentValue\n },\n useImperativeHandle() {\n // noop on server\n },\n useDebugValue() {\n // noop\n },\n useId(): string {\n if (!frame) return ':r0:'\n return `${frame.identifierPrefix}${(frame.idCounter++).toString(36)}`\n },\n useTransition(): [boolean, (fn: () => void) => void] {\n return [false, (fn) => fn()]\n },\n useDeferredValue<T>(v: T): T {\n return v\n },\n useSyncExternalStore<T>(\n _subscribe: (cb: () => void) => () => void,\n getSnapshot: () => T,\n getServerSnapshot?: () => T,\n ): T {\n return getServerSnapshot ? getServerSnapshot() : getSnapshot()\n },\n use<T>(resource: any): T {\n if (resource == null) throw new Error('use() received null or undefined')\n if (isBrowserToken(resource)) throw browserError(resource)\n if (resource.$$typeof === REACT_CONTEXT_TYPE) {\n return resource._currentValue\n }\n if (typeof resource.then === 'function') {\n const thenable = resource\n switch (thenable.status) {\n case 'fulfilled':\n return thenable.value\n case 'rejected':\n throw thenable.reason\n default: {\n if (thenable.status === undefined) {\n thenable.status = 'pending'\n thenable.then(\n (v: any) => {\n if (thenable.status === 'pending') {\n thenable.status = 'fulfilled'\n thenable.value = v\n }\n },\n (e: any) => {\n if (thenable.status === 'pending') {\n thenable.status = 'rejected'\n thenable.reason = e\n }\n },\n )\n }\n throw thenable\n }\n }\n }\n throw new Error('use() expected a Promise or Context')\n },\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,sBAAsB,0BAA0B;AACzD,SAAS,gBAAgB,oBAAoB;AAC7C,SAAS,8BAA8B;AACvC,SAAS,2BAA+C;AAWxD,IAAI,QAAyB;AAE7B,uBAAuB,OAAO,CAAC,MAAM,MAAM,YAAY;AACrD,MAAI,CAAC,MAAO,QAAO;AAClB,GAAC,MAAM,cAAc,oBAAoB,CAAC,CAAC,MAAM,cAAc,MAAM,UAAU,GAAG,IAAI,MAAM,MAAM,OAAO;AAC1G,SAAO;AACT;AAEO,SAAS,SAAS,mBAAmB,MAAM,WAAsB;AACtE,QAAM,WAAW,EAAE,OAAO,YAAY,qBAAqB,EAAE;AAC7D,UAAQ,aAAa,EAAE,WAAW,GAAG,kBAAkB,cAAc,CAAC,EAAE;AACxE,uBAAqB,IAAI;AACzB,SAAO;AACT;AAEO,SAAS,kBAA4B;AAC1C,SAAO;AACT;AAEO,SAAS,mBAAmB,MAAc,OAAY,OAAgC;AAC3F,SAAO,CAAC,CAAC,UAAU,MAAM,cAAc,oBAAoB,CAAC,CAAC,MAAM,cAAc,MAAM,UAAU,GAAG,QAAQ,MAAM,OAAO,KAAK;AAChI;AAEO,SAAS,OAAO,UAA8C;AAEnE,MAAI,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SAAS,WAAW,QAAW;AACjC,qBAAS,SAAS;AAClB,qBAAS;AAAA,cACP,CAAC,MAAW;AACV,oBAAI,SAAS,WAAW,WAAW;AACjC,2BAAS,SAAS;AAClB,2BAAS,QAAQ;AAAA,gBACnB;AAAA,cACF;AAAA,cACA,CAAC,MAAW;AACV,oBAAI,SAAS,WAAW,WAAW;AACjC,2BAAS,SAAS;AAClB,2BAAS,SAAS;AAAA,gBACpB;AAAA,cACF;AAAA,YACF;AAAA,UACF;AACA,gBAAM;AAAA,QACR;AAAA,MACF;AAAA,IACF;AACA,UAAM,IAAI,MAAM,qCAAqC;AAAA,EACvD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/server/escape.js
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { attributeName, STRING_BOOLEAN_ATTRS } from "../core/attributes";
|
|
3
|
-
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
1
|
+
// src/server/escape.ts
|
|
2
|
+
import { attributeName, STRING_BOOLEAN_ATTRS } from "../core/attributes.js";
|
|
3
|
+
function escape(value, pattern) {
|
|
4
|
+
let out = "";
|
|
5
|
+
let start = 0;
|
|
6
|
+
while (pattern.test(value)) {
|
|
7
|
+
const end = pattern.lastIndex;
|
|
8
|
+
const char = value[end - 1];
|
|
9
|
+
out += value.slice(start, end - 1) + (char === "&" ? "&" : char === "<" ? "<" : char === ">" ? ">" : """);
|
|
10
|
+
start = end;
|
|
11
|
+
}
|
|
12
|
+
return out + value.slice(start);
|
|
13
|
+
}
|
|
14
14
|
function escapeAttr(value) {
|
|
15
|
-
return value
|
|
15
|
+
return /[&"<>]/.test(value) ? escape(value, /[&"<>]/g) : value;
|
|
16
16
|
}
|
|
17
17
|
function escapeText(value) {
|
|
18
|
-
return value
|
|
18
|
+
return /[&<>]/.test(value) ? escape(value, /[&<>]/g) : value;
|
|
19
19
|
}
|
|
20
20
|
function escapeScript(value) {
|
|
21
21
|
return value.replace(/<\/(script|style)/gi, "<\\/$1").replace(/<!--/g, "<\\!--");
|
|
@@ -44,6 +44,7 @@ var BOOLEAN_ATTRS = /* @__PURE__ */ new Set([
|
|
|
44
44
|
"autoplay",
|
|
45
45
|
"checked",
|
|
46
46
|
"controls",
|
|
47
|
+
"credentialless",
|
|
47
48
|
"default",
|
|
48
49
|
"defer",
|
|
49
50
|
"disabled",
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/server/escape.ts"],
|
|
4
|
-
"sourcesContent": ["import { attributeName, STRING_BOOLEAN_ATTRS } from '../core/attributes'\n\
|
|
5
|
-
"mappings": ";AAAA,SAAS,eAAe,4BAA4B;AAEpD,
|
|
4
|
+
"sourcesContent": ["import { attributeName, STRING_BOOLEAN_ATTRS } from '../core/attributes'\n\nfunction escape(value: string, pattern: RegExp): string {\n let out = ''\n let start = 0\n while (pattern.test(value)) {\n const end = pattern.lastIndex\n const char = value[end - 1]\n out += value.slice(start, end - 1) + (\n char === '&' ? '&' : char === '<' ? '<' : char === '>' ? '>' : '"'\n )\n start = end\n }\n return out + value.slice(start)\n}\n\nexport function escapeAttr(value: string): string {\n return /[&\"<>]/.test(value) ? escape(value, /[&\"<>]/g) : value\n}\n\nexport function escapeText(value: string): string {\n return /[&<>]/.test(value) ? escape(value, /[&<>]/g) : value\n}\n\n// Raw-text element body escaping: prevent any closing tag for the raw-text\n// elements (<script>, <style>) from terminating the element early, plus\n// `<!--` (which would start an HTML comment that survives even inside\n// raw-text bodies and can be exploited to alter following script content).\n// React's serializer follows the same approach.\nexport function escapeScript(value: string): string {\n return value\n .replace(/<\\/(script|style)/gi, '<\\\\/$1')\n .replace(/<!--/g, '<\\\\!--')\n}\n\nexport const VOID_ELEMENTS = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'param',\n 'source',\n 'track',\n 'wbr',\n])\n\nexport const RAW_TEXT_ELEMENTS = new Set(['script', 'style'])\n\nconst BOOLEAN_ATTRS = new Set([\n 'allowfullscreen',\n 'async',\n 'autofocus',\n 'autoplay',\n 'checked',\n 'controls',\n 'credentialless',\n 'default',\n 'defer',\n 'disabled',\n 'formnovalidate',\n 'hidden',\n 'inert',\n 'ismap',\n 'itemscope',\n 'loop',\n 'multiple',\n 'muted',\n 'nomodule',\n 'novalidate',\n 'open',\n 'playsinline',\n 'readonly',\n 'required',\n 'reversed',\n 'selected',\n])\n\nexport function attrToHtml(name: string, value: unknown, isSvg = false): string {\n if (\n name === 'children' ||\n name === 'key' ||\n name === 'ref' ||\n name === 'dangerouslySetInnerHTML' ||\n name === 'defaultValue' ||\n name === 'defaultChecked' ||\n name === 'suppressHydrationWarning' ||\n name === 'suppressContentEditableWarning'\n ) {\n return ''\n }\n if (name[0] === 'o' && name[1] === 'n' && typeof value === 'function') return ''\n if (value == null) return ''\n\n const htmlName = attributeName(name, isSvg)\n\n // These attributes need explicit \"false\", not boolean-attribute absence.\n if (\n STRING_BOOLEAN_ATTRS.has(htmlName) ||\n name.startsWith('aria-') ||\n name.startsWith('data-')\n ) {\n return ` ${htmlName}=\"${escapeAttr(String(value))}\"`\n }\n\n if (value === false) return ''\n\n if (value === true || BOOLEAN_ATTRS.has(htmlName)) {\n return value ? ` ${htmlName}=\"\"` : ''\n }\n\n if (name === 'style' && typeof value === 'object' && value !== null) {\n return ` style=\"${escapeAttr(styleToString(value as Record<string, unknown>))}\"`\n }\n\n return ` ${htmlName}=\"${escapeAttr(String(value))}\"`\n}\n\nconst UNITLESS_STYLE = new Set([\n 'animationIterationCount',\n 'borderImageOutset',\n 'borderImageSlice',\n 'borderImageWidth',\n 'boxFlex',\n 'boxFlexGroup',\n 'boxOrdinalGroup',\n 'columnCount',\n 'columns',\n 'flex',\n 'flexGrow',\n 'flexPositive',\n 'flexShrink',\n 'flexNegative',\n 'flexOrder',\n 'gridArea',\n 'gridRow',\n 'gridRowEnd',\n 'gridRowSpan',\n 'gridRowStart',\n 'gridColumn',\n 'gridColumnEnd',\n 'gridColumnSpan',\n 'gridColumnStart',\n 'fontWeight',\n 'lineClamp',\n 'lineHeight',\n 'opacity',\n 'order',\n 'orphans',\n 'tabSize',\n 'widows',\n 'zIndex',\n 'zoom',\n 'fillOpacity',\n 'floodOpacity',\n 'stopOpacity',\n 'strokeDasharray',\n 'strokeDashoffset',\n 'strokeMiterlimit',\n 'strokeOpacity',\n 'strokeWidth',\n])\n\nfunction styleToString(style: Record<string, unknown>): string {\n let out = ''\n for (const key in style) {\n const v = style[key]\n if (v == null || v === false) continue\n const kebab = key.startsWith('--')\n ? key\n : key.replace(/[A-Z]/g, (m) => '-' + m.toLowerCase())\n const value =\n typeof v === 'number' && !UNITLESS_STYLE.has(key) && v !== 0 ? v + 'px' : v\n out += `${kebab}:${value};`\n }\n return out\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,eAAe,4BAA4B;AAEpD,SAAS,OAAO,OAAe,SAAyB;AACtD,MAAI,MAAM;AACV,MAAI,QAAQ;AACZ,SAAO,QAAQ,KAAK,KAAK,GAAG;AAC1B,UAAM,MAAM,QAAQ;AACpB,UAAM,OAAO,MAAM,MAAM,CAAC;AAC1B,WAAO,MAAM,MAAM,OAAO,MAAM,CAAC,KAC/B,SAAS,MAAM,UAAU,SAAS,MAAM,SAAS,SAAS,MAAM,SAAS;AAE3E,YAAQ;AAAA,EACV;AACA,SAAO,MAAM,MAAM,MAAM,KAAK;AAChC;AAEO,SAAS,WAAW,OAAuB;AAChD,SAAO,SAAS,KAAK,KAAK,IAAI,OAAO,OAAO,SAAS,IAAI;AAC3D;AAEO,SAAS,WAAW,OAAuB;AAChD,SAAO,QAAQ,KAAK,KAAK,IAAI,OAAO,OAAO,QAAQ,IAAI;AACzD;AAOO,SAAS,aAAa,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renderToString, renderToStaticMarkup } from
|
|
2
|
-
export { renderToReadableStream, renderToPipeableStream } from
|
|
3
|
-
export type { StreamOptions, PipeableOptions, PipeableHandle, ReadableStreamResult, } from
|
|
4
|
-
export { BOUNDARY_REVEAL_RUNTIME } from
|
|
1
|
+
export { renderToString, renderToStaticMarkup } from "./renderToString.js";
|
|
2
|
+
export { renderToReadableStream, renderToPipeableStream } from "./stream.js";
|
|
3
|
+
export type { StreamOptions, PipeableOptions, PipeableHandle, ReadableStreamResult, } from "./stream.js";
|
|
4
|
+
export { BOUNDARY_REVEAL_RUNTIME } from "./bootstrap-script.js";
|
|
5
5
|
export declare const version = "19.2.3";
|
|
6
|
-
import { renderToString, renderToStaticMarkup } from
|
|
7
|
-
import { renderToReadableStream, renderToPipeableStream } from
|
|
6
|
+
import { renderToString, renderToStaticMarkup } from "./renderToString.js";
|
|
7
|
+
import { renderToReadableStream, renderToPipeableStream } from "./stream.js";
|
|
8
8
|
declare const _default: {
|
|
9
9
|
renderToString: typeof renderToString;
|
|
10
10
|
renderToStaticMarkup: typeof renderToStaticMarkup;
|
package/dist/server/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { renderToString, renderToStaticMarkup } from "./renderToString";
|
|
3
|
-
import { renderToReadableStream, renderToPipeableStream } from "./stream";
|
|
4
|
-
import { BOUNDARY_REVEAL_RUNTIME } from "./bootstrap-script";
|
|
5
|
-
import { renderToString as renderToString2, renderToStaticMarkup as renderToStaticMarkup2 } from "./renderToString";
|
|
6
|
-
import { renderToReadableStream as renderToReadableStream2, renderToPipeableStream as renderToPipeableStream2 } from "./stream";
|
|
7
|
-
import { BOUNDARY_REVEAL_RUNTIME as BOUNDARY_REVEAL_RUNTIME2 } from "./bootstrap-script";
|
|
1
|
+
// src/server/index.ts
|
|
2
|
+
import { renderToString, renderToStaticMarkup } from "./renderToString.js";
|
|
3
|
+
import { renderToReadableStream, renderToPipeableStream } from "./stream.js";
|
|
4
|
+
import { BOUNDARY_REVEAL_RUNTIME } from "./bootstrap-script.js";
|
|
5
|
+
import { renderToString as renderToString2, renderToStaticMarkup as renderToStaticMarkup2 } from "./renderToString.js";
|
|
6
|
+
import { renderToReadableStream as renderToReadableStream2, renderToPipeableStream as renderToPipeableStream2 } from "./stream.js";
|
|
7
|
+
import { BOUNDARY_REVEAL_RUNTIME as BOUNDARY_REVEAL_RUNTIME2 } from "./bootstrap-script.js";
|
|
8
8
|
var version = "19.2.3";
|
|
9
9
|
var server_default = {
|
|
10
10
|
renderToString: renderToString2,
|
|
@@ -1,21 +1,25 @@
|
|
|
1
|
-
//
|
|
2
|
-
import { beginSSR,
|
|
3
|
-
import { walk } from "./walk";
|
|
1
|
+
// src/server/renderToString.ts
|
|
2
|
+
import { beginSSR, currentSSRFrame, endSSR } from "./dispatcher.js";
|
|
3
|
+
import { walk } from "./walk.js";
|
|
4
4
|
function renderToString(children, options = {}) {
|
|
5
|
-
|
|
6
|
-
beginSSR(options.identifierPrefix);
|
|
5
|
+
const previous = beginSSR(options.identifierPrefix);
|
|
7
6
|
let output = "";
|
|
8
7
|
let id = 0;
|
|
8
|
+
let head = 0;
|
|
9
9
|
try {
|
|
10
10
|
walk(children, {
|
|
11
11
|
emit: (s) => {
|
|
12
12
|
output += s;
|
|
13
13
|
},
|
|
14
|
-
nextBoundaryId: () => id
|
|
14
|
+
nextBoundaryId: () => id++,
|
|
15
|
+
onHead: () => {
|
|
16
|
+
head = output.length;
|
|
17
|
+
}
|
|
15
18
|
});
|
|
19
|
+
const hints = currentSSRFrame().resources?.drain();
|
|
20
|
+
if (hints) output = output.slice(0, head) + hints + output.slice(head);
|
|
16
21
|
} finally {
|
|
17
|
-
endSSR();
|
|
18
|
-
uninstallSSRDispatcher();
|
|
22
|
+
endSSR(previous);
|
|
19
23
|
}
|
|
20
24
|
return output;
|
|
21
25
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/server/renderToString.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ReactNode } from '../core'\nimport { beginSSR,
|
|
5
|
-
"mappings": ";AACA,SAAS,UAAU,
|
|
4
|
+
"sourcesContent": ["import type { ReactNode } from '../core'\nimport { beginSSR, currentSSRFrame, endSSR } from './dispatcher'\nimport { walk } from './walk'\n\nexport function renderToString(\n children: ReactNode,\n options: { identifierPrefix?: string } = {},\n): string {\n const previous = beginSSR(options.identifierPrefix)\n let output = ''\n let id = 0\n let head = 0\n try {\n walk(children, {\n emit: (s) => {\n output += s\n },\n nextBoundaryId: () => id++,\n onHead: () => { head = output.length },\n })\n const hints = currentSSRFrame().resources?.drain()\n if (hints) output = output.slice(0, head) + hints + output.slice(head)\n } finally {\n endSSR(previous)\n }\n return output\n}\n\nexport function renderToStaticMarkup(\n children: ReactNode,\n options: { identifierPrefix?: string } = {},\n): string {\n // For our purposes identical to renderToString (no hydration markers in static output)\n return renderToString(children, options).replace(/<!--[^>]*-->/g, '')\n}\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,UAAU,iBAAiB,cAAc;AAClD,SAAS,YAAY;AAEd,SAAS,eACd,UACA,UAAyC,CAAC,GAClC;AACR,QAAM,WAAW,SAAS,QAAQ,gBAAgB;AAClD,MAAI,SAAS;AACb,MAAI,KAAK;AACT,MAAI,OAAO;AACX,MAAI;AACF,SAAK,UAAU;AAAA,MACb,MAAM,CAAC,MAAM;AACX,kBAAU;AAAA,MACZ;AAAA,MACA,gBAAgB,MAAM;AAAA,MACtB,QAAQ,MAAM;AAAE,eAAO,OAAO;AAAA,MAAO;AAAA,IACvC,CAAC;AACD,UAAM,QAAQ,gBAAgB,EAAE,WAAW,MAAM;AACjD,QAAI,MAAO,UAAS,OAAO,MAAM,GAAG,IAAI,IAAI,QAAQ,OAAO,MAAM,IAAI;AAAA,EACvE,UAAE;AACA,WAAO,QAAQ;AAAA,EACjB;AACA,SAAO;AACT;AAEO,SAAS,qBACd,UACA,UAAyC,CAAC,GAClC;AAER,SAAO,eAAe,UAAU,OAAO,EAAE,QAAQ,iBAAiB,EAAE;AACtE;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ResourceHintKind, type ResourceHintOptions } from "../core/resource-hints.js";
|
|
2
|
+
interface Resource {
|
|
3
|
+
kind: ResourceHintKind | 'style';
|
|
4
|
+
href: string;
|
|
5
|
+
options: Record<string, any>;
|
|
6
|
+
sent?: boolean;
|
|
7
|
+
cancelled?: boolean;
|
|
8
|
+
preloaded?: boolean;
|
|
9
|
+
css?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface ResourceScope {
|
|
12
|
+
stylesheets?: Map<string, string[]>;
|
|
13
|
+
inline?: Set<string>;
|
|
14
|
+
}
|
|
15
|
+
export declare function createResourceHints(shellFlushed?: boolean, styleNonce?: string): {
|
|
16
|
+
add(kind: ResourceHintKind | "style", href: string, options: ResourceHintOptions): Resource;
|
|
17
|
+
addHost(type: string, props: any, scope?: ResourceScope): boolean;
|
|
18
|
+
mergeScope(scope: ResourceScope, parent?: ResourceScope): void;
|
|
19
|
+
takeStylesheets(): string[][];
|
|
20
|
+
drain(): string;
|
|
21
|
+
};
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
// src/server/resource-hints.ts
|
|
2
|
+
import { resourceKind, resourceURL } from "../core/resource-hints.js";
|
|
3
|
+
import { attrToHtml, escapeAttr } from "./escape.js";
|
|
4
|
+
import { attributeName } from "../core/attributes.js";
|
|
5
|
+
function styleText(props) {
|
|
6
|
+
const html = props.dangerouslySetInnerHTML;
|
|
7
|
+
if (html != null) {
|
|
8
|
+
if (typeof html !== "object" || !("__html" in html)) throw new Error("dangerouslySetInnerHTML must be an object with an __html field.");
|
|
9
|
+
if (props.children != null) throw new Error("Can only set one of children or dangerouslySetInnerHTML.");
|
|
10
|
+
return html.__html == null ? "" : "" + html.__html;
|
|
11
|
+
}
|
|
12
|
+
const child = Array.isArray(props.children) ? props.children.length < 2 ? props.children[0] : null : props.children;
|
|
13
|
+
return child == null || typeof child === "function" || typeof child === "symbol" ? "" : ("" + child).replace(/(<\/?)(s)(tyle)/gi, (_, prefix, s, suffix) => prefix + "\\" + s.charCodeAt(0).toString(16) + " " + suffix);
|
|
14
|
+
}
|
|
15
|
+
function markup(resource, late) {
|
|
16
|
+
const { kind, href, options } = resource;
|
|
17
|
+
const script = kind === "script" || kind === "module-script";
|
|
18
|
+
const style = kind === "stylesheet";
|
|
19
|
+
const props = script ? { src: href, ...kind === "module-script" ? { type: "module" } : {}, async: true, ...options } : style ? late ? { rel: "preload", as: "style", href, crossOrigin: options.crossOrigin, fetchPriority: options.fetchPriority, integrity: options.integrity, media: options.media, hrefLang: options.hrefLang, referrerPolicy: options.referrerPolicy } : { rel: "stylesheet", href, "data-precedence": options.precedence, ...options } : { rel: kind, ...options.as === "image" && options.imageSrcSet ? {} : { href }, ...options };
|
|
20
|
+
let output = script ? "<script" : "<link";
|
|
21
|
+
for (const name in props) {
|
|
22
|
+
if (name === "precedence" || late && name === "data-precedence") continue;
|
|
23
|
+
const value = name === "href" || name === "src" ? resourceURL(props[name]) : props[name];
|
|
24
|
+
output += attrToHtml(name, value).replace(/'/g, "'");
|
|
25
|
+
}
|
|
26
|
+
return output + (script ? "><\/script>" : "/>");
|
|
27
|
+
}
|
|
28
|
+
function createResourceHints(shellFlushed = false, styleNonce) {
|
|
29
|
+
const resources = /* @__PURE__ */ new Map();
|
|
30
|
+
const groups = [[], [], [], [], []];
|
|
31
|
+
const styles = /* @__PURE__ */ new Map();
|
|
32
|
+
const dependencies = /* @__PURE__ */ new Map();
|
|
33
|
+
const visibleInline = /* @__PURE__ */ new Set();
|
|
34
|
+
const collector = {
|
|
35
|
+
add(kind, href, options) {
|
|
36
|
+
let type = kind;
|
|
37
|
+
let source = href;
|
|
38
|
+
const init = kind === "style" || kind === "stylesheet" || kind === "script" || kind === "module-script";
|
|
39
|
+
if (kind === "preload") {
|
|
40
|
+
type = options.as;
|
|
41
|
+
if (type === "image" && options.imageSrcSet) source = options.imageSrcSet + "\n" + (options.imageSizes || "");
|
|
42
|
+
} else if (kind === "modulepreload") type = "module-" + (options.as || "script");
|
|
43
|
+
else if (kind === "stylesheet") type = "style";
|
|
44
|
+
else if (kind === "preconnect") type += ":" + (options.crossOrigin ?? "default");
|
|
45
|
+
const key = JSON.stringify([type, source]);
|
|
46
|
+
const prior = resources.get(key);
|
|
47
|
+
if (prior && (!init || prior.kind !== "preload" && prior.kind !== "modulepreload")) return prior;
|
|
48
|
+
const resource = { kind, href, options: { ...options } };
|
|
49
|
+
if (kind === "style" && (!styleNonce || options.nonce === styleNonce)) resource.css = styleText(options);
|
|
50
|
+
if (prior) {
|
|
51
|
+
prior.cancelled = true;
|
|
52
|
+
resource.preloaded = !!prior.sent;
|
|
53
|
+
for (const name of ["crossOrigin", "integrity"]) {
|
|
54
|
+
if (resource.options[name] == null && prior.options[name] != null) resource.options[name] = prior.options[name];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
resources.set(key, resource);
|
|
58
|
+
if (kind === "stylesheet" || kind === "style") {
|
|
59
|
+
const precedence = options.precedence;
|
|
60
|
+
let group = styles.get(precedence);
|
|
61
|
+
if (!group) styles.set(precedence, group = []);
|
|
62
|
+
group.push(resource);
|
|
63
|
+
} else {
|
|
64
|
+
const group = kind === "dns-prefetch" || kind === "preconnect" ? 0 : kind === "preload" && options.as === "font" ? 1 : kind === "preload" && options.as === "image" && options.fetchPriority === "high" ? 2 : init ? 3 : 4;
|
|
65
|
+
groups[group].push(resource);
|
|
66
|
+
}
|
|
67
|
+
return resource;
|
|
68
|
+
},
|
|
69
|
+
addHost(type, props, scope) {
|
|
70
|
+
const kind = resourceKind(type, props);
|
|
71
|
+
if (!kind) return false;
|
|
72
|
+
const resource = collector.add(kind === "script" && props.type === "module" ? "module-script" : kind, kind === "script" ? props.src : props.href, props);
|
|
73
|
+
if (shellFlushed && kind === "stylesheet") {
|
|
74
|
+
const descriptor = [resourceURL(resource.href), resource.options.precedence];
|
|
75
|
+
for (const name in resource.options) {
|
|
76
|
+
if (name === "href" || name === "rel" || name === "precedence" || name === "data-precedence" || name === "children" || name === "dangerouslySetInnerHTML" || name === "innerHTML" || name === "style" || name === "suppressHydrationWarning" || name === "suppressContentEditableWarning" || name === "ref" || name === "key" || /^on/i.test(name) || !/^[a-zA-Z_:][a-zA-Z0-9:_.-]*$/.test(name)) continue;
|
|
77
|
+
const value = resource.options[name];
|
|
78
|
+
if (value == null || typeof value === "function" || typeof value === "symbol" || name === "hidden" && value === false) continue;
|
|
79
|
+
descriptor.push(attributeName(name), name === "hidden" ? "" : name === "src" ? resourceURL("" + value) : "" + value);
|
|
80
|
+
}
|
|
81
|
+
;
|
|
82
|
+
(scope ? scope.stylesheets ||= /* @__PURE__ */ new Map() : dependencies).set(resource.href, descriptor);
|
|
83
|
+
} else if (shellFlushed && kind === "style") {
|
|
84
|
+
;
|
|
85
|
+
(scope ? scope.inline ||= /* @__PURE__ */ new Set() : visibleInline).add(resource.options.precedence);
|
|
86
|
+
}
|
|
87
|
+
return true;
|
|
88
|
+
},
|
|
89
|
+
mergeScope(scope, parent) {
|
|
90
|
+
if (scope.stylesheets) for (const [href, descriptor] of scope.stylesheets) {
|
|
91
|
+
;
|
|
92
|
+
(parent ? parent.stylesheets ||= /* @__PURE__ */ new Map() : dependencies).set(href, descriptor);
|
|
93
|
+
}
|
|
94
|
+
if (scope.inline) for (const precedence of scope.inline) {
|
|
95
|
+
;
|
|
96
|
+
(parent ? parent.inline ||= /* @__PURE__ */ new Set() : visibleInline).add(precedence);
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
takeStylesheets() {
|
|
100
|
+
const result = Array.from(dependencies.values());
|
|
101
|
+
dependencies.clear();
|
|
102
|
+
return result;
|
|
103
|
+
},
|
|
104
|
+
drain() {
|
|
105
|
+
let output = "";
|
|
106
|
+
function flush(group, precedence) {
|
|
107
|
+
let remaining = 0;
|
|
108
|
+
let inline = false, hasStylesheets = false;
|
|
109
|
+
let hrefs = "", rules = "";
|
|
110
|
+
for (const resource of group) {
|
|
111
|
+
if (!resource.sent && !resource.cancelled) {
|
|
112
|
+
if (resource.kind === "style") {
|
|
113
|
+
if (shellFlushed && !visibleInline.has(precedence)) {
|
|
114
|
+
group[remaining++] = resource;
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
inline = true;
|
|
118
|
+
if (resource.css !== void 0) {
|
|
119
|
+
hrefs += (hrefs ? " " : "") + resource.href;
|
|
120
|
+
rules += resource.css;
|
|
121
|
+
}
|
|
122
|
+
} else {
|
|
123
|
+
if (resource.kind === "stylesheet") hasStylesheets = true;
|
|
124
|
+
if (!(shellFlushed && resource.kind === "stylesheet" && resource.preloaded)) output += markup(resource, shellFlushed);
|
|
125
|
+
}
|
|
126
|
+
resource.sent = true;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
group.length = remaining;
|
|
130
|
+
if (hrefs || inline && !shellFlushed && !hasStylesheets) {
|
|
131
|
+
output += `<style${styleNonce !== void 0 ? ` nonce="${escapeAttr(styleNonce)}"` : ""}${shellFlushed ? ' media="not all"' : ""} data-precedence="${escapeAttr(precedence)}"${hrefs ? ` data-href="${escapeAttr(hrefs)}"` : ""}>${rules}</style>`;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
for (let index = 0; index < groups.length; index++) {
|
|
135
|
+
if (index === 3) for (const [precedence, group] of styles) flush(group, precedence);
|
|
136
|
+
flush(groups[index]);
|
|
137
|
+
}
|
|
138
|
+
shellFlushed = true;
|
|
139
|
+
visibleInline.clear();
|
|
140
|
+
return output;
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
return collector;
|
|
144
|
+
}
|
|
145
|
+
export {
|
|
146
|
+
createResourceHints
|
|
147
|
+
};
|
|
148
|
+
//# sourceMappingURL=resource-hints.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/server/resource-hints.ts"],
|
|
4
|
+
"sourcesContent": ["import { resourceKind, resourceURL, type ResourceHintKind, type ResourceHintOptions } from '../core/resource-hints'\nimport { attrToHtml, escapeAttr } from './escape'\nimport { attributeName } from '../core/attributes'\n\ninterface Resource {\n kind: ResourceHintKind | 'style'\n href: string\n options: Record<string, any>\n sent?: boolean\n cancelled?: boolean\n preloaded?: boolean\n css?: string\n}\n\nexport interface ResourceScope {\n stylesheets?: Map<string, string[]>\n inline?: Set<string>\n}\n\nfunction styleText(props: any): string {\n const html = props.dangerouslySetInnerHTML\n if (html != null) {\n if (typeof html !== 'object' || !('__html' in html)) throw new Error('dangerouslySetInnerHTML must be an object with an __html field.')\n if (props.children != null) throw new Error('Can only set one of children or dangerouslySetInnerHTML.')\n return html.__html == null ? '' : '' + html.__html\n }\n const child = Array.isArray(props.children) ? props.children.length < 2 ? props.children[0] : null : props.children\n return child == null || typeof child === 'function' || typeof child === 'symbol' ? ''\n : ('' + child).replace(/(<\\/?)(s)(tyle)/gi, (_, prefix: string, s: string, suffix: string) => prefix + '\\\\' + s.charCodeAt(0).toString(16) + ' ' + suffix)\n}\n\nfunction markup(resource: Resource, late: boolean): string {\n const { kind, href, options } = resource\n const script = kind === 'script' || kind === 'module-script'\n const style = kind === 'stylesheet'\n const props: Record<string, any> = script\n ? { src: href, ...(kind === 'module-script' ? { type: 'module' } : {}), async: true, ...options }\n : style\n ? late\n ? { rel: 'preload', as: 'style', href, crossOrigin: options.crossOrigin, fetchPriority: options.fetchPriority, integrity: options.integrity, media: options.media, hrefLang: options.hrefLang, referrerPolicy: options.referrerPolicy }\n : { rel: 'stylesheet', href, 'data-precedence': options.precedence!, ...options }\n : { rel: kind, ...(options.as === 'image' && options.imageSrcSet ? {} : { href }), ...options }\n let output = script ? '<script' : '<link'\n for (const name in props) {\n if (name === 'precedence' || late && name === 'data-precedence') continue\n const value = name === 'href' || name === 'src' ? resourceURL(props[name]!) : props[name]!\n output += attrToHtml(name, value).replace(/'/g, ''')\n }\n return output + (script ? '></script>' : '/>')\n}\n\nexport function createResourceHints(shellFlushed = false, styleNonce?: string) {\n const resources = new Map<string, Resource>()\n const groups: Resource[][] = [[], [], [], [], []]\n const styles = new Map<string, Resource[]>()\n const dependencies = new Map<string, string[]>()\n const visibleInline = new Set<string>()\n const collector = {\n add(kind: ResourceHintKind | 'style', href: string, options: ResourceHintOptions): Resource {\n let type: string = kind\n let source = href\n const init = kind === 'style' || kind === 'stylesheet' || kind === 'script' || kind === 'module-script'\n if (kind === 'preload') {\n type = options.as!\n if (type === 'image' && options.imageSrcSet) source = options.imageSrcSet + '\\n' + (options.imageSizes || '')\n } else if (kind === 'modulepreload') type = 'module-' + (options.as || 'script')\n else if (kind === 'stylesheet') type = 'style'\n else if (kind === 'preconnect') type += ':' + (options.crossOrigin ?? 'default')\n const key = JSON.stringify([type, source])\n const prior = resources.get(key)\n if (prior && (!init || prior.kind !== 'preload' && prior.kind !== 'modulepreload')) return prior\n\n const resource: Resource = { kind, href, options: { ...options } }\n if (kind === 'style' && (!styleNonce || options.nonce === styleNonce)) resource.css = styleText(options)\n if (prior) {\n prior.cancelled = true\n resource.preloaded = !!prior.sent\n for (const name of ['crossOrigin', 'integrity']) {\n if (resource.options[name] == null && prior.options[name] != null) resource.options[name] = prior.options[name]!\n }\n }\n resources.set(key, resource)\n if (kind === 'stylesheet' || kind === 'style') {\n const precedence = options.precedence!\n let group = styles.get(precedence)\n if (!group) styles.set(precedence, group = [])\n group.push(resource)\n } else {\n const group = kind === 'dns-prefetch' || kind === 'preconnect' ? 0\n : kind === 'preload' && options.as === 'font' ? 1\n : kind === 'preload' && options.as === 'image' && options.fetchPriority === 'high' ? 2\n : init ? 3 : 4\n groups[group]!.push(resource)\n }\n return resource\n },\n addHost(type: string, props: any, scope?: ResourceScope): boolean {\n const kind = resourceKind(type, props)\n if (!kind) return false\n const resource = collector.add(kind === 'script' && props.type === 'module' ? 'module-script' : kind, kind === 'script' ? props.src : props.href, props)\n if (shellFlushed && kind === 'stylesheet') {\n const descriptor = [resourceURL(resource.href), resource.options.precedence]\n for (const name in resource.options) {\n if (name === 'href' || name === 'rel' || name === 'precedence' || name === 'data-precedence' || name === 'children' || name === 'dangerouslySetInnerHTML' || name === 'innerHTML' || name === 'style' || name === 'suppressHydrationWarning' || name === 'suppressContentEditableWarning' || name === 'ref' || name === 'key' || /^on/i.test(name) || !/^[a-zA-Z_:][a-zA-Z0-9:_.-]*$/.test(name)) continue\n const value = resource.options[name]\n if (value == null || typeof value === 'function' || typeof value === 'symbol' || name === 'hidden' && value === false) continue\n descriptor.push(attributeName(name), name === 'hidden' ? '' : name === 'src' ? resourceURL('' + value) : '' + value)\n }\n ;(scope ? scope.stylesheets ||= new Map() : dependencies).set(resource.href, descriptor)\n } else if (shellFlushed && kind === 'style') {\n ;(scope ? scope.inline ||= new Set() : visibleInline).add(resource.options.precedence)\n }\n return true\n },\n mergeScope(scope: ResourceScope, parent?: ResourceScope): void {\n if (scope.stylesheets) for (const [href, descriptor] of scope.stylesheets) {\n ;(parent ? parent.stylesheets ||= new Map() : dependencies).set(href, descriptor)\n }\n if (scope.inline) for (const precedence of scope.inline) {\n ;(parent ? parent.inline ||= new Set() : visibleInline).add(precedence)\n }\n },\n takeStylesheets(): string[][] {\n const result = Array.from(dependencies.values())\n dependencies.clear()\n return result\n },\n drain(): string {\n let output = ''\n function flush(group: Resource[], precedence?: string) {\n let remaining = 0\n let inline = false, hasStylesheets = false\n let hrefs = '', rules = ''\n for (const resource of group) {\n if (!resource.sent && !resource.cancelled) {\n if (resource.kind === 'style') {\n if (shellFlushed && !visibleInline.has(precedence!)) { group[remaining++] = resource; continue }\n inline = true\n if (resource.css !== undefined) {\n hrefs += (hrefs ? ' ' : '') + resource.href\n rules += resource.css\n }\n } else {\n if (resource.kind === 'stylesheet') hasStylesheets = true\n if (!(shellFlushed && resource.kind === 'stylesheet' && resource.preloaded)) output += markup(resource, shellFlushed)\n }\n resource.sent = true\n }\n }\n group.length = remaining\n if (hrefs || inline && !shellFlushed && !hasStylesheets) {\n output += `<style${styleNonce !== undefined ? ` nonce=\"${escapeAttr(styleNonce)}\"` : ''}${shellFlushed ? ' media=\"not all\"' : ''} data-precedence=\"${escapeAttr(precedence!)}\"${hrefs ? ` data-href=\"${escapeAttr(hrefs)}\"` : ''}>${rules}</style>`\n }\n }\n for (let index = 0; index < groups.length; index++) {\n if (index === 3) for (const [precedence, group] of styles) flush(group, precedence)\n flush(groups[index]!)\n }\n shellFlushed = true\n visibleInline.clear()\n return output\n },\n }\n return collector\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,cAAc,mBAAoE;AAC3F,SAAS,YAAY,kBAAkB;AACvC,SAAS,qBAAqB;AAiB9B,SAAS,UAAU,OAAoB;AACrC,QAAM,OAAO,MAAM;AACnB,MAAI,QAAQ,MAAM;AAChB,QAAI,OAAO,SAAS,YAAY,EAAE,YAAY,MAAO,OAAM,IAAI,MAAM,iEAAiE;AACtI,QAAI,MAAM,YAAY,KAAM,OAAM,IAAI,MAAM,0DAA0D;AACtG,WAAO,KAAK,UAAU,OAAO,KAAK,KAAK,KAAK;AAAA,EAC9C;AACA,QAAM,QAAQ,MAAM,QAAQ,MAAM,QAAQ,IAAI,MAAM,SAAS,SAAS,IAAI,MAAM,SAAS,CAAC,IAAI,OAAO,MAAM;AAC3G,SAAO,SAAS,QAAQ,OAAO,UAAU,cAAc,OAAO,UAAU,WAAW,MAC9E,KAAK,OAAO,QAAQ,qBAAqB,CAAC,GAAG,QAAgB,GAAW,WAAmB,SAAS,OAAO,EAAE,WAAW,CAAC,EAAE,SAAS,EAAE,IAAI,MAAM,MAAM;AAC7J;AAEA,SAAS,OAAO,UAAoB,MAAuB;AACzD,QAAM,EAAE,MAAM,MAAM,QAAQ,IAAI;AAChC,QAAM,SAAS,SAAS,YAAY,SAAS;AAC7C,QAAM,QAAQ,SAAS;AACvB,QAAM,QAA6B,SAC/B,EAAE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AAS,QAAQ,GAAG,QAAQ,OAAO,QAAQ,SAAS;AAClD,YAAI,UAAU,EAAG,YAAW,CAAC,YAAY,KAAK,KAAK,OAAQ,OAAM,OAAO,UAAU;AAClF,cAAM,OAAO,KAAK,CAAE;AAAA,MACtB;AACA,qBAAe;AACf,oBAAc,MAAM;AACpB,aAAO;AAAA,IACT;AAAA,EACF;AACA,SAAO;AACT;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
package/dist/server/stream.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
import type { ReactNode } from
|
|
1
|
+
import type { ReactNode } from "../core/index.js";
|
|
2
|
+
import { type SSRFrame } from "./dispatcher.js";
|
|
3
|
+
import { type BrowserBailoutCallback } from "./walk.js";
|
|
2
4
|
export interface StreamOptions {
|
|
3
5
|
identifierPrefix?: string;
|
|
4
|
-
nonce?: string
|
|
6
|
+
nonce?: string | {
|
|
7
|
+
script?: string;
|
|
8
|
+
style?: string;
|
|
9
|
+
};
|
|
5
10
|
bootstrapScriptContent?: string | ReadonlyArray<string>;
|
|
6
11
|
bootstrapScripts?: ReadonlyArray<string | {
|
|
7
12
|
src: string;
|
|
@@ -13,6 +18,7 @@ export interface StreamOptions {
|
|
|
13
18
|
nonce?: string;
|
|
14
19
|
}>;
|
|
15
20
|
onError?: (error: unknown) => string | void;
|
|
21
|
+
onBrowserBailout?: BrowserBailoutCallback;
|
|
16
22
|
signal?: AbortSignal;
|
|
17
23
|
progressiveChunkSize?: number;
|
|
18
24
|
}
|
|
@@ -22,12 +28,19 @@ export interface ReadableStreamResult extends ReadableStream<Uint8Array> {
|
|
|
22
28
|
export interface PipeableWritable {
|
|
23
29
|
write(chunk: string): unknown;
|
|
24
30
|
end(): unknown;
|
|
31
|
+
destroy?(error?: unknown): unknown;
|
|
25
32
|
}
|
|
26
33
|
export interface OrchestratorState {
|
|
27
34
|
nextId: number;
|
|
28
35
|
pending: Set<Promise<void>>;
|
|
29
36
|
closed: boolean;
|
|
30
37
|
errored: unknown | null;
|
|
38
|
+
aborted: boolean;
|
|
39
|
+
reason: unknown;
|
|
40
|
+
abort: (reason?: unknown) => void;
|
|
41
|
+
cancelled: Promise<void>;
|
|
42
|
+
onShellReady?: () => void;
|
|
43
|
+
frame?: SSRFrame;
|
|
31
44
|
}
|
|
32
45
|
type Emit = (chunk: string) => void;
|
|
33
46
|
export declare function streamHtml(children: ReactNode, emit: Emit, options: StreamOptions, state: OrchestratorState): Promise<void>;
|