@nifrajs/web-react 0.1.0-alpha.4 → 0.1.0-alpha.5

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.
@@ -12,11 +12,15 @@
12
12
  * dispatcher, no crash. (Empirically verified against a two-copy install fixture — see
13
13
  * test/dual-react.test.ts.)
14
14
  *
15
- * Guarding precisely so the PRODUCTION/BUILT path is untouched: when `Bun.resolveSync` is unavailable
16
- * (Node / Deno / Cloudflare / Vercel / any bundled output), the build has already bundled+deduped a single
17
- * `react-dom` (buildServer's `reactDedupePlugin` pins `react`), so the static `import` is correct AND is
18
- * the only thing that works without a Bun resolver. We fall back to it there. The app-root resolution runs
19
- * ONLY under the Bun runtime, where the duplication can occur and `Bun.resolveSync` exists.
15
+ * Guarding precisely so the BUILT path is untouched: a bundle is detected two ways — `Bun.resolveSync` is
16
+ * unavailable (Node / Deno / Cloudflare / Vercel), OR `buildServer` tagged the output with
17
+ * `process.env.NIFRA_SSR_BUNDLED` (a `target:"bun"` bundle DOES keep `Bun.resolveSync` under the Bun
18
+ * runtime, so the resolver test alone can't see it). In either case the build already bundled+deduped a
19
+ * single `react-dom` (buildServer's `reactDedupePlugin` pins `react`), so the static `import` is correct.
20
+ * Re-rooting a bundle would instead re-import a SECOND react-dom from disk — a second React core whose hook
21
+ * dispatcher is null for the bundled components → the `…H.useRef of null` SSR crash. The app-root re-root
22
+ * therefore runs ONLY under an UNBUNDLED Bun runtime (nifra dev/start, nifra_render), where the duplication
23
+ * can occur, `Bun.resolveSync` exists, and no bundle marker is present.
20
24
  */
21
25
  import type { ReactNode } from "react";
22
26
  /** The slice of `react-dom/server` this adapter uses. Typed locally so the dynamic import (which Bun
@@ -40,5 +44,15 @@ type ResolveSync = (specifier: string, from: string) => string;
40
44
  * without depending on the machine's node_modules layout.
41
45
  */
42
46
  export declare function loadReactDomServer(resolve?: ResolveSync | undefined): Promise<ReactDomServer>;
47
+ /**
48
+ * The resolver `loadReactDomServer` uses by default, or `undefined` when re-rooting must NOT happen — a
49
+ * non-Bun host (no `Bun.resolveSync`; the static import is the only path) OR a BUNDLED SSR output.
50
+ * `buildServer` defines `process.env.NIFRA_SSR_BUNDLED` to `"1"` in every bundle, where react-dom is
51
+ * already inlined + deduped to the components' React (reactDedupePlugin); re-rooting there would re-import
52
+ * a SECOND react-dom from disk (a `target:"bun"` bundle still has `Bun.resolveSync`), giving the bundled
53
+ * components a foreign/null hook dispatcher → the `…H.useRef of null` crash. The marker is read here (per
54
+ * call, not at module load) so it stays driveable from a test. Unbundled Bun runtimes don't set it, so
55
+ * dev/start still re-root. Exported for unit testing the gate. */
56
+ export declare function bunResolverFn(): ResolveSync | undefined;
43
57
  export {};
44
58
  //# sourceMappingURL=react-dom-server.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"react-dom-server.d.ts","sourceRoot":"","sources":["../src/react-dom-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC;wFACwF;AACxF,MAAM,WAAW,cAAc;IAC7B,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAAA;IACvC,sBAAsB,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAA;CAC7E;AA4BD;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAAC,cAAc,CAAC,CAIxD;AAED,6EAA6E;AAC7E,KAAK,WAAW,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;AAE9D;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,GAAE,WAAW,GAAG,SAA2B,GACjD,OAAO,CAAC,cAAc,CAAC,CAiBzB"}
1
+ {"version":3,"file":"react-dom-server.d.ts","sourceRoot":"","sources":["../src/react-dom-server.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAEtC;wFACwF;AACxF,MAAM,WAAW,cAAc;IAC7B,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,MAAM,CAAA;IACvC,sBAAsB,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAAA;CAC7E;AA4BD;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,OAAO,CAAC,cAAc,CAAC,CAIxD;AAED,6EAA6E;AAC7E,KAAK,WAAW,GAAG,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,KAAK,MAAM,CAAA;AAE9D;;;;;GAKG;AACH,wBAAsB,kBAAkB,CACtC,OAAO,GAAE,WAAW,GAAG,SAA2B,GACjD,OAAO,CAAC,cAAc,CAAC,CAiBzB;AAED;;;;;;;;kEAQkE;AAClE,wBAAgB,aAAa,IAAI,WAAW,GAAG,SAAS,CAKvD"}
@@ -12,11 +12,15 @@
12
12
  * dispatcher, no crash. (Empirically verified against a two-copy install fixture — see
13
13
  * test/dual-react.test.ts.)
14
14
  *
15
- * Guarding precisely so the PRODUCTION/BUILT path is untouched: when `Bun.resolveSync` is unavailable
16
- * (Node / Deno / Cloudflare / Vercel / any bundled output), the build has already bundled+deduped a single
17
- * `react-dom` (buildServer's `reactDedupePlugin` pins `react`), so the static `import` is correct AND is
18
- * the only thing that works without a Bun resolver. We fall back to it there. The app-root resolution runs
19
- * ONLY under the Bun runtime, where the duplication can occur and `Bun.resolveSync` exists.
15
+ * Guarding precisely so the BUILT path is untouched: a bundle is detected two ways — `Bun.resolveSync` is
16
+ * unavailable (Node / Deno / Cloudflare / Vercel), OR `buildServer` tagged the output with
17
+ * `process.env.NIFRA_SSR_BUNDLED` (a `target:"bun"` bundle DOES keep `Bun.resolveSync` under the Bun
18
+ * runtime, so the resolver test alone can't see it). In either case the build already bundled+deduped a
19
+ * single `react-dom` (buildServer's `reactDedupePlugin` pins `react`), so the static `import` is correct.
20
+ * Re-rooting a bundle would instead re-import a SECOND react-dom from disk — a second React core whose hook
21
+ * dispatcher is null for the bundled components → the `…H.useRef of null` SSR crash. The app-root re-root
22
+ * therefore runs ONLY under an UNBUNDLED Bun runtime (nifra dev/start, nifra_render), where the duplication
23
+ * can occur, `Bun.resolveSync` exists, and no bundle marker is present.
20
24
  */
21
25
  var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
22
26
  if (typeof path === "string" && /^\.\.?\//.test(path)) {
@@ -78,8 +82,18 @@ export async function loadReactDomServer(resolve = bunResolverFn()) {
78
82
  // bundler include it (it's a constant), and at runtime resolves the copy visible to this package.
79
83
  return (await import("react-dom/server"));
80
84
  }
81
- /** The ambient `Bun.resolveSync`, or undefined on a non-Bun host (where the static import is the only path). */
82
- function bunResolverFn() {
85
+ /**
86
+ * The resolver `loadReactDomServer` uses by default, or `undefined` when re-rooting must NOT happen — a
87
+ * non-Bun host (no `Bun.resolveSync`; the static import is the only path) OR a BUNDLED SSR output.
88
+ * `buildServer` defines `process.env.NIFRA_SSR_BUNDLED` to `"1"` in every bundle, where react-dom is
89
+ * already inlined + deduped to the components' React (reactDedupePlugin); re-rooting there would re-import
90
+ * a SECOND react-dom from disk (a `target:"bun"` bundle still has `Bun.resolveSync`), giving the bundled
91
+ * components a foreign/null hook dispatcher → the `…H.useRef of null` crash. The marker is read here (per
92
+ * call, not at module load) so it stays driveable from a test. Unbundled Bun runtimes don't set it, so
93
+ * dev/start still re-root. Exported for unit testing the gate. */
94
+ export function bunResolverFn() {
95
+ if (process.env.NIFRA_SSR_BUNDLED === "1")
96
+ return undefined;
83
97
  return hasBunResolveSync && bunResolver?.resolveSync !== undefined
84
98
  ? bunResolver.resolveSync.bind(bunResolver)
85
99
  : undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"react-dom-server.js","sourceRoot":"","sources":["../src/react-dom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AO,iBAAiB,IAAI,WAAW,EAAE,WAAW,KAAK,SAAS;QAChE,CAAC,CAAC,WAAW,CAAC,WAAW,CAAC,IAAI,CAAC,WAAW,CAAC;QAC3C,CAAC,CAAC,SAAS,CAAA;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nifrajs/web-react",
3
- "version": "0.1.0-alpha.4",
3
+ "version": "0.1.0-alpha.5",
4
4
  "description": "React render adapter for @nifrajs/web — SSR + hydration (Bun-native JSX, no Babel).",
5
5
  "keywords": [
6
6
  "bun",
@@ -77,7 +77,7 @@
77
77
  "dependencies": {
78
78
  "@nifrajs/i18n": "0.1.0-alpha.4",
79
79
  "@nifrajs/image": "0.1.0-alpha.4",
80
- "@nifrajs/web": "0.1.0-alpha.4"
80
+ "@nifrajs/web": "0.1.0-alpha.5"
81
81
  },
82
82
  "peerDependencies": {
83
83
  "react": "^19.0.0",
@@ -12,11 +12,15 @@
12
12
  * dispatcher, no crash. (Empirically verified against a two-copy install fixture — see
13
13
  * test/dual-react.test.ts.)
14
14
  *
15
- * Guarding precisely so the PRODUCTION/BUILT path is untouched: when `Bun.resolveSync` is unavailable
16
- * (Node / Deno / Cloudflare / Vercel / any bundled output), the build has already bundled+deduped a single
17
- * `react-dom` (buildServer's `reactDedupePlugin` pins `react`), so the static `import` is correct AND is
18
- * the only thing that works without a Bun resolver. We fall back to it there. The app-root resolution runs
19
- * ONLY under the Bun runtime, where the duplication can occur and `Bun.resolveSync` exists.
15
+ * Guarding precisely so the BUILT path is untouched: a bundle is detected two ways — `Bun.resolveSync` is
16
+ * unavailable (Node / Deno / Cloudflare / Vercel), OR `buildServer` tagged the output with
17
+ * `process.env.NIFRA_SSR_BUNDLED` (a `target:"bun"` bundle DOES keep `Bun.resolveSync` under the Bun
18
+ * runtime, so the resolver test alone can't see it). In either case the build already bundled+deduped a
19
+ * single `react-dom` (buildServer's `reactDedupePlugin` pins `react`), so the static `import` is correct.
20
+ * Re-rooting a bundle would instead re-import a SECOND react-dom from disk — a second React core whose hook
21
+ * dispatcher is null for the bundled components → the `…H.useRef of null` SSR crash. The app-root re-root
22
+ * therefore runs ONLY under an UNBUNDLED Bun runtime (nifra dev/start, nifra_render), where the duplication
23
+ * can occur, `Bun.resolveSync` exists, and no bundle marker is present.
20
24
  */
21
25
 
22
26
  import type { ReactNode } from "react"
@@ -95,8 +99,17 @@ export async function loadReactDomServer(
95
99
  return (await import("react-dom/server")) as ReactDomServer
96
100
  }
97
101
 
98
- /** The ambient `Bun.resolveSync`, or undefined on a non-Bun host (where the static import is the only path). */
99
- function bunResolverFn(): ResolveSync | undefined {
102
+ /**
103
+ * The resolver `loadReactDomServer` uses by default, or `undefined` when re-rooting must NOT happen — a
104
+ * non-Bun host (no `Bun.resolveSync`; the static import is the only path) OR a BUNDLED SSR output.
105
+ * `buildServer` defines `process.env.NIFRA_SSR_BUNDLED` to `"1"` in every bundle, where react-dom is
106
+ * already inlined + deduped to the components' React (reactDedupePlugin); re-rooting there would re-import
107
+ * a SECOND react-dom from disk (a `target:"bun"` bundle still has `Bun.resolveSync`), giving the bundled
108
+ * components a foreign/null hook dispatcher → the `…H.useRef of null` crash. The marker is read here (per
109
+ * call, not at module load) so it stays driveable from a test. Unbundled Bun runtimes don't set it, so
110
+ * dev/start still re-root. Exported for unit testing the gate. */
111
+ export function bunResolverFn(): ResolveSync | undefined {
112
+ if (process.env.NIFRA_SSR_BUNDLED === "1") return undefined
100
113
  return hasBunResolveSync && bunResolver?.resolveSync !== undefined
101
114
  ? bunResolver.resolveSync.bind(bunResolver)
102
115
  : undefined