@tanstack/redact 0.0.14 → 0.0.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/core/internal.d.ts +23 -39
- package/dist/core/internal.js +7 -23
- package/dist/core/internal.js.map +3 -3
- package/dist/dom/dispatcher.d.ts +3 -1
- package/dist/dom/dispatcher.js +104 -97
- package/dist/dom/dispatcher.js.map +2 -2
- package/dist/dom/dom.js +1 -1
- package/dist/dom/dom.js.map +2 -2
- package/dist/dom/event-replay.js +7 -29
- package/dist/dom/event-replay.js.map +2 -2
- package/dist/dom/features/class/full.js +16 -16
- package/dist/dom/features/class/full.js.map +2 -2
- package/dist/dom/features/class/stub.js +7 -7
- package/dist/dom/features/class/stub.js.map +2 -2
- package/dist/dom/features/context/full.js +7 -7
- package/dist/dom/features/context/full.js.map +2 -2
- package/dist/dom/features/context/stub.js +3 -3
- package/dist/dom/features/context/stub.js.map +2 -2
- package/dist/dom/features/forward-ref/full.js +11 -11
- package/dist/dom/features/forward-ref/full.js.map +2 -2
- package/dist/dom/features/hydration/full.d.ts +26 -14
- package/dist/dom/features/hydration/full.js +412 -92
- package/dist/dom/features/hydration/full.js.map +2 -2
- package/dist/dom/features/hydration/stub.d.ts +13 -12
- package/dist/dom/features/hydration/stub.js +23 -8
- package/dist/dom/features/hydration/stub.js.map +2 -2
- package/dist/dom/features/lazy/full.js +3 -43
- package/dist/dom/features/lazy/full.js.map +2 -2
- package/dist/dom/features/lazy/stub.js +1 -1
- package/dist/dom/features/lazy/stub.js.map +2 -2
- package/dist/dom/features/memo/full.js +3 -3
- package/dist/dom/features/memo/full.js.map +2 -2
- package/dist/dom/features/memo/stub.js +1 -1
- package/dist/dom/features/memo/stub.js.map +2 -2
- package/dist/dom/features/portal/full.js +2 -2
- package/dist/dom/features/portal/full.js.map +2 -2
- package/dist/dom/features/suspense/full.js +151 -109
- package/dist/dom/features/suspense/full.js.map +2 -2
- package/dist/dom/reconcile.d.ts +3 -1
- package/dist/dom/reconcile.js +141 -129
- package/dist/dom/reconcile.js.map +2 -2
- package/dist/dom/root-internal.d.ts +9 -0
- package/dist/dom/root-internal.js +31 -0
- package/dist/dom/root-internal.js.map +7 -0
- package/dist/dom/root.d.ts +1 -1
- package/dist/dom/root.js +4 -136
- package/dist/dom/root.js.map +2 -2
- package/dist/dom/test-utils.js +1 -1
- package/dist/dom/test-utils.js.map +2 -2
- package/dist/react/children.js +4 -1
- package/dist/react/children.js.map +2 -2
- package/dist/react/class.js +8 -2
- package/dist/react/class.js.map +2 -2
- package/dist/react/context.js +4 -1
- package/dist/react/context.js.map +2 -2
- package/dist/react/index.js +1 -1
- package/dist/react/index.js.map +2 -2
- package/dist/react/shared-internals.d.ts +4 -7
- package/dist/react/shared-internals.js +4 -7
- package/dist/react/shared-internals.js.map +2 -2
- package/dist/server/stream.d.ts +5 -1
- package/dist/server/stream.js.map +2 -2
- package/package.json +1 -1
- package/src/core/internal.ts +30 -50
- package/src/dom/dispatcher.ts +114 -105
- package/src/dom/dom.ts +1 -1
- package/src/dom/event-replay.ts +14 -30
- package/src/dom/features/class/full.ts +16 -16
- package/src/dom/features/class/stub.ts +7 -7
- package/src/dom/features/context/full.ts +7 -7
- package/src/dom/features/context/stub.ts +3 -3
- package/src/dom/features/forward-ref/full.ts +11 -11
- package/src/dom/features/hydration/full.ts +516 -104
- package/src/dom/features/hydration/stub.ts +28 -14
- package/src/dom/features/lazy/full.ts +3 -56
- package/src/dom/features/lazy/stub.ts +1 -1
- package/src/dom/features/memo/full.ts +3 -3
- package/src/dom/features/memo/stub.ts +1 -1
- package/src/dom/features/portal/full.ts +2 -2
- package/src/dom/features/suspense/full.ts +176 -129
- package/src/dom/reconcile.ts +164 -170
- package/src/dom/root-internal.ts +40 -0
- package/src/dom/root.ts +5 -165
- package/src/dom/test-utils.ts +1 -1
- package/src/react/children.ts +4 -1
- package/src/react/class.ts +8 -2
- package/src/react/context.ts +4 -1
- package/src/react/index.ts +1 -1
- package/src/react/shared-internals.ts +8 -14
- package/src/server/stream.ts +9 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/react/children.ts"],
|
|
4
|
-
"sourcesContent": ["import { isValidElement, cloneElement } from './element'\nimport type { ReactNode, ReactElement } from '../core'\n\nfunction flatten(node: ReactNode, out: any[], prefix: string): void {\n if (node == null || typeof node === 'boolean') return\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) flatten(node[i], out, prefix + '.' + i)\n return\n }\n out.push(node)\n}\n\nfunction getKey(node: any, index: number, prefix: string): string {\n if (isValidElement(node) && node.key != null) return prefix + '$' + node.key\n return prefix + ':' + index\n}\n\nfunction mapChildren(\n children: ReactNode,\n fn: (child: ReactNode, index: number) => any,\n prefix = '',\n): any[] {\n const flat: any[] = []\n flatten(children, flat, prefix)\n const out: any[] = []\n for (let i = 0; i < flat.length; i++) {\n const child = flat[i]\n const mapped = fn(child, i)\n if (mapped == null) continue\n if (Array.isArray(mapped)) {\n for (let j = 0; j < mapped.length; j++) {\n const m = mapped[j]\n if (m == null) continue\n out.push(\n isValidElement(m) && m.key == null\n ? cloneElement(m as ReactElement, { key: getKey(child, i, prefix) + '/' + j })\n : m,\n )\n }\n } else {\n out.push(\n isValidElement(mapped) && mapped.key == null\n ? cloneElement(mapped as ReactElement, { key: getKey(child, i, prefix) })\n : mapped,\n )\n }\n }\n return out\n}\n\nexport const Children = {\n map(children: ReactNode, fn: (child: ReactNode, index: number) => any): any[] | null {\n if (children == null) return null\n return mapChildren(children, fn)\n },\n forEach(children: ReactNode, fn: (child: ReactNode, index: number) => void): void {\n if (children == null) return\n mapChildren(children, (c, i) => {\n fn(c, i)\n return null\n })\n },\n count(children: ReactNode): number {\n let n = 0\n const flat: any[] = []\n flatten(children, flat, '')\n for (let i = 0; i < flat.length; i++) n++\n return n\n },\n toArray(children: ReactNode): any[] {\n const flat: any[] = []\n flatten(children, flat, '')\n return flat.map((c, i) =>\n isValidElement(c) && c.key == null\n ? cloneElement(c as ReactElement, { key: '' + i })\n : c,\n )\n },\n only(children: ReactNode): ReactElement {\n if (!isValidElement(children)) {\n throw new Error('Children.only expected a single React element.')\n }\n return children\n },\n}\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,gBAAgB,oBAAoB;AAG7C,SAAS,QAAQ,MAAiB,KAAY,QAAsB;AAClE,MAAI,QAAQ,QAAQ,OAAO,SAAS,UAAW;AAC/C,MAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,IAAK,SAAQ,KAAK,CAAC,GAAG,KAAK,SAAS,MAAM,CAAC;AAC5E;AAAA,EACF;AACA,MAAI,KAAK,IAAI;AACf;AAEA,SAAS,OAAO,MAAW,OAAe,QAAwB;AAChE,MAAI,eAAe,IAAI,KAAK,KAAK,OAAO,KAAM,QAAO,SAAS,MAAM,KAAK;AACzE,SAAO,SAAS,MAAM;AACxB;AAEA,SAAS,YACP,UACA,IACA,SAAS,IACF;AACP,QAAM,OAAc,CAAC;AACrB,UAAQ,UAAU,MAAM,MAAM;AAC9B,QAAM,MAAa,CAAC;AACpB,WAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;AACpC,UAAM,QAAQ,KAAK,CAAC;AACpB,UAAM,SAAS,GAAG,OAAO,CAAC;AAC1B,QAAI,UAAU,KAAM;AACpB,QAAI,MAAM,QAAQ,MAAM,GAAG;AACzB,eAAS,IAAI,GAAG,IAAI,OAAO,QAAQ,KAAK;AACtC,cAAM,IAAI,OAAO,CAAC;AAClB,YAAI,KAAK,KAAM;AACf,YAAI;AAAA,UACF,eAAe,CAAC,KAAK,EAAE,OAAO,OAC1B,aAAa,GAAmB,EAAE,KAAK,OAAO,OAAO,GAAG,MAAM,IAAI,MAAM,EAAE,CAAC,IAC3E;AAAA,QACN;AAAA,MACF;AAAA,IACF,OAAO;AACL,UAAI;AAAA,QACF,eAAe,MAAM,KAAK,OAAO,OAAO,OACpC,aAAa,QAAwB,EAAE,KAAK,OAAO,OAAO,GAAG,MAAM,EAAE,CAAC,IACtE;AAAA,MACN;AAAA,IACF;AAAA,EACF;AACA,SAAO;AACT;AAEO,IAAM,WAAW;AAAA,EACtB,IAAI,UAAqB,IAA4D;AACnF,QAAI,YAAY,KAAM,QAAO;AAC7B,WAAO,YAAY,UAAU,EAAE;AAAA,EACjC;AAAA,EACA,QAAQ,UAAqB,IAAqD;AAChF,QAAI,YAAY,KAAM;AACtB,gBAAY,UAAU,CAAC,GAAG,MAAM;AAC9B,SAAG,GAAG,CAAC;AACP,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AAAA,EACA,MAAM,UAA6B;AACjC,QAAI,IAAI;AACR,UAAM,OAAc,CAAC;AACrB,YAAQ,UAAU,MAAM,EAAE;AAC1B,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,IAAK;AACtC,WAAO;AAAA,EACT;AAAA,EACA,QAAQ,UAA4B;AAClC,UAAM,OAAc,CAAC;AACrB,YAAQ,UAAU,MAAM,EAAE;AAC1B,WAAO,KAAK;AAAA,MAAI,CAAC,GAAG,MAClB,eAAe,CAAC,KAAK,EAAE,OAAO,OAC1B,aAAa,GAAmB,EAAE,KAAK,KAAK,EAAE,CAAC,IAC/C;AAAA,IACN;AAAA,EACF;AAAA,EACA,KAAK,UAAmC;AACtC,QAAI,CAAC,eAAe,QAAQ,GAAG;AAC7B,
|
|
4
|
+
"sourcesContent": ["import { isValidElement, cloneElement } from './element'\nimport type { ReactNode, ReactElement } from '../core'\n\nfunction flatten(node: ReactNode, out: any[], prefix: string): void {\n if (node == null || typeof node === 'boolean') return\n if (Array.isArray(node)) {\n for (let i = 0; i < node.length; i++) flatten(node[i], out, prefix + '.' + i)\n return\n }\n out.push(node)\n}\n\nfunction getKey(node: any, index: number, prefix: string): string {\n if (isValidElement(node) && node.key != null) return prefix + '$' + node.key\n return prefix + ':' + index\n}\n\nfunction mapChildren(\n children: ReactNode,\n fn: (child: ReactNode, index: number) => any,\n prefix = '',\n): any[] {\n const flat: any[] = []\n flatten(children, flat, prefix)\n const out: any[] = []\n for (let i = 0; i < flat.length; i++) {\n const child = flat[i]\n const mapped = fn(child, i)\n if (mapped == null) continue\n if (Array.isArray(mapped)) {\n for (let j = 0; j < mapped.length; j++) {\n const m = mapped[j]\n if (m == null) continue\n out.push(\n isValidElement(m) && m.key == null\n ? cloneElement(m as ReactElement, { key: getKey(child, i, prefix) + '/' + j })\n : m,\n )\n }\n } else {\n out.push(\n isValidElement(mapped) && mapped.key == null\n ? cloneElement(mapped as ReactElement, { key: getKey(child, i, prefix) })\n : mapped,\n )\n }\n }\n return out\n}\n\nexport const Children = {\n map(children: ReactNode, fn: (child: ReactNode, index: number) => any): any[] | null {\n if (children == null) return null\n return mapChildren(children, fn)\n },\n forEach(children: ReactNode, fn: (child: ReactNode, index: number) => void): void {\n if (children == null) return\n mapChildren(children, (c, i) => {\n fn(c, i)\n return null\n })\n },\n count(children: ReactNode): number {\n let n = 0\n const flat: any[] = []\n flatten(children, flat, '')\n for (let i = 0; i < flat.length; i++) n++\n return n\n },\n toArray(children: ReactNode): any[] {\n const flat: any[] = []\n flatten(children, flat, '')\n return flat.map((c, i) =>\n isValidElement(c) && c.key == null\n ? cloneElement(c as ReactElement, { key: '' + i })\n : c,\n )\n },\n only(children: ReactNode): ReactElement {\n if (!isValidElement(children)) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Children.only expected a single React element.')\n }\n throw new Error()\n }\n return children\n },\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,gBAAgB,oBAAoB;AAG7C,SAAS,QAAQ,MAAiB,KAAY,QAAsB;AAClE,MAAI,QAAQ,QAAQ,OAAO,SAAS,UAAW;AAC/C,MAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,IAAK,SAAQ,KAAK,CAAC,GAAG,KAAK,SAAS,MAAM,CAAC;AAC5E;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B;AACjC,QAAI,IAAI;AACR,UAAM,OAAc,CAAC;AACrB,YAAQ,UAAU,MAAM,EAAE;AAC1B,aAAS,IAAI,GAAG,IAAI,KAAK,QAAQ,IAAK;AACtC,WAAO;AAAA,EACT;AAAA,EACA,QAAQ,UAA4B;AAClC,UAAM,OAAc,CAAC;AACrB,YAAQ,UAAU,MAAM,EAAE;AAC1B,WAAO,KAAK;AAAA,MAAI,CAAC,GAAG,MAClB,eAAe,CAAC,KAAK,EAAE,OAAO,OAC1B,aAAa,GAAmB,EAAE,KAAK,KAAK,EAAE,CAAC,IAC/C;AAAA,IACN;AAAA,EACF;AAAA,EACA,KAAK,UAAmC;AACtC,QAAI,CAAC,eAAe,QAAQ,GAAG;AAC7B,UAAI,MAAuC;AACzC,cAAM,IAAI,MAAM,gDAAgD;AAAA,MAClE;AACA,YAAM,IAAI,MAAM;AAAA,IAClB;AACA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/react/class.js
CHANGED
|
@@ -17,7 +17,10 @@ var Component = class {
|
|
|
17
17
|
}
|
|
18
18
|
setState(updater, callback) {
|
|
19
19
|
if (!this._enqueueUpdate) {
|
|
20
|
-
|
|
20
|
+
if (true) {
|
|
21
|
+
throw new Error("Cannot call setState on an um component.");
|
|
22
|
+
}
|
|
23
|
+
throw new Error();
|
|
21
24
|
}
|
|
22
25
|
this._enqueueUpdate(updater, callback);
|
|
23
26
|
}
|
|
@@ -26,7 +29,10 @@ var Component = class {
|
|
|
26
29
|
this._forceUpdate(callback);
|
|
27
30
|
}
|
|
28
31
|
render() {
|
|
29
|
-
|
|
32
|
+
if (true) {
|
|
33
|
+
throw new Error("Component subclass must implement render().");
|
|
34
|
+
}
|
|
35
|
+
throw new Error();
|
|
30
36
|
}
|
|
31
37
|
};
|
|
32
38
|
Component.prototype.isReactComponent = {};
|
package/dist/react/class.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/react/class.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ReactNode } from '../core'\n\ntype SetStateCallback<S, P> =\n | Partial<S>\n | ((prev: S, props: P) => Partial<S> | null)\n | null\n\nexport class Component<P = {}, S = {}> {\n static contextType?: any\n static getDerivedStateFromProps?(props: any, state: any): any\n static getDerivedStateFromError?(error: any): any\n static defaultProps?: any\n static displayName?: string\n\n props: P\n state: S = {} as S\n context: any\n refs: Record<string, any> = {}\n\n // Injected by reconciler\n _fiber: any = null\n _enqueueUpdate: ((updater: SetStateCallback<S, P>, cb?: () => void) => void) | null = null\n _forceUpdate: ((cb?: () => void) => void) | null = null\n\n constructor(props: P, context?: any) {\n this.props = props\n this.context = context\n }\n\n setState(updater: SetStateCallback<S, P>, callback?: () => void): void {\n if (!this._enqueueUpdate) {\n throw new Error('Cannot call setState on an
|
|
5
|
-
"mappings": ";AAOO,IAAM,YAAN,MAAgC;AAAA,EACrC,OAAO;AAAA,EAGP,OAAO;AAAA,EACP,OAAO;AAAA,EAEP;AAAA,EACA,QAAW,CAAC;AAAA,EACZ;AAAA,EACA,OAA4B,CAAC;AAAA;AAAA,EAG7B,SAAc;AAAA,EACd,iBAAsF;AAAA,EACtF,eAAmD;AAAA,EAEnD,YAAY,OAAU,SAAe;AACnC,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,SAAS,SAAiC,UAA6B;AACrE,QAAI,CAAC,KAAK,gBAAgB;AACxB,
|
|
4
|
+
"sourcesContent": ["import type { ReactNode } from '../core'\n\ntype SetStateCallback<S, P> =\n | Partial<S>\n | ((prev: S, props: P) => Partial<S> | null)\n | null\n\nexport class Component<P = {}, S = {}> {\n static contextType?: any\n static getDerivedStateFromProps?(props: any, state: any): any\n static getDerivedStateFromError?(error: any): any\n static defaultProps?: any\n static displayName?: string\n\n props: P\n state: S = {} as S\n context: any\n refs: Record<string, any> = {}\n\n // Injected by reconciler\n _fiber: any = null\n _enqueueUpdate: ((updater: SetStateCallback<S, P>, cb?: () => void) => void) | null = null\n _forceUpdate: ((cb?: () => void) => void) | null = null\n\n constructor(props: P, context?: any) {\n this.props = props\n this.context = context\n }\n\n setState(updater: SetStateCallback<S, P>, callback?: () => void): void {\n if (!this._enqueueUpdate) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Cannot call setState on an um component.')\n }\n throw new Error()\n }\n this._enqueueUpdate(updater, callback)\n }\n\n forceUpdate(callback?: () => void): void {\n if (!this._forceUpdate) return\n this._forceUpdate(callback)\n }\n\n render(): ReactNode {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Component subclass must implement render().')\n }\n throw new Error()\n }\n\n componentDidMount?(): void\n componentDidUpdate?(prevProps: P, prevState: S, snapshot?: any): void\n componentWillUnmount?(): void\n shouldComponentUpdate?(nextProps: P, nextState: S, nextCtx: any): boolean\n getSnapshotBeforeUpdate?(prevProps: P, prevState: S): any\n componentDidCatch?(error: any, info: { componentStack: string }): void\n}\n;(Component.prototype as any).isReactComponent = {}\n\nexport class PureComponent<P = {}, S = {}> extends Component<P, S> {}\n;(PureComponent.prototype as any).isPureReactComponent = true\n"],
|
|
5
|
+
"mappings": ";AAOO,IAAM,YAAN,MAAgC;AAAA,EACrC,OAAO;AAAA,EAGP,OAAO;AAAA,EACP,OAAO;AAAA,EAEP;AAAA,EACA,QAAW,CAAC;AAAA,EACZ;AAAA,EACA,OAA4B,CAAC;AAAA;AAAA,EAG7B,SAAc;AAAA,EACd,iBAAsF;AAAA,EACtF,eAAmD;AAAA,EAEnD,YAAY,OAAU,SAAe;AACnC,SAAK,QAAQ;AACb,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,SAAS,SAAiC,UAA6B;AACrE,QAAI,CAAC,KAAK,gBAAgB;AACxB,UAAI,MAAuC;AACzC,cAAM,IAAI,MAAM,0CAA0C;AAAA,MAC5D;AACA,YAAM,IAAI,MAAM;AAAA,IAClB;AACA,SAAK,eAAe,SAAS,QAAQ;AAAA,EACvC;AAAA,EAEA,YAAY,UAA6B;AACvC,QAAI,CAAC,KAAK,aAAc;AACxB,SAAK,aAAa,QAAQ;AAAA,EAC5B;AAAA,EAEA,SAAoB;AAClB,QAAI,MAAuC;AACzC,YAAM,IAAI,MAAM,6CAA6C;AAAA,IAC/D;AACA,UAAM,IAAI,MAAM;AAAA,EAClB;AAQF;AACE,UAAU,UAAkB,mBAAmB,CAAC;AAE3C,IAAM,gBAAN,cAA4C,UAAgB;AAAC;AAClE,cAAc,UAAkB,uBAAuB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/react/context.js
CHANGED
|
@@ -9,7 +9,10 @@ function createContext(defaultValue) {
|
|
|
9
9
|
_currentValue: defaultValue
|
|
10
10
|
};
|
|
11
11
|
const Provider = function Provider2(_props) {
|
|
12
|
-
|
|
12
|
+
if (true) {
|
|
13
|
+
throw new Error("Provider components are handled by the renderer.");
|
|
14
|
+
}
|
|
15
|
+
throw new Error();
|
|
13
16
|
};
|
|
14
17
|
Provider.$$typeof = REACT_PROVIDER_TYPE;
|
|
15
18
|
Provider._context = context;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/react/context.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ReactElement, ReactNode } from '../core'\nimport { useContext } from './hooks'\n\nexport const REACT_CONTEXT_TYPE = Symbol.for('react.context')\nexport const REACT_PROVIDER_TYPE = Symbol.for('react.provider')\nexport const REACT_CONSUMER_TYPE = Symbol.for('react.consumer')\n\nexport interface Context<T> {\n $$typeof: typeof REACT_CONTEXT_TYPE\n _currentValue: T\n Provider: ProviderExoticComponent<{ value: T; children?: ReactNode }>\n Consumer: ConsumerExoticComponent<T>\n displayName?: string\n}\n\nexport interface ProviderExoticComponent<P> {\n $$typeof: typeof REACT_PROVIDER_TYPE\n _context: Context<any>\n (props: P): ReactElement\n}\n\nexport interface ConsumerExoticComponent<T> {\n $$typeof: typeof REACT_CONSUMER_TYPE\n _context: Context<T>\n (props: { children: (value: T) => ReactNode }): ReactElement\n}\n\nexport function createContext<T>(defaultValue: T): Context<T> {\n const context: Context<T> = {\n $$typeof: REACT_CONTEXT_TYPE,\n _currentValue: defaultValue,\n } as Context<T>\n\n const Provider: any = function Provider(_props: any): any {\n throw new Error('Provider components are handled by the renderer.')\n }\n Provider.$$typeof = REACT_PROVIDER_TYPE\n Provider._context = context\n\n const Consumer: any = function Consumer(props: { children: (v: T) => any }): any {\n return props.children(useContext(context))\n }\n Consumer.$$typeof = REACT_CONSUMER_TYPE\n Consumer._context = context\n\n context.Provider = Provider\n context.Consumer = Consumer\n\n return context\n}\n"],
|
|
5
|
-
"mappings": ";AACA,SAAS,kBAAkB;AAEpB,IAAM,qBAAqB,uBAAO,IAAI,eAAe;AACrD,IAAM,sBAAsB,uBAAO,IAAI,gBAAgB;AACvD,IAAM,sBAAsB,uBAAO,IAAI,gBAAgB;AAsBvD,SAAS,cAAiB,cAA6B;AAC5D,QAAM,UAAsB;AAAA,IAC1B,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAEA,QAAM,WAAgB,SAASA,UAAS,QAAkB;AACxD,
|
|
4
|
+
"sourcesContent": ["import type { ReactElement, ReactNode } from '../core'\nimport { useContext } from './hooks'\n\nexport const REACT_CONTEXT_TYPE = Symbol.for('react.context')\nexport const REACT_PROVIDER_TYPE = Symbol.for('react.provider')\nexport const REACT_CONSUMER_TYPE = Symbol.for('react.consumer')\n\nexport interface Context<T> {\n $$typeof: typeof REACT_CONTEXT_TYPE\n _currentValue: T\n Provider: ProviderExoticComponent<{ value: T; children?: ReactNode }>\n Consumer: ConsumerExoticComponent<T>\n displayName?: string\n}\n\nexport interface ProviderExoticComponent<P> {\n $$typeof: typeof REACT_PROVIDER_TYPE\n _context: Context<any>\n (props: P): ReactElement\n}\n\nexport interface ConsumerExoticComponent<T> {\n $$typeof: typeof REACT_CONSUMER_TYPE\n _context: Context<T>\n (props: { children: (value: T) => ReactNode }): ReactElement\n}\n\nexport function createContext<T>(defaultValue: T): Context<T> {\n const context: Context<T> = {\n $$typeof: REACT_CONTEXT_TYPE,\n _currentValue: defaultValue,\n } as Context<T>\n\n const Provider: any = function Provider(_props: any): any {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('Provider components are handled by the renderer.')\n }\n throw new Error()\n }\n Provider.$$typeof = REACT_PROVIDER_TYPE\n Provider._context = context\n\n const Consumer: any = function Consumer(props: { children: (v: T) => any }): any {\n return props.children(useContext(context))\n }\n Consumer.$$typeof = REACT_CONSUMER_TYPE\n Consumer._context = context\n\n context.Provider = Provider\n context.Consumer = Consumer\n\n return context\n}\n"],
|
|
5
|
+
"mappings": ";AACA,SAAS,kBAAkB;AAEpB,IAAM,qBAAqB,uBAAO,IAAI,eAAe;AACrD,IAAM,sBAAsB,uBAAO,IAAI,gBAAgB;AACvD,IAAM,sBAAsB,uBAAO,IAAI,gBAAgB;AAsBvD,SAAS,cAAiB,cAA6B;AAC5D,QAAM,UAAsB;AAAA,IAC1B,UAAU;AAAA,IACV,eAAe;AAAA,EACjB;AAEA,QAAM,WAAgB,SAASA,UAAS,QAAkB;AACxD,QAAI,MAAuC;AACzC,YAAM,IAAI,MAAM,kDAAkD;AAAA,IACpE;AACA,UAAM,IAAI,MAAM;AAAA,EAClB;AACA,WAAS,WAAW;AACpB,WAAS,WAAW;AAEpB,QAAM,WAAgB,SAASC,UAAS,OAAyC;AAC/E,WAAO,MAAM,SAAS,WAAW,OAAO,CAAC;AAAA,EAC3C;AACA,WAAS,WAAW;AACpB,WAAS,WAAW;AAEpB,UAAQ,WAAW;AACnB,UAAQ,WAAW;AAEnB,SAAO;AACT;",
|
|
6
6
|
"names": ["Provider", "Consumer"]
|
|
7
7
|
}
|
package/dist/react/index.js
CHANGED
|
@@ -82,7 +82,7 @@ import { Children as Children2 } from "./children";
|
|
|
82
82
|
var cache = (fn) => fn;
|
|
83
83
|
var act = async (fn) => {
|
|
84
84
|
const r = fn();
|
|
85
|
-
if (r && typeof r.then
|
|
85
|
+
if (r && typeof r.then == "function") await r;
|
|
86
86
|
};
|
|
87
87
|
function taintUniqueValue(_msg, _lifetime, _value) {
|
|
88
88
|
}
|
package/dist/react/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/react/index.ts"],
|
|
4
|
-
"sourcesContent": ["export { createElement, cloneElement, isValidElement, createRef, Fragment } from './element'\nexport type {\n ReactElement,\n ReactNode,\n Key,\n Ref,\n RefObject,\n RefCallback,\n Dispatch,\n SetStateAction,\n EffectCallback,\n DependencyList,\n} from '../core'\n\n// Lightweight functional-component alias \u2014 matches React's FC shape closely\n// enough for the common `const X: FC<P> = (props) => \u2026` pattern used in\n// tests and downstream consumer code.\nexport type FC<P = {}> = (props: P & { children?: import('../core').ReactNode }) => import('../core').ReactElement | null\nexport {\n useState,\n useReducer,\n useEffect,\n useLayoutEffect,\n useInsertionEffect,\n useRef,\n useMemo,\n useCallback,\n useContext,\n useImperativeHandle,\n useDebugValue,\n useId,\n useTransition,\n useDeferredValue,\n useSyncExternalStore,\n useSyncExternalStoreWithSelector,\n use,\n useActionState,\n useFormStatus,\n useOptimistic,\n useEffectEvent,\n startTransition,\n} from './hooks'\nexport {\n createContext,\n REACT_CONTEXT_TYPE,\n REACT_PROVIDER_TYPE,\n REACT_CONSUMER_TYPE,\n type Context,\n type ProviderExoticComponent,\n type ConsumerExoticComponent,\n} from './context'\nexport { Component, PureComponent } from './class'\nexport {\n memo, forwardRef, lazy,\n REACT_MEMO_TYPE,\n REACT_FORWARD_REF_TYPE,\n REACT_LAZY_TYPE,\n} from './memo'\nexport {\n Suspense, StrictMode, Profiler,\n REACT_SUSPENSE_TYPE,\n REACT_STRICT_MODE_TYPE,\n REACT_PROFILER_TYPE,\n} from './suspense'\nexport { REACT_PORTAL_TYPE } from './portal'\nexport { Children } from './children'\nexport { ReactSharedInternals } from './shared-internals'\n\n// Stub exports\nexport const cache = <T extends Function>(fn: T): T => fn\nexport const act = async (fn: () => any) => {\n const r = fn()\n if (r && typeof r.then
|
|
5
|
-
"mappings": ";AAAA,SAAS,eAAe,cAAc,gBAAgB,WAAW,gBAAgB;AAkBjF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,WAAW,qBAAqB;AACzC;AAAA,EACE;AAAA,EAAM;AAAA,EAAY;AAAA,EAClB;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EAAU;AAAA,EAAY;AAAA,EACtB;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,yBAAyB;AAClC,SAAS,gBAAgB;AACzB,SAAS,4BAA4B;AAcrC,SAAS,iBAAAA,gBAAe,gBAAAC,eAAc,kBAAAC,iBAAgB,aAAAC,YAAW,YAAAC,iBAAgB;AACjF;AAAA,EACE,YAAAC;AAAA,EACA,cAAAC;AAAA,EACA,aAAAC;AAAA,EACA,mBAAAC;AAAA,EACA,sBAAAC;AAAA,EACA,UAAAC;AAAA,EACA,WAAAC;AAAA,EACA,eAAAC;AAAA,EACA,cAAAC;AAAA,EACA,uBAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,SAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,wBAAAC;AAAA,EACA,OAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,mBAAAC;AAAA,OACK;AACP,SAAS,iBAAAC,sBAAqB;AAC9B,SAAS,aAAAC,YAAW,iBAAAC,sBAAqB;AACzC,SAAS,QAAAC,OAAM,cAAAC,aAAY,QAAAC,aAAY;AACvC,SAAS,YAAAC,WAAU,cAAAC,aAAY,YAAAC,iBAAgB;AAC/C,SAAS,YAAAC,iBAAgB;AAvClB,IAAM,QAAQ,CAAqB,OAAa;AAChD,IAAM,MAAM,OAAO,OAAkB;AAC1C,QAAM,IAAI,GAAG;AACb,MAAI,KAAK,OAAO,EAAE,
|
|
4
|
+
"sourcesContent": ["export { createElement, cloneElement, isValidElement, createRef, Fragment } from './element'\nexport type {\n ReactElement,\n ReactNode,\n Key,\n Ref,\n RefObject,\n RefCallback,\n Dispatch,\n SetStateAction,\n EffectCallback,\n DependencyList,\n} from '../core'\n\n// Lightweight functional-component alias \u2014 matches React's FC shape closely\n// enough for the common `const X: FC<P> = (props) => \u2026` pattern used in\n// tests and downstream consumer code.\nexport type FC<P = {}> = (props: P & { children?: import('../core').ReactNode }) => import('../core').ReactElement | null\nexport {\n useState,\n useReducer,\n useEffect,\n useLayoutEffect,\n useInsertionEffect,\n useRef,\n useMemo,\n useCallback,\n useContext,\n useImperativeHandle,\n useDebugValue,\n useId,\n useTransition,\n useDeferredValue,\n useSyncExternalStore,\n useSyncExternalStoreWithSelector,\n use,\n useActionState,\n useFormStatus,\n useOptimistic,\n useEffectEvent,\n startTransition,\n} from './hooks'\nexport {\n createContext,\n REACT_CONTEXT_TYPE,\n REACT_PROVIDER_TYPE,\n REACT_CONSUMER_TYPE,\n type Context,\n type ProviderExoticComponent,\n type ConsumerExoticComponent,\n} from './context'\nexport { Component, PureComponent } from './class'\nexport {\n memo, forwardRef, lazy,\n REACT_MEMO_TYPE,\n REACT_FORWARD_REF_TYPE,\n REACT_LAZY_TYPE,\n} from './memo'\nexport {\n Suspense, StrictMode, Profiler,\n REACT_SUSPENSE_TYPE,\n REACT_STRICT_MODE_TYPE,\n REACT_PROFILER_TYPE,\n} from './suspense'\nexport { REACT_PORTAL_TYPE } from './portal'\nexport { Children } from './children'\nexport { ReactSharedInternals } from './shared-internals'\n\n// Stub exports\nexport const cache = <T extends Function>(fn: T): T => fn\nexport const act = async (fn: () => any) => {\n const r = fn()\n if (r && typeof r.then == 'function') await r\n}\nexport function taintUniqueValue(_msg: string, _lifetime: any, _value: any): void {}\nexport function taintObjectReference(_msg: string, _object: any): void {}\n\nexport const version = '19.2.3'\n\n// Default export for `import React from 'react'` usage\nimport { createElement, cloneElement, isValidElement, createRef, Fragment } from './element'\nimport {\n useState,\n useReducer,\n useEffect,\n useLayoutEffect,\n useInsertionEffect,\n useRef,\n useMemo,\n useCallback,\n useContext,\n useImperativeHandle,\n useDebugValue,\n useId,\n useTransition,\n useDeferredValue,\n useSyncExternalStore,\n use,\n useActionState,\n useFormStatus,\n useOptimistic,\n useEffectEvent,\n startTransition,\n} from './hooks'\nimport { createContext } from './context'\nimport { Component, PureComponent } from './class'\nimport { memo, forwardRef, lazy } from './memo'\nimport { Suspense, StrictMode, Profiler } from './suspense'\nimport { Children } from './children'\n\nexport default {\n createElement,\n cloneElement,\n isValidElement,\n createRef,\n Fragment,\n useState,\n useReducer,\n useEffect,\n useLayoutEffect,\n useInsertionEffect,\n useRef,\n useMemo,\n useCallback,\n useContext,\n useImperativeHandle,\n useDebugValue,\n useId,\n useTransition,\n useDeferredValue,\n useSyncExternalStore,\n use,\n useActionState,\n useFormStatus,\n useOptimistic,\n useEffectEvent,\n startTransition,\n createContext,\n Component,\n PureComponent,\n memo,\n forwardRef,\n lazy,\n Suspense,\n StrictMode,\n Profiler,\n Children,\n version: '19.2.3',\n}\n"],
|
|
5
|
+
"mappings": ";AAAA,SAAS,eAAe,cAAc,gBAAgB,WAAW,gBAAgB;AAkBjF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AA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MAAI,KAAK,OAAO,EAAE,QAAQ,WAAY,OAAM;AAC9C;AACO,SAAS,iBAAiB,MAAc,WAAgB,QAAmB;AAAC;AAC5E,SAAS,qBAAqB,MAAc,SAAoB;AAAC;AAEjE,IAAM,UAAU;AAiCvB,IAAO,gBAAQ;AAAA,EACb,eAAAnC;AAAA,EACA,cAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,WAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,YAAAC;AAAA,EACA,WAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,oBAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC;AAAA,EACA,aAAAC;AAAA,EACA,YAAAC;AAAA,EACA,qBAAAC;AAAA,EACA,eAAAC;AAAA,EACA,OAAAC;AAAA,EACA,eAAAC;AAAA,EACA,kBAAAC;AAAA,EACA,sBAAAC;AAAA,EACA,KAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,eAAAC;AAAA,EACA,eAAAC;AAAA,EACA,gBAAAC;AAAA,EACA,iBAAAC;AAAA,EACA,eAAAC;AAAA,EACA,WAAAC;AAAA,EACA,eAAAC;AAAA,EACA,MAAAC;AAAA,EACA,YAAAC;AAAA,EACA,MAAAC;AAAA,EACA,UAAAC;AAAA,EACA,YAAAC;AAAA,EACA,UAAAC;AAAA,EACA,UAAAC;AAAA,EACA,SAAS;AACX;",
|
|
6
6
|
"names": ["createElement", "cloneElement", "isValidElement", "createRef", "Fragment", "useState", "useReducer", "useEffect", "useLayoutEffect", "useInsertionEffect", "useRef", "useMemo", "useCallback", "useContext", "useImperativeHandle", "useDebugValue", "useId", "useTransition", "useDeferredValue", "useSyncExternalStore", "use", "useActionState", "useFormStatus", "useOptimistic", "useEffectEvent", "startTransition", "createContext", "Component", "PureComponent", "memo", "forwardRef", "lazy", "Suspense", "StrictMode", "Profiler", "Children"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Fiber,
|
|
1
|
+
import type { Fiber, Hook } from '../core';
|
|
2
2
|
export interface Dispatcher {
|
|
3
3
|
useState<S>(initial: S | (() => S)): [S, (s: S | ((p: S) => S)) => void];
|
|
4
4
|
useReducer<S, A>(reducer: (s: S, a: A) => S, initial: S | any, init?: (a: any) => S): [S, (a: A) => void];
|
|
@@ -21,12 +21,9 @@ export interface Dispatcher {
|
|
|
21
21
|
}
|
|
22
22
|
interface SharedInternals {
|
|
23
23
|
H: Dispatcher | null;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
currentRoot: FiberRoot | null;
|
|
28
|
-
currentHook: Hook | null;
|
|
29
|
-
hookIndex: number;
|
|
24
|
+
F: Fiber | null;
|
|
25
|
+
K: Hook | null;
|
|
26
|
+
I: number;
|
|
30
27
|
}
|
|
31
28
|
export declare const ReactSharedInternals: SharedInternals;
|
|
32
29
|
export declare function getDispatcher(): Dispatcher;
|
|
@@ -3,12 +3,9 @@ var KEY = /* @__PURE__ */ Symbol.for("@tanstack/redact.ReactSharedInternals");
|
|
|
3
3
|
var g = globalThis;
|
|
4
4
|
var ReactSharedInternals = g[KEY] ?? (g[KEY] = {
|
|
5
5
|
H: null,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
currentRoot: null,
|
|
10
|
-
currentHook: null,
|
|
11
|
-
hookIndex: 0
|
|
6
|
+
F: null,
|
|
7
|
+
K: null,
|
|
8
|
+
I: 0
|
|
12
9
|
});
|
|
13
10
|
function getDispatcher() {
|
|
14
11
|
const d = ReactSharedInternals.H;
|
|
@@ -18,7 +15,7 @@ function getDispatcher() {
|
|
|
18
15
|
'Hooks can only be called inside a function component. If this fires during SSR/RSC, the most common cause is a component that uses client-only hooks (useState, useContext, useRouter, etc.) being rendered in the RSC server environment without a "use client" directive at the top of its file.'
|
|
19
16
|
);
|
|
20
17
|
}
|
|
21
|
-
throw new Error(
|
|
18
|
+
throw new Error();
|
|
22
19
|
}
|
|
23
20
|
return d;
|
|
24
21
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/react/shared-internals.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Fiber,
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["import type { Fiber, Hook } from '../core'\n\nexport interface Dispatcher {\n useState<S>(initial: S | (() => S)): [S, (s: S | ((p: S) => S)) => void]\n useReducer<S, A>(\n reducer: (s: S, a: A) => S,\n initial: S | any,\n init?: (a: any) => S,\n ): [S, (a: A) => void]\n useEffect(create: () => any, deps?: ReadonlyArray<unknown>): void\n useLayoutEffect(create: () => any, deps?: ReadonlyArray<unknown>): void\n useInsertionEffect(create: () => any, deps?: ReadonlyArray<unknown>): void\n useRef<T>(initial: T): { current: T }\n useMemo<T>(factory: () => T, deps?: ReadonlyArray<unknown>): T\n useCallback<T extends Function>(fn: T, deps?: ReadonlyArray<unknown>): T\n useContext<T>(ctx: any): T\n useImperativeHandle<T>(ref: any, factory: () => T, deps?: ReadonlyArray<unknown>): void\n useDebugValue<T>(value: T, formatter?: (v: T) => any): void\n useId(): string\n useTransition(): [boolean, (fn: () => void) => void]\n useDeferredValue<T>(v: T): T\n useSyncExternalStore<T>(\n subscribe: (cb: () => void) => () => void,\n getSnapshot: () => T,\n getServerSnapshot?: () => T,\n ): T\n use<T>(promiseOrContext: any): T\n}\n\ninterface SharedInternals {\n H: Dispatcher | null\n F: Fiber | null\n K: Hook | null\n I: number\n}\n\n// Stash the singleton on `globalThis` under a registered symbol. Module-scoped\n// state goes wrong fast in environments that end up with multiple copies of\n// `@tanstack/redact` in flight \u2014 most notably Cloudflare's `vite-plugin` dev\n// mode, where the worker entry inlines `@tanstack/redact` once via `noExternal`\n// while user code reaches a separate pre-bundled `deps_ssr/redact.js` copy.\n// Each copy would otherwise have its own `ReactSharedInternals.H`, so the SSR\n// dispatcher installed by one would be invisible to hooks called through the\n// other and `useContext` would explode with \"Hooks can only be called inside a\n// function component\". `Symbol.for` survives module re-evaluation and isolate\n// boundaries, giving every copy the same backing object.\nconst KEY = Symbol.for('@tanstack/redact.ReactSharedInternals')\nconst g = globalThis as unknown as { [k: symbol]: SharedInternals | undefined }\n\nexport const ReactSharedInternals: SharedInternals =\n g[KEY] ??\n (g[KEY] = {\n H: null,\n F: null,\n K: null,\n I: 0,\n })\n\nexport function getDispatcher(): Dispatcher {\n const d = ReactSharedInternals.H\n if (!d) {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error(\n 'Hooks can only be called inside a function component. ' +\n 'If this fires during SSR/RSC, the most common cause is a component that uses client-only hooks ' +\n '(useState, useContext, useRouter, etc.) being rendered in the RSC server environment without a ' +\n '\"use client\" directive at the top of its file.',\n )\n }\n throw new Error()\n }\n return d\n}\n"],
|
|
5
|
+
"mappings": ";AA8CA,IAAM,MAAM,uBAAO,IAAI,uCAAuC;AAC9D,IAAM,IAAI;AAEH,IAAM,uBACX,EAAE,GAAG,MACJ,EAAE,GAAG,IAAI;AAAA,EACR,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AAAA,EACH,GAAG;AACL;AAEK,SAAS,gBAA4B;AAC1C,QAAM,IAAI,qBAAqB;AAC/B,MAAI,CAAC,GAAG;AACN,QAAI,MAAuC;AACzC,YAAM,IAAI;AAAA,QACR;AAAA,MAIF;AAAA,IACF;AACA,UAAM,IAAI,MAAM;AAAA,EAClB;AACA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/server/stream.d.ts
CHANGED
|
@@ -19,6 +19,10 @@ export interface StreamOptions {
|
|
|
19
19
|
export interface ReadableStreamResult extends ReadableStream<Uint8Array> {
|
|
20
20
|
allReady: Promise<void>;
|
|
21
21
|
}
|
|
22
|
+
export interface PipeableWritable {
|
|
23
|
+
write(chunk: string): unknown;
|
|
24
|
+
end(): unknown;
|
|
25
|
+
}
|
|
22
26
|
export interface OrchestratorState {
|
|
23
27
|
nextId: number;
|
|
24
28
|
pending: Set<Promise<void>>;
|
|
@@ -29,7 +33,7 @@ type Emit = (chunk: string) => void;
|
|
|
29
33
|
export declare function streamHtml(children: ReactNode, emit: Emit, options: StreamOptions, state: OrchestratorState): Promise<void>;
|
|
30
34
|
export declare function renderToReadableStream(children: ReactNode, options?: StreamOptions): Promise<ReadableStreamResult>;
|
|
31
35
|
export interface PipeableHandle {
|
|
32
|
-
pipe<T extends
|
|
36
|
+
pipe<T extends PipeableWritable>(dest: T): T;
|
|
33
37
|
abort(reason?: unknown): void;
|
|
34
38
|
}
|
|
35
39
|
export interface PipeableOptions extends StreamOptions {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/server/stream.ts"],
|
|
4
|
-
"sourcesContent": ["import type { ReactNode } from '../core'\nimport {\n beginSSR,\n endSSR,\n installSSRDispatcher,\n uninstallSSRDispatcher,\n applyContextSnapshot,\n} from './dispatcher'\nimport { walk, type SuspendedBoundary } from './walk'\nimport { BOUNDARY_REVEAL_RUNTIME, revealScript } from './bootstrap-script'\nimport { escapeScript } from './escape'\n\nexport interface StreamOptions {\n identifierPrefix?: string\n nonce?: string\n bootstrapScriptContent?: string | ReadonlyArray<string>\n bootstrapScripts?: ReadonlyArray<string | { src: string; async?: boolean; nonce?: string }>\n bootstrapModules?: ReadonlyArray<string | { src: string; nonce?: string }>\n onError?: (error: unknown) => string | void\n signal?: AbortSignal\n progressiveChunkSize?: number\n}\n\nexport interface ReadableStreamResult extends ReadableStream<Uint8Array> {\n allReady: Promise<void>\n}\n\nexport interface OrchestratorState {\n nextId: number\n pending: Set<Promise<void>>\n closed: boolean\n errored: unknown | null\n}\n\ntype Emit = (chunk: string) => void\n\nexport async function streamHtml(\n children: ReactNode,\n emit: Emit,\n options: StreamOptions,\n state: OrchestratorState,\n): Promise<void> {\n installSSRDispatcher()\n beginSSR(options.identifierPrefix)\n const nonce = options.nonce\n\n try {\n const boundaries: SuspendedBoundary[] = []\n\n // Buffer shell + bootstrap into a string[] and flush as a single emit.\n // Per-emit overhead in renderToReadableStream is TextEncoder.encode +\n // controller.enqueue \u2014 each walkHost normally fires 3+ emits (opening\n // tag, per-attribute, closing bracket), which for a ~30-component tree\n // is ~100 stream-controller round-trips. Batching collapses those into\n // one encode and one enqueue per shell \u2014 measured ~2-4% of total SSR\n // time on CPU profiles.\n const shellChunks: string[] = []\n const bufferedEmit: Emit = (chunk) => {\n shellChunks.push(chunk)\n }\n\n // 1. Render the shell. A root-level `use(promise)` has no Suspense\n // boundary to capture it, but App Router SSR commonly suspends at this\n // level while resolving the RSC stream. Wait and retry without leaking\n // partial shell chunks or boundary ids from the aborted attempt.\n let shellRendered = false\n let rootRetries = 0\n while (!shellRendered) {\n const chunkCount = shellChunks.length\n const boundaryCount = boundaries.length\n const nextId = state.nextId\n try {\n walk(children, {\n emit: bufferedEmit,\n onSuspend: (b) => boundaries.push(b),\n nextBoundaryId: () => state.nextId++,\n })\n shellRendered = true\n } catch (err) {\n shellChunks.length = chunkCount\n boundaries.length = boundaryCount\n state.nextId = nextId\n if (!isThenable(err)) throw err\n if (++rootRetries > 50) {\n throw new Error('renderToReadableStream exceeded 50 root suspension retries.')\n }\n await err\n }\n }\n\n // 2. Inject runtime + bootstrap scripts (once, after shell). Skip the\n // reveal/event-replay runtime when nothing needs it \u2014 no suspensions to\n // reveal and no bootstrap scripts to guard against early user input. That\n // keeps fully-static SSR responses byte-equivalent to a plain walk and\n // matches React's behavior where `renderToReadableStream` of a static\n // tree emits only the markup.\n const hasBootstrap =\n bootstrapScriptContentToArray(options.bootstrapScriptContent).length > 0 ||\n (options.bootstrapScripts?.length ?? 0) > 0 ||\n (options.bootstrapModules?.length ?? 0) > 0\n if (boundaries.length > 0 || hasBootstrap) {\n shellChunks.push(`<script${nonce ? ` nonce=\"${nonce}\"` : ''}>${BOUNDARY_REVEAL_RUNTIME}</script>`)\n for (const content of bootstrapScriptContentToArray(options.bootstrapScriptContent)) {\n shellChunks.push(inlineBootstrapTag(content, nonce))\n }\n for (const s of options.bootstrapScripts ?? []) {\n shellChunks.push(bootstrapTag(s, 'script', nonce))\n }\n for (const m of options.bootstrapModules ?? []) {\n shellChunks.push(bootstrapTag(m, 'module', nonce))\n }\n }\n\n if (shellChunks.length) emit(normalizeDocumentShell(shellChunks.join('')))\n\n // 3. Stream suspended boundaries as they resolve\n for (const b of boundaries) streamBoundary(b, emit, options, state)\n await drain(state)\n } catch (err) {\n state.errored = err\n if (options.onError) options.onError(err)\n throw err\n } finally {\n endSSR()\n uninstallSSRDispatcher()\n state.closed = true\n }\n}\n\nfunction streamBoundary(\n b: SuspendedBoundary,\n emit: Emit,\n options: StreamOptions,\n state: OrchestratorState,\n): void {\n const task = (async () => {\n try {\n await b.thenable\n } catch (err) {\n if (options.onError) options.onError(err)\n }\n if (state.closed) return\n\n // Re-render the boundary's children into a string, restoring the\n // provider stack from when the boundary first suspended.\n const parts: string[] = []\n const sub: SuspendedBoundary[] = []\n const restore = applyContextSnapshot(b.contextSnapshot)\n try {\n walk(b.children, {\n emit: (s) => parts.push(s),\n onSuspend: (n) => sub.push(n),\n nextBoundaryId: () => state.nextId++,\n })\n } catch (err) {\n if (options.onError) options.onError(err)\n restore()\n return\n }\n restore()\n\n emit(`<div hidden id=\"S:${b.id}\">${parts.join('')}</div>${revealScript(b.id, options.nonce)}`)\n\n // Recurse: any nested suspensions inside the now-revealed content\n for (const s of sub) streamBoundary(s, emit, options, state)\n })()\n state.pending.add(task)\n task.finally(() => state.pending.delete(task))\n}\n\nasync function drain(state: OrchestratorState): Promise<void> {\n while (state.pending.size > 0) {\n await Promise.race(state.pending)\n }\n}\n\nfunction isThenable(value: unknown): value is Promise<unknown> {\n return !!value && typeof (value as { then?: unknown }).then === 'function'\n}\n\nfunction bootstrapScriptContentToArray(\n content: StreamOptions['bootstrapScriptContent'],\n): string[] {\n if (content === undefined) return []\n return typeof content === 'string' ? [content] : [...content]\n}\n\nfunction inlineBootstrapTag(content: string, defaultNonce: string | undefined): string {\n const nAttr = defaultNonce ? ` nonce=\"${defaultNonce}\"` : ''\n return `<script${nAttr}>${escapeScript(content)}</script>`\n}\n\nfunction normalizeDocumentShell(html: string): string {\n const doctypeIndex = html.indexOf('<!DOCTYPE html><html')\n if (doctypeIndex <= 0) return html\n\n const headPrefix = html.slice(0, doctypeIndex)\n if (!isHeadPrefix(headPrefix)) return html\n\n const documentHtml = html.slice(doctypeIndex)\n const headOpen = documentHtml.match(/<head(?:\\s[^>]*)?>/)\n if (!headOpen || headOpen.index === undefined) return html\n\n const insertAt = headOpen.index + headOpen[0].length\n return documentHtml.slice(0, insertAt) + headPrefix + documentHtml.slice(insertAt)\n}\n\nfunction isHeadPrefix(value: string): boolean {\n if (!value) return false\n return stripLeadingHeadTags(value).trim() === ''\n}\n\nfunction stripLeadingHeadTags(value: string): string {\n let rest = value\n let changed = true\n while (changed) {\n changed = false\n const next = rest.replace(\n /^\\s*(?:<meta\\b[^>]*>|<link\\b[^>]*>|<base\\b[^>]*>|<title\\b[^>]*>[\\s\\S]*?<\\/title>|<style\\b[^>]*>[\\s\\S]*?<\\/style>|<script\\b[^>]*>[\\s\\S]*?<\\/script>)/i,\n '',\n )\n if (next !== rest) {\n rest = next\n changed = true\n }\n }\n return rest\n}\n\nfunction bootstrapTag(\n entry: string | { src: string; async?: boolean; nonce?: string },\n kind: 'script' | 'module',\n defaultNonce: string | undefined,\n): string {\n const src = typeof entry === 'string' ? entry : entry.src\n const nonce = typeof entry === 'string' ? defaultNonce : entry.nonce ?? defaultNonce\n const nAttr = nonce ? ` nonce=\"${nonce}\"` : ''\n if (kind === 'module') return `<script type=\"module\"${nAttr} src=\"${src}\"></script>`\n return `<script async${nAttr} src=\"${src}\"></script>`\n}\n\n// ---------------------------------------------------------------------------\n// Web Streams: renderToReadableStream\n// ---------------------------------------------------------------------------\n\nexport function renderToReadableStream(\n children: ReactNode,\n options: StreamOptions = {},\n): Promise<ReadableStreamResult> {\n const state: OrchestratorState = {\n nextId: 0,\n pending: new Set(),\n closed: false,\n errored: null,\n }\n const encoder = new TextEncoder()\n\n let allReadyResolve!: () => void\n let allReadyReject!: (e: unknown) => void\n const allReady = new Promise<void>((r, rej) => {\n allReadyResolve = r\n allReadyReject = rej\n })\n\n const stream = new ReadableStream<Uint8Array>({\n start(controller) {\n const emit = (chunk: string) => {\n try {\n controller.enqueue(encoder.encode(chunk))\n } catch {}\n }\n\n streamHtml(children, emit, options, state).then(\n () => {\n try {\n controller.close()\n } catch {}\n allReadyResolve()\n },\n (err) => {\n try {\n controller.error(err)\n } catch {}\n allReadyReject(err)\n },\n )\n\n options.signal?.addEventListener('abort', () => {\n state.closed = true\n try {\n controller.close()\n } catch {}\n })\n },\n })\n\n return Promise.resolve(Object.assign(stream, { allReady }))\n}\n\n// ---------------------------------------------------------------------------\n// Node Streams: renderToPipeableStream\n// ---------------------------------------------------------------------------\n\nexport interface PipeableHandle {\n pipe<T extends NodeJS.WritableStream>(dest: T): T\n abort(reason?: unknown): void\n}\n\nexport interface PipeableOptions extends StreamOptions {\n onShellReady?: () => void\n onShellError?: (err: unknown) => void\n onAllReady?: () => void\n}\n\nexport function renderToPipeableStream(\n children: ReactNode,\n options: PipeableOptions = {},\n): PipeableHandle {\n const state: OrchestratorState = {\n nextId: 0,\n pending: new Set(),\n closed: false,\n errored: null,\n }\n\n const buffers: string[] = []\n let dest: NodeJS.WritableStream | null = null\n let shellReady = false\n let finished = false\n let aborted = false\n\n const flushTo = (w: NodeJS.WritableStream) => {\n if (!buffers.length) return\n for (const b of buffers) w.write(b)\n buffers.length = 0\n }\n\n const emit: Emit = (chunk) => {\n if (aborted || finished) return\n if (dest) dest.write(chunk)\n else buffers.push(chunk)\n }\n\n // Kick off rendering\n streamHtml(children, emit, options, state).then(\n () => {\n finished = true\n if (dest) dest.end()\n options.onAllReady?.()\n },\n (err) => {\n if (!shellReady) {\n options.onShellError?.(err)\n } else {\n options.onError?.(err)\n if (dest) dest.end()\n }\n },\n )\n\n // We call onShellReady once the first synchronous emit has landed.\n // streamHtml above runs the shell synchronously before the first await in drain(),\n // so we can schedule onShellReady right after the first microtask.\n queueMicrotask(() => {\n if (aborted || finished) return\n shellReady = true\n options.onShellReady?.()\n })\n\n return {\n pipe<T extends NodeJS.WritableStream>(target: T): T {\n dest = target\n flushTo(target)\n if (finished) target.end()\n return target\n },\n abort(_reason?: unknown) {\n aborted = true\n state.closed = true\n if (dest) dest.end()\n },\n }\n}\n"],
|
|
5
|
-
"mappings": ";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAoC;AAC7C,SAAS,yBAAyB,oBAAoB;AACtD,SAAS,oBAAoB;
|
|
4
|
+
"sourcesContent": ["import type { ReactNode } from '../core'\nimport {\n beginSSR,\n endSSR,\n installSSRDispatcher,\n uninstallSSRDispatcher,\n applyContextSnapshot,\n} from './dispatcher'\nimport { walk, type SuspendedBoundary } from './walk'\nimport { BOUNDARY_REVEAL_RUNTIME, revealScript } from './bootstrap-script'\nimport { escapeScript } from './escape'\n\nexport interface StreamOptions {\n identifierPrefix?: string\n nonce?: string\n bootstrapScriptContent?: string | ReadonlyArray<string>\n bootstrapScripts?: ReadonlyArray<string | { src: string; async?: boolean; nonce?: string }>\n bootstrapModules?: ReadonlyArray<string | { src: string; nonce?: string }>\n onError?: (error: unknown) => string | void\n signal?: AbortSignal\n progressiveChunkSize?: number\n}\n\nexport interface ReadableStreamResult extends ReadableStream<Uint8Array> {\n allReady: Promise<void>\n}\n\nexport interface PipeableWritable {\n write(chunk: string): unknown\n end(): unknown\n}\n\nexport interface OrchestratorState {\n nextId: number\n pending: Set<Promise<void>>\n closed: boolean\n errored: unknown | null\n}\n\ntype Emit = (chunk: string) => void\n\nexport async function streamHtml(\n children: ReactNode,\n emit: Emit,\n options: StreamOptions,\n state: OrchestratorState,\n): Promise<void> {\n installSSRDispatcher()\n beginSSR(options.identifierPrefix)\n const nonce = options.nonce\n\n try {\n const boundaries: SuspendedBoundary[] = []\n\n // Buffer shell + bootstrap into a string[] and flush as a single emit.\n // Per-emit overhead in renderToReadableStream is TextEncoder.encode +\n // controller.enqueue \u2014 each walkHost normally fires 3+ emits (opening\n // tag, per-attribute, closing bracket), which for a ~30-component tree\n // is ~100 stream-controller round-trips. Batching collapses those into\n // one encode and one enqueue per shell \u2014 measured ~2-4% of total SSR\n // time on CPU profiles.\n const shellChunks: string[] = []\n const bufferedEmit: Emit = (chunk) => {\n shellChunks.push(chunk)\n }\n\n // 1. Render the shell. A root-level `use(promise)` has no Suspense\n // boundary to capture it, but App Router SSR commonly suspends at this\n // level while resolving the RSC stream. Wait and retry without leaking\n // partial shell chunks or boundary ids from the aborted attempt.\n let shellRendered = false\n let rootRetries = 0\n while (!shellRendered) {\n const chunkCount = shellChunks.length\n const boundaryCount = boundaries.length\n const nextId = state.nextId\n try {\n walk(children, {\n emit: bufferedEmit,\n onSuspend: (b) => boundaries.push(b),\n nextBoundaryId: () => state.nextId++,\n })\n shellRendered = true\n } catch (err) {\n shellChunks.length = chunkCount\n boundaries.length = boundaryCount\n state.nextId = nextId\n if (!isThenable(err)) throw err\n if (++rootRetries > 50) {\n throw new Error('renderToReadableStream exceeded 50 root suspension retries.')\n }\n await err\n }\n }\n\n // 2. Inject runtime + bootstrap scripts (once, after shell). Skip the\n // reveal/event-replay runtime when nothing needs it \u2014 no suspensions to\n // reveal and no bootstrap scripts to guard against early user input. That\n // keeps fully-static SSR responses byte-equivalent to a plain walk and\n // matches React's behavior where `renderToReadableStream` of a static\n // tree emits only the markup.\n const hasBootstrap =\n bootstrapScriptContentToArray(options.bootstrapScriptContent).length > 0 ||\n (options.bootstrapScripts?.length ?? 0) > 0 ||\n (options.bootstrapModules?.length ?? 0) > 0\n if (boundaries.length > 0 || hasBootstrap) {\n shellChunks.push(`<script${nonce ? ` nonce=\"${nonce}\"` : ''}>${BOUNDARY_REVEAL_RUNTIME}</script>`)\n for (const content of bootstrapScriptContentToArray(options.bootstrapScriptContent)) {\n shellChunks.push(inlineBootstrapTag(content, nonce))\n }\n for (const s of options.bootstrapScripts ?? []) {\n shellChunks.push(bootstrapTag(s, 'script', nonce))\n }\n for (const m of options.bootstrapModules ?? []) {\n shellChunks.push(bootstrapTag(m, 'module', nonce))\n }\n }\n\n if (shellChunks.length) emit(normalizeDocumentShell(shellChunks.join('')))\n\n // 3. Stream suspended boundaries as they resolve\n for (const b of boundaries) streamBoundary(b, emit, options, state)\n await drain(state)\n } catch (err) {\n state.errored = err\n if (options.onError) options.onError(err)\n throw err\n } finally {\n endSSR()\n uninstallSSRDispatcher()\n state.closed = true\n }\n}\n\nfunction streamBoundary(\n b: SuspendedBoundary,\n emit: Emit,\n options: StreamOptions,\n state: OrchestratorState,\n): void {\n const task = (async () => {\n try {\n await b.thenable\n } catch (err) {\n if (options.onError) options.onError(err)\n }\n if (state.closed) return\n\n // Re-render the boundary's children into a string, restoring the\n // provider stack from when the boundary first suspended.\n const parts: string[] = []\n const sub: SuspendedBoundary[] = []\n const restore = applyContextSnapshot(b.contextSnapshot)\n try {\n walk(b.children, {\n emit: (s) => parts.push(s),\n onSuspend: (n) => sub.push(n),\n nextBoundaryId: () => state.nextId++,\n })\n } catch (err) {\n if (options.onError) options.onError(err)\n restore()\n return\n }\n restore()\n\n emit(`<div hidden id=\"S:${b.id}\">${parts.join('')}</div>${revealScript(b.id, options.nonce)}`)\n\n // Recurse: any nested suspensions inside the now-revealed content\n for (const s of sub) streamBoundary(s, emit, options, state)\n })()\n state.pending.add(task)\n task.finally(() => state.pending.delete(task))\n}\n\nasync function drain(state: OrchestratorState): Promise<void> {\n while (state.pending.size > 0) {\n await Promise.race(state.pending)\n }\n}\n\nfunction isThenable(value: unknown): value is Promise<unknown> {\n return !!value && typeof (value as { then?: unknown }).then === 'function'\n}\n\nfunction bootstrapScriptContentToArray(\n content: StreamOptions['bootstrapScriptContent'],\n): string[] {\n if (content === undefined) return []\n return typeof content === 'string' ? [content] : [...content]\n}\n\nfunction inlineBootstrapTag(content: string, defaultNonce: string | undefined): string {\n const nAttr = defaultNonce ? ` nonce=\"${defaultNonce}\"` : ''\n return `<script${nAttr}>${escapeScript(content)}</script>`\n}\n\nfunction normalizeDocumentShell(html: string): string {\n const doctypeIndex = html.indexOf('<!DOCTYPE html><html')\n if (doctypeIndex <= 0) return html\n\n const headPrefix = html.slice(0, doctypeIndex)\n if (!isHeadPrefix(headPrefix)) return html\n\n const documentHtml = html.slice(doctypeIndex)\n const headOpen = documentHtml.match(/<head(?:\\s[^>]*)?>/)\n if (!headOpen || headOpen.index === undefined) return html\n\n const insertAt = headOpen.index + headOpen[0].length\n return documentHtml.slice(0, insertAt) + headPrefix + documentHtml.slice(insertAt)\n}\n\nfunction isHeadPrefix(value: string): boolean {\n if (!value) return false\n return stripLeadingHeadTags(value).trim() === ''\n}\n\nfunction stripLeadingHeadTags(value: string): string {\n let rest = value\n let changed = true\n while (changed) {\n changed = false\n const next = rest.replace(\n /^\\s*(?:<meta\\b[^>]*>|<link\\b[^>]*>|<base\\b[^>]*>|<title\\b[^>]*>[\\s\\S]*?<\\/title>|<style\\b[^>]*>[\\s\\S]*?<\\/style>|<script\\b[^>]*>[\\s\\S]*?<\\/script>)/i,\n '',\n )\n if (next !== rest) {\n rest = next\n changed = true\n }\n }\n return rest\n}\n\nfunction bootstrapTag(\n entry: string | { src: string; async?: boolean; nonce?: string },\n kind: 'script' | 'module',\n defaultNonce: string | undefined,\n): string {\n const src = typeof entry === 'string' ? entry : entry.src\n const nonce = typeof entry === 'string' ? defaultNonce : entry.nonce ?? defaultNonce\n const nAttr = nonce ? ` nonce=\"${nonce}\"` : ''\n if (kind === 'module') return `<script type=\"module\"${nAttr} src=\"${src}\"></script>`\n return `<script async${nAttr} src=\"${src}\"></script>`\n}\n\n// ---------------------------------------------------------------------------\n// Web Streams: renderToReadableStream\n// ---------------------------------------------------------------------------\n\nexport function renderToReadableStream(\n children: ReactNode,\n options: StreamOptions = {},\n): Promise<ReadableStreamResult> {\n const state: OrchestratorState = {\n nextId: 0,\n pending: new Set(),\n closed: false,\n errored: null,\n }\n const encoder = new TextEncoder()\n\n let allReadyResolve!: () => void\n let allReadyReject!: (e: unknown) => void\n const allReady = new Promise<void>((r, rej) => {\n allReadyResolve = r\n allReadyReject = rej\n })\n\n const stream = new ReadableStream<Uint8Array>({\n start(controller) {\n const emit = (chunk: string) => {\n try {\n controller.enqueue(encoder.encode(chunk))\n } catch {}\n }\n\n streamHtml(children, emit, options, state).then(\n () => {\n try {\n controller.close()\n } catch {}\n allReadyResolve()\n },\n (err) => {\n try {\n controller.error(err)\n } catch {}\n allReadyReject(err)\n },\n )\n\n options.signal?.addEventListener('abort', () => {\n state.closed = true\n try {\n controller.close()\n } catch {}\n })\n },\n })\n\n return Promise.resolve(Object.assign(stream, { allReady }))\n}\n\n// ---------------------------------------------------------------------------\n// Node Streams: renderToPipeableStream\n// ---------------------------------------------------------------------------\n\nexport interface PipeableHandle {\n pipe<T extends PipeableWritable>(dest: T): T\n abort(reason?: unknown): void\n}\n\nexport interface PipeableOptions extends StreamOptions {\n onShellReady?: () => void\n onShellError?: (err: unknown) => void\n onAllReady?: () => void\n}\n\nexport function renderToPipeableStream(\n children: ReactNode,\n options: PipeableOptions = {},\n): PipeableHandle {\n const state: OrchestratorState = {\n nextId: 0,\n pending: new Set(),\n closed: false,\n errored: null,\n }\n\n const buffers: string[] = []\n let dest: PipeableWritable | null = null\n let shellReady = false\n let finished = false\n let aborted = false\n\n const flushTo = (w: PipeableWritable) => {\n if (!buffers.length) return\n for (const b of buffers) w.write(b)\n buffers.length = 0\n }\n\n const emit: Emit = (chunk) => {\n if (aborted || finished) return\n if (dest) dest.write(chunk)\n else buffers.push(chunk)\n }\n\n // Kick off rendering\n streamHtml(children, emit, options, state).then(\n () => {\n finished = true\n if (dest) dest.end()\n options.onAllReady?.()\n },\n (err) => {\n if (!shellReady) {\n options.onShellError?.(err)\n } else {\n options.onError?.(err)\n if (dest) dest.end()\n }\n },\n )\n\n // We call onShellReady once the first synchronous emit has landed.\n // streamHtml above runs the shell synchronously before the first await in drain(),\n // so we can schedule onShellReady right after the first microtask.\n queueMicrotask(() => {\n if (aborted || finished) return\n shellReady = true\n options.onShellReady?.()\n })\n\n return {\n pipe<T extends PipeableWritable>(target: T): T {\n dest = target\n flushTo(target)\n if (finished) target.end()\n return target\n },\n abort(_reason?: unknown) {\n aborted = true\n state.closed = true\n if (dest) dest.end()\n },\n }\n}\n"],
|
|
5
|
+
"mappings": ";AACA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,YAAoC;AAC7C,SAAS,yBAAyB,oBAAoB;AACtD,SAAS,oBAAoB;AA+B7B,eAAsB,WACpB,UACA,MACA,SACA,OACe;AACf,uBAAqB;AACrB,WAAS,QAAQ,gBAAgB;AACjC,QAAM,QAAQ,QAAQ;AAEtB,MAAI;AACF,UAAM,aAAkC,CAAC;AASzC,UAAM,cAAwB,CAAC;AAC/B,UAAM,eAAqB,CAAC,UAAU;AACpC,kBAAY,KAAK,KAAK;AAAA,IACxB;AAMA,QAAI,gBAAgB;AACpB,QAAI,cAAc;AAClB,WAAO,CAAC,eAAe;AACrB,YAAM,aAAa,YAAY;AAC/B,YAAM,gBAAgB,WAAW;AACjC,YAAM,SAAS,MAAM;AACrB,UAAI;AACF,aAAK,UAAU;AAAA,UACb,MAAM;AAAA,UACN,WAAW,CAAC,MAAM,WAAW,KAAK,CAAC;AAAA,UACnC,gBAAgB,MAAM,MAAM;AAAA,QAC9B,CAAC;AACD,wBAAgB;AAAA,MAClB,SAAS,KAAK;AACZ,oBAAY,SAAS;AACrB,mBAAW,SAAS;AACpB,cAAM,SAAS;AACf,YAAI,CAAC,WAAW,GAAG,EAAG,OAAM;AAC5B,YAAI,EAAE,cAAc,IAAI;AACtB,gBAAM,IAAI,MAAM,6DAA6D;AAAA,QAC/E;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAQA,UAAM,eACJ,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aAAa;AAAA,IACvB;AAAA,IACA,CAAC,QAAQ;AACP,UAAI,CAAC,YAAY;AACf,gBAAQ,eAAe,GAAG;AAAA,MAC5B,OAAO;AACL,gBAAQ,UAAU,GAAG;AACrB,YAAI,KAAM,MAAK,IAAI;AAAA,MACrB;AAAA,IACF;AAAA,EACF;AAKA,iBAAe,MAAM;AACnB,QAAI,WAAW,SAAU;AACzB,iBAAa;AACb,YAAQ,eAAe;AAAA,EACzB,CAAC;AAED,SAAO;AAAA,IACL,KAAiC,QAAc;AAC7C,aAAO;AACP,cAAQ,MAAM;AACd,UAAI,SAAU,QAAO,IAAI;AACzB,aAAO;AAAA,IACT;AAAA,IACA,MAAM,SAAmB;AACvB,gBAAU;AACV,YAAM,SAAS;AACf,UAAI,KAAM,MAAK,IAAI;AAAA,IACrB;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
package/src/core/internal.ts
CHANGED
|
@@ -16,31 +16,17 @@ export const enum FiberTag {
|
|
|
16
16
|
Root = 12,
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
export const enum FiberFlag {
|
|
20
|
-
None = 0,
|
|
21
|
-
Placement = 1 << 0,
|
|
22
|
-
Update = 1 << 1,
|
|
23
|
-
Deletion = 1 << 2,
|
|
24
|
-
Ref = 1 << 3,
|
|
25
|
-
Effect = 1 << 4,
|
|
26
|
-
LayoutEffect = 1 << 5,
|
|
27
|
-
ContentReset = 1 << 6,
|
|
28
|
-
DidCapture = 1 << 7,
|
|
29
|
-
}
|
|
30
|
-
|
|
31
19
|
export interface Hook {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
20
|
+
s: any
|
|
21
|
+
q: any
|
|
22
|
+
d: any
|
|
23
|
+
c: any
|
|
24
|
+
n: Hook | null
|
|
37
25
|
}
|
|
38
26
|
|
|
39
27
|
export interface Effect {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
destroy: (() => void) | void
|
|
43
|
-
deps: ReadonlyArray<unknown> | undefined
|
|
28
|
+
t: 0 | 1
|
|
29
|
+
c: () => any
|
|
44
30
|
}
|
|
45
31
|
|
|
46
32
|
export interface Fiber {
|
|
@@ -48,34 +34,31 @@ export interface Fiber {
|
|
|
48
34
|
type: any
|
|
49
35
|
key: string | null
|
|
50
36
|
ref: Ref<any> | null
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
37
|
+
pp: any
|
|
38
|
+
mp: any
|
|
39
|
+
ms: any
|
|
40
|
+
sn: any
|
|
55
41
|
dom: Node | null
|
|
56
42
|
parent: Fiber | null
|
|
57
43
|
child: Fiber | null
|
|
58
44
|
sibling: Fiber | null
|
|
59
45
|
hooks: Hook | null
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
flags: FiberFlag
|
|
64
|
-
dirty: boolean
|
|
65
|
-
unmounted: boolean
|
|
46
|
+
cu: Array<() => void> | null
|
|
47
|
+
dy: boolean
|
|
48
|
+
um: boolean
|
|
66
49
|
root: FiberRoot | null
|
|
67
50
|
}
|
|
68
51
|
|
|
69
52
|
export interface FiberRoot {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
53
|
+
c: Element | DocumentFragment
|
|
54
|
+
r: Fiber
|
|
55
|
+
p: Set<Fiber>
|
|
56
|
+
s: boolean
|
|
57
|
+
re?: ((err: unknown) => void) | undefined
|
|
58
|
+
ce?: ((err: unknown) => void) | undefined
|
|
59
|
+
ue?: ((err: unknown) => void) | undefined
|
|
60
|
+
i: string
|
|
61
|
+
h: boolean
|
|
79
62
|
}
|
|
80
63
|
|
|
81
64
|
export function createFiber(tag: FiberTag, type: any, key: string | null): Fiber {
|
|
@@ -84,21 +67,18 @@ export function createFiber(tag: FiberTag, type: any, key: string | null): Fiber
|
|
|
84
67
|
type,
|
|
85
68
|
key,
|
|
86
69
|
ref: null,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
70
|
+
pp: null,
|
|
71
|
+
mp: null,
|
|
72
|
+
ms: null,
|
|
73
|
+
sn: null,
|
|
91
74
|
dom: null,
|
|
92
75
|
parent: null,
|
|
93
76
|
child: null,
|
|
94
77
|
sibling: null,
|
|
95
78
|
hooks: null,
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
flags: FiberFlag.None,
|
|
100
|
-
dirty: false,
|
|
101
|
-
unmounted: false,
|
|
79
|
+
cu: null,
|
|
80
|
+
dy: false,
|
|
81
|
+
um: false,
|
|
102
82
|
root: null,
|
|
103
83
|
}
|
|
104
84
|
}
|