@nifrajs/web-react 4.0.0 → 5.0.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.
Files changed (61) hide show
  1. package/dist/auth.d.ts.map +1 -1
  2. package/dist/auth.js +39 -18
  3. package/dist/auth.js.map +1 -1
  4. package/dist/react-dom-server.js +1 -1
  5. package/dist/route-props.d.ts.map +1 -1
  6. package/dist/route-props.js +1 -0
  7. package/dist/route-props.js.map +1 -1
  8. package/dist/server-components/client.d.ts +3 -0
  9. package/dist/server-components/client.d.ts.map +1 -0
  10. package/dist/server-components/client.js +167 -0
  11. package/dist/server-components/client.js.map +1 -0
  12. package/dist/server-components/flight.d.ts +4 -0
  13. package/dist/server-components/flight.d.ts.map +1 -0
  14. package/dist/server-components/flight.js +87 -0
  15. package/dist/server-components/flight.js.map +1 -0
  16. package/dist/server-components/guard.d.ts +8 -0
  17. package/dist/server-components/guard.d.ts.map +1 -0
  18. package/dist/server-components/guard.js +139 -0
  19. package/dist/server-components/guard.js.map +1 -0
  20. package/dist/server-components/jsx-dev-runtime.d.ts +8 -0
  21. package/dist/server-components/jsx-dev-runtime.d.ts.map +1 -0
  22. package/dist/server-components/jsx-dev-runtime.js +12 -0
  23. package/dist/server-components/jsx-dev-runtime.js.map +1 -0
  24. package/dist/server-components/jsx-runtime.d.ts +5 -0
  25. package/dist/server-components/jsx-runtime.d.ts.map +1 -0
  26. package/dist/server-components/jsx-runtime.js +14 -0
  27. package/dist/server-components/jsx-runtime.js.map +1 -0
  28. package/dist/server-components/nested.d.ts +11 -0
  29. package/dist/server-components/nested.d.ts.map +1 -0
  30. package/dist/server-components/nested.js +12 -0
  31. package/dist/server-components/nested.js.map +1 -0
  32. package/dist/server-components/nested.props.d.ts +5 -0
  33. package/dist/server-components/nested.props.d.ts.map +1 -0
  34. package/dist/server-components/nested.props.js +3 -0
  35. package/dist/server-components/nested.props.js.map +1 -0
  36. package/dist/server-components/outlet.d.ts +19 -0
  37. package/dist/server-components/outlet.d.ts.map +1 -0
  38. package/dist/server-components/outlet.js +76 -0
  39. package/dist/server-components/outlet.js.map +1 -0
  40. package/dist/server-components/rsc.d.ts +4 -0
  41. package/dist/server-components/rsc.d.ts.map +1 -0
  42. package/dist/server-components/rsc.js +33 -0
  43. package/dist/server-components/rsc.js.map +1 -0
  44. package/dist/server-components/server.d.ts +4 -0
  45. package/dist/server-components/server.d.ts.map +1 -0
  46. package/dist/server-components/server.js +34 -0
  47. package/dist/server-components/server.js.map +1 -0
  48. package/package.json +63 -9
  49. package/src/auth.ts +34 -18
  50. package/src/react-dom-server.ts +1 -1
  51. package/src/route-props.ts +1 -0
  52. package/src/server-components/client.ts +176 -0
  53. package/src/server-components/flight.ts +87 -0
  54. package/src/server-components/guard.ts +199 -0
  55. package/src/server-components/jsx-dev-runtime.ts +27 -0
  56. package/src/server-components/jsx-runtime.ts +19 -0
  57. package/src/server-components/nested.props.ts +2 -0
  58. package/src/server-components/nested.ts +18 -0
  59. package/src/server-components/outlet.ts +109 -0
  60. package/src/server-components/rsc.ts +39 -0
  61. package/src/server-components/server.ts +52 -0
