@maravilla-labs/adapter-react-router 0.1.25 → 0.1.27
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/dist/entry-server-template.d.ts +9 -0
- package/dist/entry-server-template.d.ts.map +1 -0
- package/dist/entry-server-template.js +42 -0
- package/dist/entry-server-template.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/vite-plugin.d.ts.map +1 -1
- package/dist/vite-plugin.js +0 -1
- package/dist/vite-plugin.js.map +1 -1
- package/dist/worker-template.d.ts +6 -1
- package/dist/worker-template.d.ts.map +1 -1
- package/dist/worker-template.js +26 -11
- package/dist/worker-template.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web-stream entry.server.tsx template for Maravilla Runtime.
|
|
3
|
+
*
|
|
4
|
+
* Uses renderToReadableStream (Web Streams API) instead of
|
|
5
|
+
* renderToPipeableStream (Node.js streams). This is required for
|
|
6
|
+
* non-Node runtimes like Maravilla, Cloudflare Workers, and Deno.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ENTRY_SERVER_TEMPLATE = "import type { AppLoadContext, EntryContext } from \"react-router\";\nimport { ServerRouter } from \"react-router\";\nimport { isbot } from \"isbot\";\nimport { renderToReadableStream } from \"react-dom/server\";\n\nexport default async function handleRequest(\n request: Request,\n responseStatusCode: number,\n responseHeaders: Headers,\n routerContext: EntryContext,\n loadContext: AppLoadContext\n) {\n const body = await renderToReadableStream(\n <ServerRouter context={routerContext} url={request.url} />,\n {\n signal: request.signal,\n onError(error: unknown) {\n console.error(error);\n responseStatusCode = 500;\n },\n }\n );\n\n if (isbot(request.headers.get(\"user-agent\") || \"\")) {\n await body.allReady;\n }\n\n responseHeaders.set(\"Content-Type\", \"text/html\");\n return new Response(body, {\n headers: responseHeaders,\n status: responseStatusCode,\n });\n}\n";
|
|
9
|
+
//# sourceMappingURL=entry-server-template.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-server-template.d.ts","sourceRoot":"","sources":["../src/entry-server-template.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,g7BAiCjC,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web-stream entry.server.tsx template for Maravilla Runtime.
|
|
3
|
+
*
|
|
4
|
+
* Uses renderToReadableStream (Web Streams API) instead of
|
|
5
|
+
* renderToPipeableStream (Node.js streams). This is required for
|
|
6
|
+
* non-Node runtimes like Maravilla, Cloudflare Workers, and Deno.
|
|
7
|
+
*/
|
|
8
|
+
export const ENTRY_SERVER_TEMPLATE = `import type { AppLoadContext, EntryContext } from "react-router";
|
|
9
|
+
import { ServerRouter } from "react-router";
|
|
10
|
+
import { isbot } from "isbot";
|
|
11
|
+
import { renderToReadableStream } from "react-dom/server";
|
|
12
|
+
|
|
13
|
+
export default async function handleRequest(
|
|
14
|
+
request: Request,
|
|
15
|
+
responseStatusCode: number,
|
|
16
|
+
responseHeaders: Headers,
|
|
17
|
+
routerContext: EntryContext,
|
|
18
|
+
loadContext: AppLoadContext
|
|
19
|
+
) {
|
|
20
|
+
const body = await renderToReadableStream(
|
|
21
|
+
<ServerRouter context={routerContext} url={request.url} />,
|
|
22
|
+
{
|
|
23
|
+
signal: request.signal,
|
|
24
|
+
onError(error: unknown) {
|
|
25
|
+
console.error(error);
|
|
26
|
+
responseStatusCode = 500;
|
|
27
|
+
},
|
|
28
|
+
}
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
if (isbot(request.headers.get("user-agent") || "")) {
|
|
32
|
+
await body.allReady;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
responseHeaders.set("Content-Type", "text/html");
|
|
36
|
+
return new Response(body, {
|
|
37
|
+
headers: responseHeaders,
|
|
38
|
+
status: responseStatusCode,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
`;
|
|
42
|
+
//# sourceMappingURL=entry-server-template.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entry-server-template.js","sourceRoot":"","sources":["../src/entry-server-template.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiCpC,CAAC"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,KAAK,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAkC,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAkC,MAAM,kBAAkB,CAAC;AACxF,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAOL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAGtC,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC/D,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,yBAA8B,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"vite-plugin.d.ts","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,MAAM,CAAC;AACnC,OAAO,EAOL,KAAK,cAAc,EACpB,MAAM,8BAA8B,CAAC;AAGtC,MAAM,WAAW,yBAA0B,SAAQ,cAAc;IAC/D,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yEAAyE;IACzE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,yDAAyD;IACzD,eAAe,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,OAAO,GAAE,yBAA8B,GAAG,MAAM,CAwHpF"}
|
package/dist/vite-plugin.js
CHANGED
package/dist/vite-plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite-plugin.js","sourceRoot":"","sources":["../src/vite-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,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CAAC,GAAG,CAAC,0BAA0B,CAAC,CAAC;YACxC,OAAO,CAAC,GAAG,CAAC,kCAAkC,GAAG,EAAE,CAAC,CAAC;QACvD,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -3,6 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The __SERVER_BUILD__ placeholder is replaced at build time with the path
|
|
5
5
|
* to the React Router server build output.
|
|
6
|
+
*
|
|
7
|
+
* NOTE: No top-level await or ES module import statements — our runtime
|
|
8
|
+
* wraps bundles in an IIFE which doesn't support them. esbuild resolves
|
|
9
|
+
* all imports at bundle time. Lazy initialization in handleRequest avoids
|
|
10
|
+
* top-level await.
|
|
6
11
|
*/
|
|
7
|
-
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\nimport * as build from '__SERVER_BUILD__';\
|
|
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";
|
|
8
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
|
|
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"}
|
package/dist/worker-template.js
CHANGED
|
@@ -4,23 +4,26 @@ import { WORKER_POLYFILLS } from '@maravilla-labs/adapter-core';
|
|
|
4
4
|
*
|
|
5
5
|
* The __SERVER_BUILD__ placeholder is replaced at build time with the path
|
|
6
6
|
* to the React Router server build output.
|
|
7
|
+
*
|
|
8
|
+
* NOTE: No top-level await or ES module import statements — our runtime
|
|
9
|
+
* wraps bundles in an IIFE which doesn't support them. esbuild resolves
|
|
10
|
+
* all imports at bundle time. Lazy initialization in handleRequest avoids
|
|
11
|
+
* top-level await.
|
|
7
12
|
*/
|
|
8
13
|
export const WORKER_TEMPLATE = `${WORKER_POLYFILLS}
|
|
9
14
|
|
|
10
|
-
// Import the React Router server build
|
|
15
|
+
// Import the React Router server build (resolved by esbuild at bundle time)
|
|
11
16
|
import * as build from '__SERVER_BUILD__';
|
|
17
|
+
import { createRequestHandler } from 'react-router';
|
|
12
18
|
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
const { createRequestHandler } = await import('react-router');
|
|
16
|
-
|
|
17
|
-
const handler = createRequestHandler(build, 'production');
|
|
19
|
+
// Lazy-init the handler on first request (avoids top-level await)
|
|
20
|
+
let handler;
|
|
18
21
|
|
|
19
|
-
/**
|
|
20
|
-
* Main request handler for the Maravilla runtime.
|
|
21
|
-
* Called by the runtime for each incoming HTTP request.
|
|
22
|
-
*/
|
|
23
22
|
async function handleRequest(request) {
|
|
23
|
+
if (!handler) {
|
|
24
|
+
handler = createRequestHandler(build, 'production');
|
|
25
|
+
}
|
|
26
|
+
|
|
24
27
|
// Re-apply polyfills if needed (worker reuse)
|
|
25
28
|
if (globalThis.Request !== EnhancedRequest) {
|
|
26
29
|
globalThis.Request = EnhancedRequest;
|
|
@@ -38,7 +41,19 @@ async function handleRequest(request) {
|
|
|
38
41
|
queue: globalThis.platform?.queue,
|
|
39
42
|
};
|
|
40
43
|
|
|
41
|
-
|
|
44
|
+
try {
|
|
45
|
+
const response = await handler(request, loadContext);
|
|
46
|
+
console.log('[maravilla] Response status:', response.status);
|
|
47
|
+
if (response.status >= 500) {
|
|
48
|
+
const body = await response.clone().text();
|
|
49
|
+
console.error('[maravilla] 500 response body:', body || '(empty)');
|
|
50
|
+
}
|
|
51
|
+
return response;
|
|
52
|
+
} catch (error) {
|
|
53
|
+
console.error('[maravilla] handleRequest error:', error?.message || error);
|
|
54
|
+
console.error('[maravilla] stack:', error?.stack || 'no stack');
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
42
57
|
}
|
|
43
58
|
|
|
44
59
|
globalThis.handleRequest = handleRequest;
|
|
@@ -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
|
|
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"}
|