react-bun-ssr 0.1.1 → 0.3.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.
@@ -2,6 +2,7 @@ import {
2
2
  createContext,
3
3
  useContext,
4
4
  type ComponentType,
5
+ type Context,
5
6
  type ReactElement,
6
7
  type ReactNode,
7
8
  } from "react";
@@ -15,8 +16,29 @@ interface RuntimeState {
15
16
  reset: () => void;
16
17
  }
17
18
 
18
- const RuntimeContext = createContext<RuntimeState | null>(null);
19
- const OutletContext = createContext<ReactNode>(null);
19
+ const RUNTIME_CONTEXT_KEY = Symbol.for("react-bun-ssr.runtime-context");
20
+ const OUTLET_CONTEXT_KEY = Symbol.for("react-bun-ssr.outlet-context");
21
+
22
+ function getGlobalContext<T>(key: symbol, createValue: () => Context<T>): Context<T> {
23
+ const globalRegistry = globalThis as typeof globalThis & { [contextKey: symbol]: Context<T> | undefined };
24
+ const existing = globalRegistry[key];
25
+ if (existing) {
26
+ return existing;
27
+ }
28
+
29
+ const context = createValue();
30
+ globalRegistry[key] = context;
31
+ return context;
32
+ }
33
+
34
+ const RuntimeContext = getGlobalContext<RuntimeState | null>(
35
+ RUNTIME_CONTEXT_KEY,
36
+ () => createContext<RuntimeState | null>(null),
37
+ );
38
+ const OutletContext = getGlobalContext<ReactNode>(
39
+ OUTLET_CONTEXT_KEY,
40
+ () => createContext<ReactNode>(null),
41
+ );
20
42
  const NOOP_RESET = () => undefined;
21
43
 
22
44
  function useRuntimeState(): RuntimeState {
@@ -123,7 +123,7 @@ export interface ApiRouteModule {
123
123
 
124
124
  export interface ResponseHeaderRule {
125
125
  source: string;
126
- headers: Record<string, string>;
126
+ headers: Record<string, string | null>;
127
127
  }
128
128
 
129
129
  export interface ResolvedResponseHeaderRule extends ResponseHeaderRule {
@@ -254,7 +254,17 @@ export interface TransitionRedirectChunk {
254
254
  status: number;
255
255
  }
256
256
 
257
- export type TransitionChunk = TransitionInitialChunk | TransitionDeferredChunk | TransitionRedirectChunk;
257
+ export interface TransitionDocumentChunk {
258
+ type: "document";
259
+ location: string;
260
+ status: number;
261
+ }
262
+
263
+ export type TransitionChunk =
264
+ | TransitionInitialChunk
265
+ | TransitionDeferredChunk
266
+ | TransitionRedirectChunk
267
+ | TransitionDocumentChunk;
258
268
 
259
269
  export interface RouteModuleBundle {
260
270
  root: RouteModule;
@@ -274,6 +284,7 @@ export interface ServerRuntimeOptions {
274
284
  devAssets?: Record<string, BuildRouteAsset>;
275
285
  getDevAssets?: () => Record<string, BuildRouteAsset>;
276
286
  reloadVersion?: () => number;
287
+ routeManifestVersion?: () => number;
277
288
  subscribeReload?: (listener: (version: number) => void) => (() => void) | void;
278
289
  resolvePaths?: () => Partial<ResolvedConfig>;
279
290
  onBeforeRequest?: () => Promise<void>;
@@ -85,6 +85,9 @@ export function sanitizeErrorMessage(error: unknown, production: boolean): strin
85
85
  if (error instanceof Error) {
86
86
  return error.message;
87
87
  }
88
+ if (typeof error === "string") {
89
+ return error;
90
+ }
88
91
  return Bun.inspect(error);
89
92
  }
90
93
  return "Internal Server Error";
package/package.json CHANGED
@@ -1,9 +1,12 @@
1
1
  {
2
2
  "name": "react-bun-ssr",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "sideEffects": false,
7
+ "workspaces": [
8
+ "app"
9
+ ],
7
10
  "types": "./framework/runtime/index.ts",
8
11
  "repository": {
9
12
  "type": "git",
@@ -44,9 +47,16 @@
44
47
  "start": "bun bin/rbssr.ts start",
45
48
  "typecheck": "bun bin/rbssr.ts typecheck",
46
49
  "test": "bun bin/rbssr.ts test",
47
- "test:unit": "bun test ./tests/unit",
48
- "test:integration": "bun test ./tests/integration",
50
+ "test:unit": "bun test ./tests/framework/unit ./tests/docs-app/unit",
51
+ "test:integration": "bun test ./tests/framework/integration ./tests/docs-app/integration",
52
+ "test:consumer": "RBSSR_RUN_CONSUMER_SMOKE=1 bun test ./tests/framework/integration/package-smoke.test.ts",
53
+ "test:watch": "bunx chokidar-cli \"framework/**/*\" \"app/**/*\" \"scripts/**/*\" \"tests/**/*\" -c \"bun run test:unit && bun run test:integration\"",
54
+ "test:watch:framework:unit": "bunx chokidar-cli \"framework/**/*\" \"scripts/**/*\" \"tests/framework/unit/**/*\" \"tests/framework/helpers/**/*\" -c \"bun test ./tests/framework/unit\"",
55
+ "test:watch:framework:integration": "bunx chokidar-cli \"framework/**/*\" \"scripts/**/*\" \"tests/framework/integration/**/*\" \"tests/framework/helpers/**/*\" \"app/**/*\" -c \"bun test ./tests/framework/integration\"",
56
+ "test:watch:docs-app:unit": "bunx chokidar-cli \"app/**/*\" \"tests/docs-app/unit/**/*\" -c \"bun test ./tests/docs-app/unit\"",
57
+ "test:watch:docs-app:integration": "bunx chokidar-cli \"app/**/*\" \"scripts/**/*\" \"tests/docs-app/integration/**/*\" -c \"bun test ./tests/docs-app/integration\"",
49
58
  "test:e2e": "bunx playwright test",
59
+ "test:e2e:ui": "bunx playwright test --ui",
50
60
  "docs:dev": "bun run scripts/generate-api-docs.ts && bun run scripts/build-docs-manifest.ts && bun run scripts/build-search-index.ts && bun run scripts/build-blog-manifest.ts && bun run scripts/build-sitemap.ts && bun bin/rbssr.ts dev",
51
61
  "docs:build": "bun run scripts/docs-build.ts",
52
62
  "docs:check": "bun run scripts/check-docs.ts",
@@ -64,9 +74,5 @@
64
74
  "react": "^19",
65
75
  "react-dom": "^19",
66
76
  "typescript": "^5.9.2"
67
- },
68
- "dependencies": {
69
- "@datadog/browser-rum": "^6.28.1",
70
- "@datadog/browser-rum-react": "^6.28.1"
71
77
  }
72
78
  }