@@ -1 +1 @@
1
- {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,KAAK,UAAU,EAEf,KAAK,OAAO,EACZ,KAAK,aAAa,EAClB,KAAK,cAAc,EACpB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAGL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAA;AAEd,YAAY,EAAE,OAAO,EAAE,CAAA;AACvB,MAAM,MAAM,UAAU,GAAG,SAAS,GAAG,eAAe,GAAG,iBAAiB,CAAA;AAExE,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAA;IAC3B,QAAQ,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAA;IAChC,sFAAsF;IACtF,QAAQ,CAAC,OAAO,EAAE,MA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,MAAM,EAAE,OAAO,CAAC,EAAE,aAAa,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;IAC/E,QAAQ,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;CAC9D;AAID,MAAM,WAAW,wBAAwB;IACvC,6EAA6E;IAC7E,QAAQ,CAAC,MAAM,CAAC,EAAE,UAAU,CAAA;IAC5B;6EACyE;IACzE,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,GAAG,IAAI,CAAA;IACxC,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAC9B;AAMD;gGACgG;AAChG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,SAAS,CA+E9E;AAED,uGAAuG;AACvG,wBAAgB,cAAc,IAAI,WAAW,CAQ5C"}
package/dist/auth.js CHANGED
@@ -5,7 +5,7 @@
5
5
  * `react` + `@nifrajs/authjs/client`; no JSX (the package builds with plain `tsc`).
6
6
  */
7
7
  import { createAuthClient, } from "@nifrajs/authjs/client";
8
- import { createContext, createElement, useContext, useEffect, useMemo, useState, } from "react";
8
+ import { createContext, createElement, useContext, useEffect, useMemo, useRef, useState, } from "react";
9
9
  const AuthSessionContext = createContext(null);
10
10
  function seededStatus(seed) {
11
11
  return seed === undefined ? "loading" : seed === null ? "unauthenticated" : "authenticated";
@@ -17,7 +17,18 @@ export function AuthSessionProvider(props) {
17
17
  const [seed, setSeed] = useState(props.initialSession);
18
18
  const [status, setStatus] = useState(seededStatus(props.initialSession));
19
19
  const [session, setSession] = useState(props.initialSession ?? null);
20
+ // A read applies only while it holds the latest generation; a newer read, a sign-out, a new client
21
+ // or seed, and unmount each take one. The record is never replaced, so a sign-out that settles
22
+ // after a client or seed change still clears the session the server ended.
23
+ const reads = useRef({ generation: 0, signingOut: 0, live: true, client });
24
+ if (reads.current.client !== client) {
25
+ // A new client keeps what is shown (a parent may build one per render); only answers to the
26
+ // previous client's reads are dropped.
27
+ reads.current.client = client;
28
+ reads.current.generation++;
29
+ }
20
30
  if (seed !== props.initialSession) {
31
+ reads.current.generation++;
21
32
  // A render-phase update: React re-runs this component before any child sees the old session.
22
33
  setSeed(props.initialSession);
23
34
  setStatus(seededStatus(props.initialSession));
@@ -25,47 +36,57 @@ export function AuthSessionProvider(props) {
25
36
  }
26
37
  const refresh = useMemo(() => {
27
38
  return async () => {
39
+ const state = reads.current;
40
+ // A read made while signing out could answer with the session being ended.
41
+ if (state.signingOut > 0 || state.client !== client)
42
+ return;
43
+ const generation = ++state.generation;
28
44
  try {
29
45
  const next = await client.getSession();
46
+ if (!state.live || state.generation !== generation)
47
+ return;
30
48
  setSession(next);
31
49
  setStatus(next === null ? "unauthenticated" : "authenticated");
32
50
  }
33
51
  catch {
34
52
  // A failed session read must fail closed as anonymous; leaving "loading" can strand the
35
53
  // subtree in an auth-pending state and make protected UI appear available by omission.
54
+ if (!state.live || state.generation !== generation)
55
+ return;
36
56
  setSession(null);
37
57
  setStatus("unauthenticated");
38
58
  }
39
59
  };
40
60
  }, [client]);
41
61
  useEffect(() => {
42
- let live = true;
62
+ const state = reads.current;
63
+ state.live = true;
43
64
  if (props.initialSession === undefined) {
44
- void client.getSession().then((next) => {
45
- if (!live)
46
- return;
47
- setSession(next);
48
- setStatus(next === null ? "unauthenticated" : "authenticated");
49
- }, () => {
50
- // Treat an unavailable session endpoint as anonymous rather than keeping auth state
51
- // pending indefinitely or exposing stale authenticated UI.
52
- if (!live)
53
- return;
54
- setSession(null);
55
- setStatus("unauthenticated");
56
- });
65
+ void refresh();
57
66
  }
58
67
  return () => {
59
- live = false;
68
+ state.live = false;
69
+ state.generation++;
60
70
  };
61
- }, [client, props.initialSession]);
71
+ }, [refresh, props.initialSession]);
62
72
  const value = useMemo(() => ({
63
73
  status,
64
74
  session,
65
75
  refresh,
66
76
  signIn: (providerId, options) => client.signIn(providerId, options),
67
77
  signOut: async (options) => {
68
- await client.signOut(options);
78
+ const state = reads.current;
79
+ state.signingOut++;
80
+ state.generation++;
81
+ try {
82
+ await client.signOut(options);
83
+ }
84
+ finally {
85
+ state.signingOut--;
86
+ state.generation++;
87
+ }
88
+ if (!state.live)
89
+ return;
69
90
  // The server ended the session: the subtree must not go on showing it, whether a redirect is
70
91
  // pending or `redirect: false` keeps the page.
71
92
  setSession(null);
package/dist/auth.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAEL,gBAAgB,GAIjB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,aAAa,EACb,aAAa,EAEb,UAAU,EACV,SAAS,EACT,OAAO,EACP,QAAQ,GACT,MAAM,OAAO,CAAA;AAcd,MAAM,kBAAkB,GAAG,aAAa,CAAqB,IAAI,CAAC,CAAA;AAWlE,SAAS,YAAY,CAAC,IAAgC;IACpD,OAAO,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,eAAe,CAAA;AAC7F,CAAC;AAED;gGACgG;AAChG,MAAM,UAAU,mBAAmB,CAAC,KAA+B;IACjE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,IAAI,gBAAgB,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAA;IAChF,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,CAAA;IACtD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAa,YAAY,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,CAAA;IACpF,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAiB,KAAK,CAAC,cAAc,IAAI,IAAI,CAAC,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AAA;IACD,OAAO,aAAa,CAAC,kBAAkB,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,QAAQ,CAAC,CAAA;AAC9E,CAAC;AAED,uGAAuG;AACvG,MAAM,UAAU,cAAc;IAC5B,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAA;IAC9C,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CACb,iFAAiF,CAClF,CAAA;IACH,CAAC;IACD,OAAO,OAAO,CAAA;AAChB,CAAC"}
@@ -94,7 +94,7 @@ export function assertSingleReactCore(reactDomServerPath, resolve, realpath = ru
94
94
  rendererReact = realpath(resolve("react", dirnamePortable(reactDomServerPath)));
95
95
  // The `react` the app's route components import - the core they call hooks on.
96
96
  componentsReact = realpath(resolve("react", appRoot()));
97
- // @nifra-gate-reviewed: not a security gate. If either `react` cannot be resolved we cannot prove
97
+ // nifra-expect NF-S001: not a security gate. If either `react` cannot be resolved we cannot prove
98
98
  // a duplicate exists, so we skip the assertion rather than block a valid render.
99
99
  }
100
100
  catch {
@@ -1 +1 @@
1
- {"version":3,"file":"route-props.d.ts","sourceRoot":"","sources":["../src/route-props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAKhF,iGAAiG;AACjG,wBAAgB,UAAU,CACxB,KAAK,EAAE,WAAW,EAClB,aAAa,EAAE,kBAAkB,CAAC,eAAe,CAAC,EAClD,WAAW,CAAC,EAAE,kBAAkB,CAAC,aAAa,CAAC,GAC9C,WAAW,CA0Bb"}
1
+ {"version":3,"file":"route-props.d.ts","sourceRoot":"","sources":["../src/route-props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAKhF,iGAAiG;AACjG,wBAAgB,UAAU,CACxB,KAAK,EAAE,WAAW,EAClB,aAAa,EAAE,kBAAkB,CAAC,eAAe,CAAC,EAClD,WAAW,CAAC,EAAE,kBAAkB,CAAC,aAAa,CAAC,GAC9C,WAAW,CA2Bb"}
@@ -11,6 +11,7 @@ export function routeProps(state, searchSchemas, matchChains) {
11
11
  const rawSearch = q === -1 ? "" : state.path.slice(q);
12
12
  return {
13
13
  data: state.data,
14
+ ...(state.serverComponents === undefined ? {} : { serverComponents: state.serverComponents }),
14
15
  // Each layout's own loader data. Without it a layout renders `data: null` on the client while the
15
16
  // server rendered it with its data - a hydration mismatch on the first paint.
16
17
  ...(state.layoutData !== undefined ? { layoutData: state.layoutData } : {}),
@@ -1 +1 @@
1
- {"version":3,"file":"route-props.js","sourceRoot":"","sources":["../src/route-props.ts"],"names":[],"mappings":"AACA,mGAAmG;AACnG,gGAAgG;AAChG,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAEnD,iGAAiG;AACjG,MAAM,UAAU,UAAU,CACxB,KAAkB,EAClB,aAAkD,EAClD,WAA+C;IAE/C,MAAM,UAAU,GAAG,WAAW,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;IAC/C,qGAAqG;IACrG,sGAAsG;IACtG,oCAAoC;IACpC,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;IACjC,MAAM,SAAS,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IACrD,OAAO;QACL,IAAI,EAAE,KAAK,CAAC,IAAI;QAChB,kGAAkG;QAClG,8EAA8E;QAC9E,GAAG,CAAC,KAAK,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3E,UAAU,EAAE,KAAK,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F,GAAG,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACpD,CAAA;AACH,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { ComponentClientAdapter } from "@nifrajs/web/server-components/client";
2
+ export declare function reactComponentClient(): ComponentClientAdapter;
3
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/server-components/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,sBAAsB,EAIvB,MAAM,uCAAuC,CAAA;AAqI9C,wBAAgB,oBAAoB,IAAI,sBAAsB,CAqC7D"}
@@ -0,0 +1,167 @@
1
+ import { bytesStream, decodeComponentBytes } from "@nifrajs/web/server-components/stream";
2
+ import { createFromReadableStream } from "@vitejs/plugin-rsc/browser";
3
+ import { createElement, useLayoutEffect, useSyncExternalStore } from "react";
4
+ import { flushSync } from "react-dom";
5
+ import { createRoot, hydrateRoot } from "react-dom/client";
6
+ // Flight's framework-facing lazy ABI is pinned with React/Flight in the compatibility gate.
7
+ async function prepareTree(value, current, seen = new Set(), depth = 0) {
8
+ if (!current())
9
+ throw new Error("component_cancelled");
10
+ if (depth > 64 || seen.size > 16384)
11
+ throw new Error("component_limit");
12
+ if (typeof value !== "object" || value === null || seen.has(value))
13
+ return;
14
+ seen.add(value);
15
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Only this adapter produces its prepared tree and native root; component records and public props are validated before native preparation.
16
+ const node = value;
17
+ if (node.$$typeof === Symbol.for("react.lazy")) {
18
+ const init = node._init;
19
+ if (typeof init !== "function")
20
+ throw new Error("component_protocol");
21
+ while (true) {
22
+ try {
23
+ await prepareTree(init(node._payload), current, seen, depth + 1);
24
+ break;
25
+ }
26
+ catch (pending) {
27
+ if (typeof pending !== "object" ||
28
+ pending === null ||
29
+ !("then" in pending) ||
30
+ typeof pending.then !== "function")
31
+ throw pending;
32
+ await pending;
33
+ if (!current())
34
+ throw new Error("component_cancelled");
35
+ }
36
+ }
37
+ }
38
+ else if ("then" in node && typeof node.then === "function") {
39
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Only this adapter produces its prepared tree and native root; component records and public props are validated before native preparation.
40
+ await prepareTree(await value, current, seen, depth + 1);
41
+ }
42
+ else if (Array.isArray(value)) {
43
+ await Promise.all(value.map((child) => prepareTree(child, current, seen, depth + 1)));
44
+ }
45
+ else if (node.$$typeof === Symbol.for("react.transitional.element")) {
46
+ await prepareTree(node.type, current, seen, depth + 1);
47
+ await prepareTree(node.props, current, seen, depth + 1);
48
+ }
49
+ else {
50
+ await Promise.all(Object.values(node).map((child) => prepareTree(child, current, seen, depth + 1)));
51
+ }
52
+ }
53
+ class FlightRoot {
54
+ #host;
55
+ #root;
56
+ #listeners = new Set();
57
+ #snapshot;
58
+ #current;
59
+ #committed = null;
60
+ #disposed = false;
61
+ #ready;
62
+ ready;
63
+ constructor(host, tree, record, current, fresh = false) {
64
+ this.#host = host;
65
+ this.#snapshot = tree;
66
+ this.#current = current;
67
+ let ready;
68
+ this.ready = new Promise((resolve) => {
69
+ ready = resolve;
70
+ });
71
+ this.#ready = ready;
72
+ const store = this;
73
+ function CurrentTree() {
74
+ const value = useSyncExternalStore((listener) => {
75
+ store.#listeners.add(listener);
76
+ return () => store.#listeners.delete(listener);
77
+ }, () => store.#snapshot, () => tree);
78
+ const display = store.#current() ? value : store.#committed;
79
+ useLayoutEffect(() => {
80
+ store.#committed = display;
81
+ store.#ready();
82
+ });
83
+ return display;
84
+ }
85
+ const options = {
86
+ identifierPrefix: `${record.instance}-`,
87
+ onRecoverableError() {
88
+ if (current())
89
+ throw new Error("component_failed");
90
+ },
91
+ onUncaughtError() {
92
+ store.#ready();
93
+ store.dispose();
94
+ throw new Error("component_failed");
95
+ },
96
+ };
97
+ if (fresh) {
98
+ this.#root = createRoot(host, options);
99
+ this.#root.render(createElement(CurrentTree));
100
+ }
101
+ else
102
+ this.#root = hydrateRoot(host, createElement(CurrentTree), options);
103
+ }
104
+ publish(tree, current) {
105
+ if (this.#disposed || !current())
106
+ return;
107
+ flushSync(() => {
108
+ if (!current())
109
+ return;
110
+ this.#current = current;
111
+ this.#snapshot = tree;
112
+ for (const listener of this.#listeners)
113
+ listener();
114
+ });
115
+ }
116
+ update() {
117
+ throw new Error("component_contract");
118
+ }
119
+ dispose() {
120
+ if (this.#disposed)
121
+ return;
122
+ this.#disposed = true;
123
+ this.#root.unmount();
124
+ this.#listeners.clear();
125
+ this.#host.replaceChildren();
126
+ this.#ready();
127
+ }
128
+ }
129
+ export function reactComponentClient() {
130
+ return {
131
+ name: "react",
132
+ async prepare(record, current) {
133
+ if (typeof record.payload !== "object" ||
134
+ record.payload === null ||
135
+ Array.isArray(record.payload) ||
136
+ !Object.hasOwn(record.payload, "flight"))
137
+ throw new Error("component_protocol");
138
+ const tree = await createFromReadableStream(
139
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Only this adapter produces its prepared tree and native root; component records and public props are validated before native preparation.
140
+ bytesStream(decodeComponentBytes(record.payload.flight)));
141
+ await prepareTree(tree, current);
142
+ if (!current())
143
+ throw new Error("component_cancelled");
144
+ return tree;
145
+ },
146
+ async hydrate(host, record, tree, current) {
147
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Only this adapter produces its prepared tree and native root; component records and public props are validated before native preparation.
148
+ const root = new FlightRoot(host, tree, record, current);
149
+ await root.ready;
150
+ return root;
151
+ },
152
+ async create(host, record, tree, current) {
153
+ if (!current())
154
+ throw new Error("component_cancelled");
155
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Only this adapter produces its prepared tree and native root; component records and public props are validated before native preparation.
156
+ const root = new FlightRoot(host, tree, record, current, true);
157
+ await root.ready;
158
+ return root;
159
+ },
160
+ update(root, _record, tree, current) {
161
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Only this adapter produces its prepared tree and native root; component records and public props are validated before native preparation.
162
+ ;
163
+ root.publish(tree, current);
164
+ },
165
+ };
166
+ }
167
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/server-components/client.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAA;AACzF,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AACrE,OAAO,EAAE,aAAa,EAAkB,eAAe,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAA;AAC5F,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AAE1D,4FAA4F;AAC5F,KAAK,UAAU,WAAW,CACxB,KAAc,EACd,OAAyB,EACzB,OAAO,IAAI,GAAG,EAAU,EACxB,KAAK,GAAG,CAAC;IAET,IAAI,CAAC,OAAO,EAAE;QAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;IACtD,IAAI,KAAK,GAAG,EAAE,IAAI,IAAI,CAAC,IAAI,GAAG,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;IACvE,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC;QAAE,OAAM;IAC1E,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;IACf,2MAA2M;IAC3M,MAAM,IAAI,GAAG,KAAgC,CAAA;IAC7C,IAAI,IAAI,CAAC,QAAQ,KAAK,MAAM,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;QAC/C,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAA;QACvB,IAAI,OAAO,IAAI,KAAK,UAAU;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC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IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;YACvC,2MAA2M;YAC3M,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,EAAE,IAAiB,EAAE,MAAM,EAAE,OAAO,CAAC,CAAA;YACrE,MAAM,IAAI,CAAC,KAAK,CAAA;YAChB,OAAO,IAAI,CAAA;QACb,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO;YACtC,IAAI,CAAC,OAAO,EAAE;gBAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;YACtD,2MAA2M;YAC3M,MAAM,IAAI,GAAG,IAAI,UAAU,CAAC,IAAI,EAAE,IAAiB,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAA;YAC3E,MAAM,IAAI,CAAC,KAAK,CAAA;YAChB,OAAO,IAAI,CAAA;QACb,CAAC;QACD,MAAM,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO;YACjC,2MAA2M;YAC3M,CAAC;YAAC,IAAmB,CAAC,OAAO,CAAC,IAAiB,EAAE,OAAO,CAAC,CAAA;QAC3D,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -0,0 +1,4 @@
1
+ /** React 19.2.8 Flight framing: remove development owners/stacks/console records before transport. */
2
+ export declare function publicFlight(bytes: Uint8Array): Uint8Array;
3
+ export declare function publicFlightStream(stream: ReadableStream<Uint8Array>, signal: AbortSignal): Promise<ReadableStream<Uint8Array>>;
4
+ //# sourceMappingURL=flight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flight.d.ts","sourceRoot":"","sources":["../../src/server-components/flight.ts"],"names":[],"mappings":"AAoBA,sGAAsG;AACtG,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAqD1D;AACD,wBAAsB,kBAAkB,CACtC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,EAClC,MAAM,EAAE,WAAW,GAClB,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAQrC"}
@@ -0,0 +1,87 @@
1
+ import { readComponentBytes } from "@nifrajs/web/server-components/stream";
2
+ const encoder = new TextEncoder();
3
+ const decoder = new TextDecoder("utf-8", { fatal: true });
4
+ function publicModel(value, depth = 0) {
5
+ if (depth > 128)
6
+ throw new Error("component_limit");
7
+ if (typeof value === "string" && value.startsWith("$F"))
8
+ throw new Error("component_contract");
9
+ if (Array.isArray(value))
10
+ return (value[0] === "$"
11
+ ? [...value.slice(0, 4), null, null, value[6] === 1 || value[6] === 2 ? value[6] : 0]
12
+ : value).map((item) => publicModel(item, depth + 1));
13
+ if (typeof value === "object" && value !== null)
14
+ return Object.fromEntries(Object.entries(value).map(([key, item]) => [key, publicModel(item, depth + 1)]));
15
+ return value;
16
+ }
17
+ /** React 19.2.8 Flight framing: remove development owners/stacks/console records before transport. */
18
+ export function publicFlight(bytes) {
19
+ const rows = [];
20
+ let offset = 0;
21
+ while (offset < bytes.length) {
22
+ const start = offset;
23
+ while (offset < bytes.length && bytes[offset] !== 58)
24
+ offset++;
25
+ const id = decoder.decode(bytes.subarray(start, offset));
26
+ if (!/^[0-9a-f]*$/.test(id) || offset === bytes.length)
27
+ throw new Error("component_protocol");
28
+ offset++;
29
+ if (bytes[offset] === 84) {
30
+ const lengthStart = ++offset;
31
+ while (offset < bytes.length && bytes[offset] !== 44)
32
+ offset++;
33
+ const encodedLength = decoder.decode(bytes.subarray(lengthStart, offset));
34
+ if (!/^[0-9a-f]+$/.test(encodedLength))
35
+ throw new Error("component_protocol");
36
+ const length = parseInt(encodedLength, 16);
37
+ offset++;
38
+ if (offset + length > bytes.length)
39
+ throw new Error("component_protocol");
40
+ offset += length;
41
+ rows.push(bytes.slice(start, offset));
42
+ continue;
43
+ }
44
+ const end = bytes.indexOf(10, offset);
45
+ if (end === -1)
46
+ throw new Error("component_protocol");
47
+ const row = decoder.decode(bytes.subarray(offset, end));
48
+ offset = end + 1;
49
+ if (/^[DNW]/.test(row))
50
+ continue;
51
+ if (row.startsWith("E")) {
52
+ rows.push(encoder.encode(id +
53
+ ':E{"digest":"component_failed","message":"component_failed","name":"Error","stack":[],"env":"Server","owner":null}\n'));
54
+ continue;
55
+ }
56
+ if (/^[[{"0-9tnf-]/.test(row)) {
57
+ let model;
58
+ try {
59
+ model = JSON.parse(row);
60
+ }
61
+ catch {
62
+ throw new Error("component_protocol");
63
+ }
64
+ rows.push(encoder.encode(`${id}:${JSON.stringify(publicModel(model))}\n`));
65
+ }
66
+ else
67
+ rows.push(bytes.slice(start, offset));
68
+ }
69
+ const size = rows.reduce((size, row) => size + row.length, 0);
70
+ const output = new Uint8Array(size);
71
+ let at = 0;
72
+ for (const row of rows) {
73
+ output.set(row, at);
74
+ at += row.length;
75
+ }
76
+ return output;
77
+ }
78
+ export async function publicFlightStream(stream, signal) {
79
+ const bytes = publicFlight(await readComponentBytes(stream, signal));
80
+ return new ReadableStream({
81
+ start(controller) {
82
+ controller.enqueue(bytes);
83
+ controller.close();
84
+ },
85
+ });
86
+ }
87
+ //# sourceMappingURL=flight.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flight.js","sourceRoot":"","sources":["../../src/server-components/flight.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAA;AAE1E,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;AACjC,MAAM,OAAO,GAAG,IAAI,WAAW,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;AACzD,SAAS,WAAW,CAAC,KAAc,EAAE,KAAK,GAAG,CAAC;IAC5C,IAAI,KAAK,GAAG,GAAG;QAAE,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAA;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,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AO,MAAM,CAAA;AACf,CAAC;AACD,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAAkC,EAClC,MAAmB;IAEnB,MAAM,KAAK,GAAG,YAAY,CAAC,MAAM,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;IACpE,OAAO,IAAI,cAAc,CAAC;QACxB,KAAK,CAAC,UAAU;YACd,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;YACzB,UAAU,CAAC,KAAK,EAAE,CAAA;QACpB,CAAC;KACF,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { StandardSchemaV1 } from "@nifrajs/core/schema";
2
+ import { type ComponentType, type ReactElement, type ReactNode } from "react";
3
+ /** Called by generated facades. The actual native reference stays private to this module. */
4
+ export declare function guardedClientReference(reference: unknown, schema: StandardSchemaV1, slots?: readonly string[]): ComponentType<Record<string, unknown>>;
5
+ export declare function guardedClientElement(type: unknown, raw: unknown, key?: unknown): ReactNode | undefined;
6
+ export declare function guardedCreateElement(type: unknown, props?: unknown, ...children: ReactNode[]): ReactNode;
7
+ export declare function guardedCloneElement(element: ReactElement, props?: unknown, ...children: ReactNode[]): ReactNode;
8
+ //# sourceMappingURL=guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.d.ts","sourceRoot":"","sources":["../../src/server-components/guard.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAA;AAE5D,OAAO,EACL,KAAK,aAAa,EAIlB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAoDd,6FAA6F;AAC7F,wBAAgB,sBAAsB,CACpC,SAAS,EAAE,OAAO,EAClB,MAAM,EAAE,gBAAgB,EACxB,KAAK,GAAE,SAAS,MAAM,EAAO,GAC5B,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAWxC;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,OAAO,EACb,GAAG,EAAE,OAAO,EACZ,GAAG,CAAC,EAAE,OAAO,GACZ,SAAS,GAAG,SAAS,CA8BvB;AAED,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,OAAO,EACb,KAAK,CAAC,EAAE,OAAO,EACf,GAAG,QAAQ,EAAE,SAAS,EAAE,GACvB,SAAS,CAqBX;AAED,wBAAgB,mBAAmB,CACjC,OAAO,EAAE,YAAY,EACrB,KAAK,CAAC,EAAE,OAAO,EACf,GAAG,QAAQ,EAAE,SAAS,EAAE,GACvB,SAAS,CAoDX"}
@@ -0,0 +1,139 @@
1
+ import { guardComponentProps } from "@nifrajs/web/server-components/props";
2
+ import { cloneElement, createElement, isValidElement, } from "react";
3
+ const contracts = new WeakMap();
4
+ const wrappers = new WeakMap();
5
+ const encoder = new TextEncoder();
6
+ function failure() {
7
+ const error = new Error("component_failed");
8
+ error.stack = "";
9
+ return error;
10
+ }
11
+ function slot(value, depth = 0) {
12
+ if (depth > 16)
13
+ throw failure();
14
+ if (value === undefined ||
15
+ value === null ||
16
+ typeof value === "boolean" ||
17
+ typeof value === "string" ||
18
+ (typeof value === "number" && Number.isFinite(value)) ||
19
+ isValidElement(value))
20
+ return value;
21
+ if (Array.isArray(value) && value.length <= 128)
22
+ return value.map((item) => slot(item, depth + 1));
23
+ throw failure();
24
+ }
25
+ function publicProps(contract, raw) {
26
+ return (async () => {
27
+ if (typeof raw !== "object" || raw === null || Array.isArray(raw))
28
+ throw failure();
29
+ const dto = Object.create(null);
30
+ const slots = Object.create(null);
31
+ for (const [name, descriptor] of Object.entries(Object.getOwnPropertyDescriptors(raw))) {
32
+ if (!Object.hasOwn(descriptor, "value"))
33
+ throw failure();
34
+ if (contract.slots.includes(name))
35
+ slots[name] = slot(descriptor.value);
36
+ else if (name !== "children" && name !== "ref" && name !== "key")
37
+ dto[name] = descriptor.value;
38
+ }
39
+ const projected = await guardComponentProps(contract.schema, dto);
40
+ if (typeof projected !== "object" || projected === null || Array.isArray(projected))
41
+ throw failure();
42
+ return { ...projected, ...slots };
43
+ })().catch(() => {
44
+ throw failure();
45
+ });
46
+ }
47
+ /** Called by generated facades. The actual native reference stays private to this module. */
48
+ export function guardedClientReference(reference, schema, slots = []) {
49
+ const Facade = () => {
50
+ throw failure();
51
+ };
52
+ contracts.set(Facade, {
53
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Registered native references and projected props retain the pinned React ABI; key and prop vocabulary are checked before serialization.
54
+ reference: reference,
55
+ schema,
56
+ slots,
57
+ });
58
+ return Facade;
59
+ }
60
+ export function guardedClientElement(type, raw, key) {
61
+ if ((typeof type !== "object" && typeof type !== "function") || type === null)
62
+ return undefined;
63
+ const contract = contracts.get(type);
64
+ if (contract === undefined)
65
+ return undefined;
66
+ if (key !== undefined &&
67
+ key !== null &&
68
+ !((typeof key === "string" && encoder.encode(key).length <= 128) ||
69
+ (typeof key === "number" && Number.isSafeInteger(key))))
70
+ throw failure();
71
+ const props = publicProps(contract, raw ?? {});
72
+ const publicKey = typeof key === "string" || typeof key === "number" ? key : null;
73
+ // Only a promise of projected props reaches React's element/debug metadata. Raw props stay in the guard closure.
74
+ const Guarded = async ({ value, }) => createElement(contract.reference, {
75
+ ...(await value),
76
+ key: publicKey,
77
+ });
78
+ wrappers.set(Guarded, contract);
79
+ return createElement(Guarded, {
80
+ value: props,
81
+ key: publicKey,
82
+ });
83
+ }
84
+ export function guardedCreateElement(type, props, ...children) {
85
+ const raw = children.length === 0
86
+ ? props
87
+ : {
88
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Registered native references and projected props retain the pinned React ABI; key and prop vocabulary are checked before serialization.
89
+ ...props,
90
+ children: children.length === 1 ? children[0] : children,
91
+ };
92
+ const key =
93
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Registered native references and projected props retain the pinned React ABI; key and prop vocabulary are checked before serialization.
94
+ typeof raw === "object" && raw !== null ? raw.key : undefined;
95
+ const guarded = guardedClientElement(type, raw, key);
96
+ if (guarded !== undefined)
97
+ return guarded;
98
+ return createElement(
99
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Registered native references and projected props retain the pinned React ABI; key and prop vocabulary are checked before serialization.
100
+ type,
101
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Registered native references and projected props retain the pinned React ABI; key and prop vocabulary are checked before serialization.
102
+ props, ...children);
103
+ }
104
+ export function guardedCloneElement(element, props, ...children) {
105
+ const contract = (typeof element.type === "object" || typeof element.type === "function") &&
106
+ element.type !== null
107
+ ? (wrappers.get(element.type) ?? contracts.get(element.type))
108
+ : undefined;
109
+ if (contract === undefined)
110
+ return cloneElement(element,
111
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Registered native references and projected props retain the pinned React ABI; key and prop vocabulary are checked before serialization.
112
+ props === null ? undefined : props, ...children);
113
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Registered native references and projected props retain the pinned React ABI; key and prop vocabulary are checked before serialization.
114
+ const previous = element.props;
115
+ const value = Object.hasOwn(previous, "value")
116
+ ? // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Registered native references and projected props retain the pinned React ABI; key and prop vocabulary are checked before serialization.
117
+ previous.value
118
+ : publicProps(contract, previous);
119
+ const raw = props ?? {};
120
+ if (typeof raw !== "object" ||
121
+ raw === null ||
122
+ Array.isArray(raw) ||
123
+ Object.values(Object.getOwnPropertyDescriptors(raw)).some((descriptor) => !Object.hasOwn(descriptor, "value")))
124
+ throw failure();
125
+ const next = value.then((projected) => publicProps(contract, { ...projected, ...raw, ...(children.length === 0 ? {} : { children }) }));
126
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Registered native references and projected props retain the pinned React ABI; key and prop vocabulary are checked before serialization.
127
+ const rawKey = raw.key ?? element.key;
128
+ if (rawKey !== null &&
129
+ !((typeof rawKey === "string" && encoder.encode(rawKey).length <= 128) ||
130
+ (typeof rawKey === "number" && Number.isSafeInteger(rawKey))))
131
+ throw failure();
132
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Registered native references and projected props retain the pinned React ABI; key and prop vocabulary are checked before serialization.
133
+ const key = rawKey;
134
+ const Guarded = async ({ value, }) => createElement(contract.reference, { ...(await value), key });
135
+ wrappers.set(Guarded, contract);
136
+ // biome-ignore lint/plugin/requireSafetyCommentForTypeAssertion: Registered native references and projected props retain the pinned React ABI; key and prop vocabulary are checked before serialization.
137
+ return createElement(Guarded, { value: next, key: key });
138
+ }
139
+ //# sourceMappingURL=guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guard.js","sourceRoot":"","sources":["../../src/server-components/guard.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAA;AAC1E,OAAO,EAEL,YAAY,EACZ,aAAa,EACb,cAAc,GAGf,MAAM,OAAO,CAAA;AAOd,MAAM,SAAS,GAAG,IAAI,OAAO,EAA0B,CAAA;AACvD,MAAM,QAAQ,GAAG,IAAI,OAAO,EAA0B,CAAA;AACtD,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAA;AAEjC,SAAS,OAAO;IACd,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAA;IAC3C,KAAK,CAAC,KAAK,GAAG,EAAE,CAAA;IAChB,OAAO,KAAK,CAAA;AACd,CAAC;AAED,SAAS,IAAI,CAAC,KAAc,EAAE,KAAK,GAAG,CAAC;IACrC,IAAI,KAAK,GAAG,EAAE;QAAE,MAAM,OAAO,EAAE,CAAA;IAC/B,IACE,KAAK,KAAK,SAAS;QACnB,KAAK,KAAK,IAAI;QACd,OAAO,KAAK,KAAK,SAAS;QAC1B,OAAO,KAAK,KAAK,QAAQ;QACzB,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;QACrD,cAAc,CAAC,KAAK,CAAC;QAErB,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Children: boolean, source?: {
4
+ fileName: string;
5
+ lineNumber: number;
6
+ columnNumber: number;
7
+ }, self?: unknown): unknown;
8
+ //# sourceMappingURL=jsx-dev-runtime.d.ts.map