@maravilla-labs/adapter-react-router 0.2.6 → 0.2.7

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.
@@ -9,5 +9,5 @@
9
9
  * all imports at bundle time. Lazy initialization in handleRequest avoids
10
10
  * top-level await.
11
11
  */
12
- export declare const WORKER_TEMPLATE = "// Maravilla Runtime Worker Polyfills\n// Shared across all framework adapters\n\nconst originalFetch = globalThis.fetch;\nconst OriginalRequest = globalThis.Request;\n\nclass EnhancedRequest extends OriginalRequest {\n constructor(input, init) {\n if (typeof input === 'string') {\n try {\n super(input, init);\n } catch (e) {\n if (globalThis.location && e.message && e.message.includes('relative')) {\n try {\n const absoluteUrl = new URL(input, globalThis.location.href);\n super(absoluteUrl.href, init);\n } catch (e2) {\n throw e;\n }\n } else {\n throw e;\n }\n }\n return;\n }\n\n if (input && typeof input === 'object' && !(input instanceof OriginalRequest)) {\n const url = input.url || input.href || input.toString();\n if (!url) {\n throw new TypeError('Request must have a URL');\n }\n const newInit = {\n method: input.method || init?.method || 'GET',\n headers: input.headers || init?.headers,\n body: input.body || init?.body,\n mode: input.mode || init?.mode,\n credentials: input.credentials || init?.credentials,\n cache: input.cache || init?.cache,\n redirect: input.redirect || init?.redirect,\n referrer: input.referrer || init?.referrer,\n referrerPolicy: input.referrerPolicy || init?.referrerPolicy,\n integrity: input.integrity || init?.integrity,\n keepalive: input.keepalive || init?.keepalive,\n signal: input.signal || init?.signal,\n ...init\n };\n super(url, newInit);\n return;\n }\n\n super(input, init);\n }\n}\n\nglobalThis.Request = EnhancedRequest;\n\nglobalThis.fetch = function enhancedFetch(input, init) {\n let request;\n\n if (input instanceof Request) {\n request = input;\n } else if (typeof input === 'string') {\n if (input.startsWith('http://') || input.startsWith('https://')) {\n request = new Request(input, init);\n } else if (globalThis.location) {\n try {\n const absoluteUrl = new URL(input, globalThis.location.href);\n request = new Request(absoluteUrl.href, init);\n } catch (e) {\n console.error('Failed to resolve relative URL:', input, 'against', globalThis.location.href);\n throw e;\n }\n } else {\n console.error('Cannot resolve relative URL without globalThis.location:', input);\n throw new Error('Cannot resolve relative URL without a base URL');\n }\n } else if (input && typeof input === 'object') {\n request = new Request(input, init);\n } else {\n throw new TypeError('First argument must be a string, Request, or URL');\n }\n\n return originalFetch(request);\n};\n\n\n// Import the React Router server build (resolved by esbuild at bundle time)\nimport * as build from '__SERVER_BUILD__';\nimport { createRequestHandler } from 'react-router';\n\n// Lazy-init the handler on first request (avoids top-level await)\nlet handler;\n\nasync function handleRequest(request) {\n if (!handler) {\n handler = createRequestHandler(build, 'production');\n }\n\n // Re-apply polyfills if needed (worker reuse)\n if (globalThis.Request !== EnhancedRequest) {\n globalThis.Request = EnhancedRequest;\n globalThis.fetch = enhancedFetch;\n }\n\n // React Router v7's singleFetchAction hard-invariants on request.signal\n // being an AbortSignal. The runtime attaches one when it constructs the\n // Request (crates/runtime/src/worker_core/streaming_js.rs), but that\n // signal can be lost across the custom Request polyfill's re-construction\n // paths or React Router's internal single-fetch wrapping. Guarantee one\n // here at the last mile \u2014 keeping the controller on a local const so its\n // signal isn't GC'd out from under us mid-handler.\n const abortController = new AbortController();\n const requestForHandler = request.signal\n ? request\n : new Request(request, { signal: abortController.signal });\n\n // Build the load context that React Router passes to loaders/actions.\n // Users access this via: export async function loader({ context }) { ... }\n const loadContext = {\n platform: globalThis.platform,\n env: globalThis.platform?.env || {},\n kv: globalThis.platform?.kv,\n db: globalThis.platform?.db,\n storage: globalThis.platform?.storage,\n queue: globalThis.platform?.queue,\n };\n\n try {\n const response = await handler(requestForHandler, loadContext);\n console.log('[maravilla] Response status:', response.status);\n if (response.status >= 500) {\n const body = await response.clone().text();\n console.error('[maravilla] 500 response body:', body || '(empty)');\n }\n return response;\n } catch (error) {\n console.error('[maravilla] handleRequest error:', error?.message || error);\n console.error('[maravilla] stack:', error?.stack || 'no stack');\n throw error;\n }\n}\n\nglobalThis.handleRequest = handleRequest;\n";
12
+ export declare const WORKER_TEMPLATE = "// Maravilla Runtime Worker Polyfills\n// Shared across all framework adapters\n\nconst originalFetch = globalThis.fetch;\nconst OriginalRequest = globalThis.Request;\n\nclass EnhancedRequest extends OriginalRequest {\n constructor(input, init) {\n if (typeof input === 'string') {\n try {\n super(input, init);\n } catch (e) {\n if (globalThis.location && e.message && e.message.includes('relative')) {\n try {\n const absoluteUrl = new URL(input, globalThis.location.href);\n super(absoluteUrl.href, init);\n } catch (e2) {\n throw e;\n }\n } else {\n throw e;\n }\n }\n return;\n }\n\n if (input && typeof input === 'object' && !(input instanceof OriginalRequest)) {\n const url = input.url || input.href || input.toString();\n if (!url) {\n throw new TypeError('Request must have a URL');\n }\n const newInit = {\n method: input.method || init?.method || 'GET',\n headers: input.headers || init?.headers,\n body: input.body || init?.body,\n mode: input.mode || init?.mode,\n credentials: input.credentials || init?.credentials,\n cache: input.cache || init?.cache,\n redirect: input.redirect || init?.redirect,\n referrer: input.referrer || init?.referrer,\n referrerPolicy: input.referrerPolicy || init?.referrerPolicy,\n integrity: input.integrity || init?.integrity,\n keepalive: input.keepalive || init?.keepalive,\n signal: input.signal || init?.signal,\n ...init\n };\n super(url, newInit);\n return;\n }\n\n super(input, init);\n }\n}\n\nglobalThis.Request = EnhancedRequest;\n\nglobalThis.fetch = function enhancedFetch(input, init) {\n let request;\n\n if (input instanceof Request) {\n request = input;\n } else if (typeof input === 'string') {\n if (input.startsWith('http://') || input.startsWith('https://')) {\n request = new Request(input, init);\n } else if (globalThis.location) {\n try {\n const absoluteUrl = new URL(input, globalThis.location.href);\n request = new Request(absoluteUrl.href, init);\n } catch (e) {\n console.error('Failed to resolve relative URL:', input, 'against', globalThis.location.href);\n throw e;\n }\n } else {\n console.error('Cannot resolve relative URL without globalThis.location:', input);\n throw new Error('Cannot resolve relative URL without a base URL');\n }\n } else if (input && typeof input === 'object') {\n request = new Request(input, init);\n } else {\n throw new TypeError('First argument must be a string, Request, or URL');\n }\n\n return originalFetch(request);\n};\n\n\n// Import the React Router server build (resolved by esbuild at bundle time)\nimport * as build from '__SERVER_BUILD__';\nimport { createRequestHandler } from 'react-router';\n\n// Lazy-init the handler on first request (avoids top-level await)\nlet handler;\n\nasync function handleRequest(request) {\n if (!handler) {\n handler = createRequestHandler(build, 'production');\n }\n\n // Re-apply polyfills if needed (worker reuse)\n if (globalThis.Request !== EnhancedRequest) {\n globalThis.Request = EnhancedRequest;\n globalThis.fetch = enhancedFetch;\n }\n\n // Build the load context that React Router passes to loaders/actions.\n // Users access this via: export async function loader({ context }) { ... }\n const loadContext = {\n platform: globalThis.platform,\n env: globalThis.platform?.env || {},\n kv: globalThis.platform?.kv,\n db: globalThis.platform?.db,\n storage: globalThis.platform?.storage,\n queue: globalThis.platform?.queue,\n };\n\n try {\n const response = await handler(request, loadContext);\n console.log('[maravilla] Response status:', response.status);\n if (response.status >= 500) {\n const body = await response.clone().text();\n console.error('[maravilla] 500 response body:', body || '(empty)');\n }\n return response;\n } catch (error) {\n console.error('[maravilla] handleRequest error:', error?.message || error);\n console.error('[maravilla] stack:', error?.stack || 'no stack');\n throw error;\n }\n}\n\nglobalThis.handleRequest = handleRequest;\n";
13
13
  //# sourceMappingURL=worker-template.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-template.d.ts","sourceRoot":"","sources":["../src/worker-template.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,o8JA2D3B,CAAC"}
