partial-react 0.0.4 → 0.0.6

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "partial-react",
3
3
  "description": "A state-preserving renderer for prefix-growing streaming React/TSX.",
4
- "version": "0.0.4",
4
+ "version": "0.0.6",
5
5
  "type": "module",
6
6
  "repository": {
7
7
  "type": "git",
@@ -15,6 +15,9 @@
15
15
  "./remote-module": "./src/remoteModule.ts",
16
16
  "./render-context": "./src/renderContext.ts"
17
17
  },
18
+ "browser": {
19
+ "./src/nodeWasm.ts": false
20
+ },
18
21
  "files": [
19
22
  "src/**/*",
20
23
  "!src/**/*.test.*"
@@ -24,8 +27,8 @@
24
27
  "partial-tsx": "0.0.3"
25
28
  },
26
29
  "peerDependencies": {
27
- "react": "^19.0.0",
28
- "react-dom": "^19.0.0"
30
+ "react": "^18.3.0 || ^19.0.0",
31
+ "react-dom": "^18.3.0 || ^19.0.0"
29
32
  },
30
33
  "sideEffects": false
31
34
  }
package/src/compiler.ts CHANGED
@@ -7,16 +7,10 @@ export type CompileResult = { code: string; source: string; changed: boolean };
7
7
  export type TsxCompiler = { compile: (code: string, options?: CompileOptions) => Promise<CompileResult> };
8
8
 
9
9
  let initPromise: Promise<unknown> | null = null;
10
- const loadNodeWasm = async () => {
11
- // `import.meta.resolve` yields a `file://` URL under both Bun and Node/Vite SSR, so `new URL` is safe — don't "fix" it with pathToFileURL.
12
- const wasmUrl = new URL(import.meta.resolve("@esm.sh/tsx/pkg/tsx_bg.wasm"));
13
- if (typeof Bun !== "undefined") return Bun.file(wasmUrl).arrayBuffer();
14
- return (await import("node:fs/promises")).readFile(wasmUrl);
15
- };
16
10
  const initCompiler = () =>
17
11
  (initPromise ??= (async () => {
18
12
  try {
19
- if (typeof window === "undefined") return initTsx(await loadNodeWasm());
13
+ if (typeof window === "undefined") return initTsx(await (await import("./nodeWasm")).loadNodeWasm());
20
14
  } catch {
21
15
  // Environments without a filesystem (e.g. web workers) fall back to the bundled asset below.
22
16
  }
@@ -0,0 +1,11 @@
1
+ // Kept out of `compiler.ts` so browser bundles never see `import.meta.resolve`: it is a syntax-level construct, so a
2
+ // bundler emitting CJS produces a file that throws on evaluation no matter which branch would run. #1717
3
+ // Typed off `globalThis` instead of the `Bun` global to avoid forcing `@types/bun` on consumers (we ship raw `.ts`).
4
+ const bun = (globalThis as { Bun?: { file(path: URL): { arrayBuffer(): Promise<ArrayBuffer> } } }).Bun;
5
+
6
+ export const loadNodeWasm = async () => {
7
+ // `import.meta.resolve` yields a `file://` URL under both Bun and Node/Vite SSR, so `new URL` is safe — don't "fix" it with pathToFileURL.
8
+ const wasmUrl = new URL(import.meta.resolve("@esm.sh/tsx/pkg/tsx_bg.wasm"));
9
+ if (bun) return bun.file(wasmUrl).arrayBuffer();
10
+ return (await import("node:fs/promises")).readFile(wasmUrl);
11
+ };
package/src/runtime.ts CHANGED
@@ -422,7 +422,8 @@ export class GenUIRenderer {
422
422
  createElement(
423
423
  RuntimeErrorBoundary,
424
424
  { key: preserve ? getPreserveBoundaryKey(this.preserveBoundaryEpoch) : `boundary:${this.renderRound}`, resetKey: this.errorEpoch, onError: onRenderError },
425
- createElement(GenUIRenderContext.Provider, { value: renderContext }, createElement(preserve ? this.slot.Component : (renderedComponent as ComponentType<Record<string, unknown>>), { key: "generated-component" })),
425
+ // The cast wraps the whole ternary: @types/react 18 rejects the slot's `Promise<ReactNode>` return, and we ship raw .ts to 18.3 peers.
426
+ createElement(GenUIRenderContext.Provider, { value: renderContext }, createElement((preserve ? this.slot.Component : renderedComponent) as ComponentType<Record<string, unknown>>, { key: "generated-component" })),
426
427
  createElement(RenderNotify, {
427
428
  key: `render-notify:${this.renderRound}`,
428
429
  onCommit: () => {