1
+ {"version":3,"file":"worker-template.d.ts","sourceRoot":"","sources":["../src/worker-template.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,eAAO,MAAM,eAAe,swIA+C3B,CAAC"}
@@ -30,18 +30,6 @@ async function handleRequest(request) {
30
30
  globalThis.fetch = enhancedFetch;
31
31
  }
32
32
 
33
- // React Router v7's singleFetchAction hard-invariants on request.signal
34
- // being an AbortSignal. The runtime attaches one when it constructs the
35
- // Request (crates/runtime/src/worker_core/streaming_js.rs), but that
36
- // signal can be lost across the custom Request polyfill's re-construction
37
- // paths or React Router's internal single-fetch wrapping. Guarantee one
38
- // here at the last mile — keeping the controller on a local const so its
39
- // signal isn't GC'd out from under us mid-handler.
40
- const abortController = new AbortController();
41
- const requestForHandler = request.signal
42
- ? request
43
- : new Request(request, { signal: abortController.signal });
44
-
45
33
  // Build the load context that React Router passes to loaders/actions.
46
34
  // Users access this via: export async function loader({ context }) { ... }
47
35
  const loadContext = {
@@ -54,7 +42,7 @@ async function handleRequest(request) {
54
42
  };
55
43
 
56
44
  try {
57
- const response = await handler(requestForHandler, loadContext);
45
+ const response = await handler(request, loadContext);
58
46
  console.log('[maravilla] Response status:', response.status);
59
47
  if (response.status >= 500) {
60
48
  const body = await response.clone().text();
@@ -1 +1 @@
1
- {"version":3,"file":"worker-template.js","sourceRoot":"","sources":["../src/worker-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2DjD,CAAC"}
1
+ {"version":3,"file":"worker-template.js","sourceRoot":"","sources":["../src/worker-template.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAEhE;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,GAAG,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+CjD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@maravilla-labs/adapter-react-router",
3
- "version": "0.2.6",
3
+ "version": "0.2.7",
4
4
  "description": "React Router 7 adapter for Maravilla Runtime",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",