@canonical/react-ssr 0.22.0 → 0.24.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.
- package/dist/esm/bin/serve-express.js +86 -0
- package/dist/esm/bin/serve-express.js.map +1 -0
- package/dist/esm/index.js +3 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/lib/adapter/index.js +2 -0
- package/dist/esm/lib/adapter/index.js.map +1 -0
- package/dist/esm/lib/adapter/mime.js +85 -0
- package/dist/esm/lib/adapter/mime.js.map +1 -0
- package/dist/esm/lib/adapter/types.js +10 -0
- package/dist/esm/lib/adapter/types.js.map +1 -0
- package/dist/esm/lib/index.js +4 -0
- package/dist/esm/lib/index.js.map +1 -0
- package/dist/esm/lib/renderer/Extractor.js +172 -0
- package/dist/esm/lib/renderer/Extractor.js.map +1 -0
- package/dist/esm/lib/renderer/JSXRenderer.js +283 -0
- package/dist/esm/lib/renderer/JSXRenderer.js.map +1 -0
- package/dist/esm/lib/renderer/SitemapRenderer.js +241 -0
- package/dist/esm/lib/renderer/SitemapRenderer.js.map +1 -0
- package/dist/esm/lib/renderer/TextRenderer.js +124 -0
- package/dist/esm/lib/renderer/TextRenderer.js.map +1 -0
- package/dist/esm/lib/renderer/constants.js.map +1 -0
- package/dist/esm/lib/renderer/index.js +6 -0
- package/dist/esm/lib/renderer/index.js.map +1 -0
- package/dist/esm/lib/renderer/types.js +10 -0
- package/dist/esm/lib/renderer/types.js.map +1 -0
- package/dist/esm/lib/server/index.js +3 -0
- package/dist/esm/lib/server/index.js.map +1 -0
- package/dist/esm/lib/server/serveStream.js +53 -0
- package/dist/esm/lib/server/serveStream.js.map +1 -0
- package/dist/esm/lib/server/serveString.js +49 -0
- package/dist/esm/lib/server/serveString.js.map +1 -0
- package/dist/types/bin/serve-express.d.ts +24 -0
- package/dist/types/bin/serve-express.d.ts.map +1 -0
- package/dist/types/index.d.ts +3 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/lib/adapter/index.d.ts +3 -0
- package/dist/types/lib/adapter/index.d.ts.map +1 -0
- package/dist/types/lib/adapter/mime.d.ts +43 -0
- package/dist/types/lib/adapter/mime.d.ts.map +1 -0
- package/dist/types/lib/adapter/types.d.ts +85 -0
- package/dist/types/lib/adapter/types.d.ts.map +1 -0
- package/dist/types/lib/index.d.ts +4 -0
- package/dist/types/lib/index.d.ts.map +1 -0
- package/dist/types/lib/renderer/Extractor.d.ts +93 -0
- package/dist/types/lib/renderer/Extractor.d.ts.map +1 -0
- package/dist/types/lib/renderer/JSXRenderer.d.ts +163 -0
- package/dist/types/lib/renderer/JSXRenderer.d.ts.map +1 -0
- package/dist/types/lib/renderer/SitemapRenderer.d.ts +153 -0
- package/dist/types/lib/renderer/SitemapRenderer.d.ts.map +1 -0
- package/dist/types/lib/renderer/TextRenderer.d.ts +83 -0
- package/dist/types/lib/renderer/TextRenderer.d.ts.map +1 -0
- package/dist/types/lib/renderer/constants.d.ts.map +1 -0
- package/dist/types/lib/renderer/index.d.ts +7 -0
- package/dist/types/lib/renderer/index.d.ts.map +1 -0
- package/dist/types/lib/renderer/types.d.ts +161 -0
- package/dist/types/lib/renderer/types.d.ts.map +1 -0
- package/dist/types/lib/server/index.d.ts +3 -0
- package/dist/types/lib/server/index.d.ts.map +1 -0
- package/dist/types/lib/server/serveStream.d.ts +41 -0
- package/dist/types/lib/server/serveStream.d.ts.map +1 -0
- package/dist/types/lib/server/serveString.d.ts +37 -0
- package/dist/types/lib/server/serveString.d.ts.map +1 -0
- package/package.json +37 -17
- package/dist/esm/renderer/Extractor.js +0 -127
- package/dist/esm/renderer/Extractor.js.map +0 -1
- package/dist/esm/renderer/JSXRenderer.js +0 -168
- package/dist/esm/renderer/JSXRenderer.js.map +0 -1
- package/dist/esm/renderer/constants.js.map +0 -1
- package/dist/esm/renderer/index.js +0 -4
- package/dist/esm/renderer/index.js.map +0 -1
- package/dist/esm/renderer/types.js +0 -2
- package/dist/esm/renderer/types.js.map +0 -1
- package/dist/esm/server/index.js +0 -2
- package/dist/esm/server/index.js.map +0 -1
- package/dist/esm/server/serve-express.js +0 -58
- package/dist/esm/server/serve-express.js.map +0 -1
- package/dist/esm/server/serve.js +0 -41
- package/dist/esm/server/serve.js.map +0 -1
- package/dist/types/renderer/Extractor.d.ts +0 -68
- package/dist/types/renderer/Extractor.d.ts.map +0 -1
- package/dist/types/renderer/JSXRenderer.d.ts +0 -71
- package/dist/types/renderer/JSXRenderer.d.ts.map +0 -1
- package/dist/types/renderer/constants.d.ts.map +0 -1
- package/dist/types/renderer/index.d.ts +0 -5
- package/dist/types/renderer/index.d.ts.map +0 -1
- package/dist/types/renderer/types.d.ts +0 -35
- package/dist/types/renderer/types.d.ts.map +0 -1
- package/dist/types/server/index.d.ts +0 -2
- package/dist/types/server/index.d.ts.map +0 -1
- package/dist/types/server/serve-express.d.ts +0 -3
- package/dist/types/server/serve-express.d.ts.map +0 -1
- package/dist/types/server/serve.d.ts +0 -30
- package/dist/types/server/serve.d.ts.map +0 -1
- /package/dist/esm/{renderer → lib/renderer}/constants.js +0 -0
- /package/dist/types/{renderer → lib/renderer}/constants.d.ts +0 -0
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from "./constants.js";
|
|
2
|
+
export { default as Extractor } from "./Extractor.js";
|
|
3
|
+
export { default as JSXRenderer } from "./JSXRenderer.js";
|
|
4
|
+
export { default as SitemapRenderer } from "./SitemapRenderer.js";
|
|
5
|
+
export { default as TextRenderer } from "./TextRenderer.js";
|
|
6
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/renderer/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type contracts for the SSR renderer domain.
|
|
3
|
+
*
|
|
4
|
+
* These types define the interface between renderers (which produce HTML or XML
|
|
5
|
+
* content and record metadata like status codes) and server adapters (which
|
|
6
|
+
* deliver that content over HTTP). Renderers are transport-agnostic — they
|
|
7
|
+
* never write to a response object.
|
|
8
|
+
*/
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/lib/renderer/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convenience wrapper that adapts a renderer factory into a Node.js `(req, res)` handler
|
|
3
|
+
* for pipeable stream rendering.
|
|
4
|
+
*
|
|
5
|
+
* Calls the factory with each incoming request. The factory is expected to construct
|
|
6
|
+
* a renderer (with per-request context like locale, auth, theme) and call
|
|
7
|
+
* `renderToPipeableStream()` on it. This wrapper then awaits `statusReady`, writes
|
|
8
|
+
* headers with the renderer's `statusCode`, and pipes the stream to the response.
|
|
9
|
+
*
|
|
10
|
+
* Does not set `Content-Type` — the consumer controls headers through the factory
|
|
11
|
+
* or by wrapping this handler. Defaults to `text/html; charset=utf-8`.
|
|
12
|
+
*
|
|
13
|
+
* @note This function is impure — it writes to the HTTP response.
|
|
14
|
+
*
|
|
15
|
+
* @param factory - A function that receives the request and returns a renderer.
|
|
16
|
+
* The renderer must have `renderToPipeableStream()`, `statusCode`, and `statusReady`.
|
|
17
|
+
* @returns A Node.js request handler suitable for `app.use()` or `http.createServer()`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* import { JSXRenderer } from "@canonical/react-ssr/renderer";
|
|
22
|
+
* import { serveStream } from "@canonical/react-ssr/server";
|
|
23
|
+
*
|
|
24
|
+
* app.use(serveStream((req) => {
|
|
25
|
+
* return new JSXRenderer(
|
|
26
|
+
* EntryServer,
|
|
27
|
+
* { locale: getLocale(req), user: getUser(req) },
|
|
28
|
+
* { htmlString },
|
|
29
|
+
* );
|
|
30
|
+
* }));
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function serveStream(factory) {
|
|
34
|
+
return async (req, res) => {
|
|
35
|
+
try {
|
|
36
|
+
const renderer = factory(req);
|
|
37
|
+
const result = renderer.renderToPipeableStream();
|
|
38
|
+
await renderer.statusReady;
|
|
39
|
+
res.writeHead(renderer.statusCode, {
|
|
40
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
41
|
+
});
|
|
42
|
+
result.pipe(res);
|
|
43
|
+
/* v8 ignore next -- finish event fires after stream completes; not triggered in unit tests */
|
|
44
|
+
res.on("finish", () => res.end());
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
console.error("Error during rendering:", error);
|
|
48
|
+
res.statusCode = 500;
|
|
49
|
+
res.end("Internal server error");
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=serveStream.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serveStream.js","sourceRoot":"","sources":["../../../../src/lib/server/serveStream.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,WAAW,CACzB,OAMC;IAED,OAAO,KAAK,EAAE,GAAoB,EAAE,GAAmB,EAAE,EAAE;QACzD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAC9B,MAAM,MAAM,GAAG,QAAQ,CAAC,sBAAsB,EAAE,CAAC;YACjD,MAAM,QAAQ,CAAC,WAAW,CAAC;YAC3B,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE;gBACjC,cAAc,EAAE,0BAA0B;aAC3C,CAAC,CAAC;YACH,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;YACjB,8FAA8F;YAC9F,GAAG,CAAC,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,CAAC;QACpC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;YAChD,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Convenience wrapper that adapts a renderer factory into a Node.js `(req, res)` handler
|
|
3
|
+
* for string rendering.
|
|
4
|
+
*
|
|
5
|
+
* Calls the factory with each incoming request. The factory is expected to construct
|
|
6
|
+
* a renderer (with per-request context like locale, auth, theme) and call
|
|
7
|
+
* `renderToString()` on it. This wrapper then writes headers with the renderer's
|
|
8
|
+
* `statusCode` and sends the HTML string as the response body.
|
|
9
|
+
*
|
|
10
|
+
* Does not set `Content-Type` — defaults to `text/html; charset=utf-8`.
|
|
11
|
+
*
|
|
12
|
+
* @note This function is impure — it writes to the HTTP response.
|
|
13
|
+
*
|
|
14
|
+
* @param factory - A function that receives the request and returns a renderer.
|
|
15
|
+
* The renderer must have `renderToString()` and `statusCode`.
|
|
16
|
+
* @returns A Node.js request handler suitable for `app.use()` or `http.createServer()`.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* import { JSXRenderer } from "@canonical/react-ssr/renderer";
|
|
21
|
+
* import { serveString } from "@canonical/react-ssr/server";
|
|
22
|
+
*
|
|
23
|
+
* app.use(serveString((req) => {
|
|
24
|
+
* return new JSXRenderer(
|
|
25
|
+
* EntryServer,
|
|
26
|
+
* { locale: getLocale(req), user: getUser(req) },
|
|
27
|
+
* { htmlString },
|
|
28
|
+
* );
|
|
29
|
+
* }));
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export function serveString(factory) {
|
|
33
|
+
return (req, res) => {
|
|
34
|
+
try {
|
|
35
|
+
const renderer = factory(req);
|
|
36
|
+
const body = renderer.renderToString();
|
|
37
|
+
res.writeHead(renderer.statusCode, {
|
|
38
|
+
"Content-Type": "text/html; charset=utf-8",
|
|
39
|
+
});
|
|
40
|
+
res.end(body);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error("Error during rendering:", error);
|
|
44
|
+
res.statusCode = 500;
|
|
45
|
+
res.end("Internal server error");
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
//# sourceMappingURL=serveString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serveString.js","sourceRoot":"","sources":["../../../../src/lib/server/serveString.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,UAAU,WAAW,CACzB,OAGC;IAED,OAAO,CAAC,GAAoB,EAAE,GAAmB,EAAE,EAAE;QACnD,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC;YAC9B,MAAM,IAAI,GAAG,QAAQ,CAAC,cAAc,EAAE,CAAC;YACvC,GAAG,CAAC,SAAS,CAAC,QAAQ,CAAC,UAAU,EAAE;gBACjC,cAAc,EAAE,0BAA0B;aAC3C,CAAC,CAAC;YACH,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAChB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,yBAAyB,EAAE,KAAK,CAAC,CAAC;YAChD,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC;YACrB,GAAG,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Standalone Express server for serving an SSR application.
|
|
4
|
+
*
|
|
5
|
+
* Dynamically imports a renderer module that exports a factory function.
|
|
6
|
+
* The factory receives a Node `IncomingMessage` and returns a renderer.
|
|
7
|
+
* Supports both streaming and string rendering modes.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```sh
|
|
11
|
+
* # String rendering (default), one static directory
|
|
12
|
+
* serve-express dist/server/renderer.js --static assets:dist/client/assets
|
|
13
|
+
*
|
|
14
|
+
* # Streaming, multiple static directories
|
|
15
|
+
* serve-express dist/server/renderer.js --streaming \
|
|
16
|
+
* --static assets:dist/client/assets \
|
|
17
|
+
* --static public:dist/client/public
|
|
18
|
+
*
|
|
19
|
+
* # Custom port
|
|
20
|
+
* serve-express dist/server/renderer.js -p 3000 --static assets:dist/client/assets
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export {};
|
|
24
|
+
//# sourceMappingURL=serve-express.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serve-express.d.ts","sourceRoot":"","sources":["../../../src/bin/serve-express.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;GAoBG"}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export * as
|
|
2
|
-
export * as
|
|
1
|
+
export * as adapter from "./lib/adapter/index.js";
|
|
2
|
+
export * as renderer from "./lib/renderer/index.js";
|
|
3
|
+
export * as server from "./lib/server/index.js";
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,wBAAwB,CAAC;AAClD,OAAO,KAAK,QAAQ,MAAM,yBAAyB,CAAC;AACpD,OAAO,KAAK,MAAM,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/adapter/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzE,YAAY,EACV,WAAW,EACX,eAAe,EACf,cAAc,EACd,eAAe,EACf,iBAAiB,GAClB,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal MIME type lookup for static asset serving.
|
|
3
|
+
*
|
|
4
|
+
* Covers the file types commonly produced by Vite builds (scripts, styles,
|
|
5
|
+
* images, fonts, source maps). Adapters use this when the platform doesn't
|
|
6
|
+
* provide native MIME detection (Cloudflare R2, Deno filesystem).
|
|
7
|
+
*
|
|
8
|
+
* No external dependencies — the lookup is a plain record.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Look up the MIME type for a file path based on its extension.
|
|
12
|
+
*
|
|
13
|
+
* Returns `"application/octet-stream"` for unknown extensions.
|
|
14
|
+
*
|
|
15
|
+
* @param path - File path or name (e.g. `"main.abc123.js"`, `"/assets/logo.png"`).
|
|
16
|
+
* @returns The MIME type string.
|
|
17
|
+
*/
|
|
18
|
+
export declare function getMimeType(path: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Build a `Cache-Control` header value from a cache configuration.
|
|
21
|
+
*
|
|
22
|
+
* @param cache - Cache configuration with optional directives.
|
|
23
|
+
* @returns A `Cache-Control` header string.
|
|
24
|
+
*/
|
|
25
|
+
export declare function buildCacheControl(cache: {
|
|
26
|
+
maxAge?: number;
|
|
27
|
+
sMaxAge?: number;
|
|
28
|
+
staleWhileRevalidate?: number;
|
|
29
|
+
}): string;
|
|
30
|
+
/**
|
|
31
|
+
* Match a URL pathname against a simple pattern.
|
|
32
|
+
*
|
|
33
|
+
* Supports three forms:
|
|
34
|
+
* - Exact match: `"/sitemap.xml"` matches only `"/sitemap.xml"`
|
|
35
|
+
* - Wildcard suffix: `"/api/*"` matches `"/api/"` and anything below
|
|
36
|
+
* - Catch-all: `"/*"` matches everything
|
|
37
|
+
*
|
|
38
|
+
* @param pattern - The route pattern.
|
|
39
|
+
* @param pathname - The URL pathname to test.
|
|
40
|
+
* @returns `true` if the pathname matches the pattern.
|
|
41
|
+
*/
|
|
42
|
+
export declare function matchPattern(pattern: string, pathname: string): boolean;
|
|
43
|
+
//# sourceMappingURL=mime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../../../../src/lib/adapter/mime.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AA0BH;;;;;;;GAOG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAKhD;AAED;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE;IACvC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B,GAAG,MAAM,CAOT;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAOvE"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared type contracts for SSR deployment adapters.
|
|
3
|
+
*
|
|
4
|
+
* These types define the interface between platform-specific adapters
|
|
5
|
+
* (Cloudflare Workers, Vercel, Deno Deploy) and the transport-agnostic
|
|
6
|
+
* renderers in `@canonical/react-ssr`. Adapters consume these types;
|
|
7
|
+
* renderers satisfy them.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* The subset of a renderer that adapters need to produce a response.
|
|
11
|
+
*
|
|
12
|
+
* Any renderer (`JSXRenderer`, `SitemapRenderer`, `TextRenderer`) satisfies
|
|
13
|
+
* this interface after calling the appropriate render method.
|
|
14
|
+
*/
|
|
15
|
+
export interface RendererResult {
|
|
16
|
+
/** Render to a web `ReadableStream` (Bun, Deno, Cloudflare Workers, Vercel Edge). */
|
|
17
|
+
renderToReadableStream: (signal?: AbortSignal) => Promise<ReadableStream>;
|
|
18
|
+
/** HTTP status code determined during rendering. */
|
|
19
|
+
statusCode: number;
|
|
20
|
+
/** Resolves when `statusCode` is determined. */
|
|
21
|
+
statusReady: Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A function that creates a renderer for a given request.
|
|
25
|
+
*
|
|
26
|
+
* All adapters use the Web Standard `Request` type. Adapters running on
|
|
27
|
+
* Node.js (e.g. Vercel serverless) convert `IncomingMessage` to `Request`
|
|
28
|
+
* internally before calling the factory.
|
|
29
|
+
*/
|
|
30
|
+
export type RendererFactory = (request: Request) => RendererResult;
|
|
31
|
+
/**
|
|
32
|
+
* A route definition that maps a URL pattern to a renderer factory.
|
|
33
|
+
*
|
|
34
|
+
* Adapters iterate routes in order and use the first match. The pattern
|
|
35
|
+
* uses simple glob matching: `"/*"` matches everything, `"/sitemap.xml"`
|
|
36
|
+
* matches exactly, `"/api/*"` matches any path under `/api/`.
|
|
37
|
+
*/
|
|
38
|
+
export interface RouteDefinition {
|
|
39
|
+
/** URL pattern (e.g. `"/sitemap.xml"`, `"/api/*"`, `"/*"`). */
|
|
40
|
+
pattern: string;
|
|
41
|
+
/** Factory that creates a renderer for matched requests. */
|
|
42
|
+
factory: RendererFactory;
|
|
43
|
+
/**
|
|
44
|
+
* Content-Type header for responses from this route.
|
|
45
|
+
* Defaults to `"text/html; charset=utf-8"` when omitted.
|
|
46
|
+
*/
|
|
47
|
+
contentType?: string;
|
|
48
|
+
/** Cache configuration for responses from this route. */
|
|
49
|
+
cache?: CacheConfig;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Cache-Control header configuration.
|
|
53
|
+
*
|
|
54
|
+
* Adapters translate these values into platform-appropriate caching:
|
|
55
|
+
* - Cloudflare: Cache API (`caches.default.put`) + `Cache-Control` header
|
|
56
|
+
* - Vercel: `Cache-Control` header (CDN respects `s-maxage`)
|
|
57
|
+
* - Deno: `Cache-Control` header only
|
|
58
|
+
*/
|
|
59
|
+
export interface CacheConfig {
|
|
60
|
+
/** Browser cache duration in seconds (`max-age`). */
|
|
61
|
+
maxAge?: number;
|
|
62
|
+
/** CDN/edge cache duration in seconds (`s-maxage`). */
|
|
63
|
+
sMaxAge?: number;
|
|
64
|
+
/** Duration in seconds to serve stale while revalidating (`stale-while-revalidate`). */
|
|
65
|
+
staleWhileRevalidate?: number;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Configuration for serving static assets (CSS, JS, images, fonts).
|
|
69
|
+
*
|
|
70
|
+
* Each entry maps a URL prefix to a source directory. The adapter serves
|
|
71
|
+
* matching requests from the source using the platform's optimal mechanism
|
|
72
|
+
* (R2 on Cloudflare, CDN on Vercel, filesystem on Deno/Bun).
|
|
73
|
+
*/
|
|
74
|
+
export interface StaticAssetConfig {
|
|
75
|
+
/** URL path prefix (e.g. `"/assets"`). */
|
|
76
|
+
urlPrefix: string;
|
|
77
|
+
/**
|
|
78
|
+
* Source directory or key prefix.
|
|
79
|
+
* - Cloudflare: R2 key prefix (e.g. `"assets"`)
|
|
80
|
+
* - Vercel: not used (static assets served by CDN from `.vercel/output/static/`)
|
|
81
|
+
* - Deno/Bun: filesystem path (e.g. `"dist/client/assets"`)
|
|
82
|
+
*/
|
|
83
|
+
directory: string;
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/lib/adapter/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B,qFAAqF;IACrF,sBAAsB,EAAE,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAE1E,oDAAoD;IACpD,UAAU,EAAE,MAAM,CAAC;IAEnB,gDAAgD;IAChD,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAED;;;;;;GAMG;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,cAAc,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC9B,+DAA+D;IAC/D,OAAO,EAAE,MAAM,CAAC;IAEhB,4DAA4D;IAC5D,OAAO,EAAE,eAAe,CAAC;IAEzB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,yDAAyD;IACzD,KAAK,CAAC,EAAE,WAAW,CAAC;CACrB;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,WAAW;IAC1B,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,wFAAwF;IACxF,oBAAoB,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,0CAA0C;IAC1C,SAAS,EAAE,MAAM,CAAC;IAElB;;;;;OAKG;IACH,SAAS,EAAE,MAAM,CAAC;CACnB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,oBAAoB,CAAC;AAC9C,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAC;AAChD,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Collected representation of an HTML element extracted during SAX parsing.
|
|
4
|
+
*
|
|
5
|
+
* Mirrors the subset of DOM element data needed to construct a React element:
|
|
6
|
+
* the tag name, its attributes, and optional text content.
|
|
7
|
+
*/
|
|
8
|
+
interface CollectedElement {
|
|
9
|
+
name: string;
|
|
10
|
+
attribs: Record<string, string>;
|
|
11
|
+
text: string | undefined;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* The three buckets into which `parseHeadElements` dispatches extracted tags.
|
|
15
|
+
*/
|
|
16
|
+
interface ParseResult {
|
|
17
|
+
links: CollectedElement[];
|
|
18
|
+
scripts: CollectedElement[];
|
|
19
|
+
others: CollectedElement[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Extracts `<head>` elements from an HTML string and converts them to React elements.
|
|
23
|
+
*
|
|
24
|
+
* The primary use case is server-side rendering with Vite: the build process produces
|
|
25
|
+
* an HTML shell containing `<script>`, `<link>`, `<meta>`, `<title>`, `<style>`, and
|
|
26
|
+
* `<base>` tags. This class parses that shell via `parseHeadElements` (a SAX handler —
|
|
27
|
+
* no DOM tree is constructed) and exposes the extracted tags as React elements that the
|
|
28
|
+
* server entrypoint component can inject into its rendered output.
|
|
29
|
+
*
|
|
30
|
+
* Parsing happens once in the constructor. The three getter methods return the
|
|
31
|
+
* elements in the order they appeared in the original HTML.
|
|
32
|
+
*/
|
|
33
|
+
export default class Extractor {
|
|
34
|
+
/** Parsed head elements, grouped by category. */
|
|
35
|
+
protected readonly parsed: ParseResult;
|
|
36
|
+
/**
|
|
37
|
+
* Create an Extractor for the given HTML string.
|
|
38
|
+
*
|
|
39
|
+
* @param html - The full HTML string to parse (typically from a Vite build).
|
|
40
|
+
*/
|
|
41
|
+
constructor(html: string);
|
|
42
|
+
/**
|
|
43
|
+
* Convert an HTML attribute name to the corresponding React prop name.
|
|
44
|
+
*
|
|
45
|
+
* Checks `REACT_KEYS_DICTIONARY` for known exceptions (e.g. `class` becomes
|
|
46
|
+
* `className`). Falls back to generic camelCase conversion, which correctly
|
|
47
|
+
* handles `data-*` and `aria-*` attributes.
|
|
48
|
+
*
|
|
49
|
+
* @param key - The HTML attribute name, e.g. `"crossorigin"` or `"data-test-id"`.
|
|
50
|
+
* @returns The React prop name, e.g. `"crossOrigin"` or `"dataTestId"`.
|
|
51
|
+
*/
|
|
52
|
+
protected convertKeyToReactKey(key: string): string;
|
|
53
|
+
/**
|
|
54
|
+
* Convert a collected element into a `React.createElement` call.
|
|
55
|
+
*
|
|
56
|
+
* Attributes are mapped to React prop names via `convertKeyToReactKey`.
|
|
57
|
+
* A stable `key` prop is synthesised from the tag name and the element's
|
|
58
|
+
* position index so that React can reconcile lists of head elements.
|
|
59
|
+
*
|
|
60
|
+
* If the element has text content (e.g. `<title>My App</title>` or
|
|
61
|
+
* `<style>.body { color: red }</style>`), it is passed as the element's
|
|
62
|
+
* `children` argument.
|
|
63
|
+
*
|
|
64
|
+
* @param element - The collected element data from SAX parsing.
|
|
65
|
+
* @param index - The position of this element within its sibling group.
|
|
66
|
+
* @returns A React element matching the original HTML tag.
|
|
67
|
+
*/
|
|
68
|
+
protected convertToReactElement(element: CollectedElement, index: number): React.ReactElement;
|
|
69
|
+
/**
|
|
70
|
+
* Return all `<link>` elements as React elements, in document order.
|
|
71
|
+
*
|
|
72
|
+
* Typically used to inject stylesheet and preload links into the
|
|
73
|
+
* server-rendered `<head>`.
|
|
74
|
+
*/
|
|
75
|
+
getLinkElements(): React.ReactElement[];
|
|
76
|
+
/**
|
|
77
|
+
* Return all `<script>` elements as React elements, in document order.
|
|
78
|
+
*
|
|
79
|
+
* Preserving order is important: Vite dev mode emits module scripts
|
|
80
|
+
* that depend on being evaluated in sequence.
|
|
81
|
+
*/
|
|
82
|
+
getScriptElements(): React.ReactElement[];
|
|
83
|
+
/**
|
|
84
|
+
* Return all non-script, non-link head elements as React elements, in document order.
|
|
85
|
+
*
|
|
86
|
+
* This covers `<title>`, `<style>`, `<meta>`, and `<base>`. Elements are returned
|
|
87
|
+
* in the order they appeared in the HTML, preserving inter-type ordering (a `<meta>`
|
|
88
|
+
* between two `<style>` tags stays between them).
|
|
89
|
+
*/
|
|
90
|
+
getOtherHeadElements(): React.ReactElement[];
|
|
91
|
+
}
|
|
92
|
+
export {};
|
|
93
|
+
//# sourceMappingURL=Extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Extractor.d.ts","sourceRoot":"","sources":["../../../../src/lib/renderer/Extractor.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAoB1B;;;;;GAKG;AACH,UAAU,gBAAgB;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED;;GAEG;AACH,UAAU,WAAW;IACnB,KAAK,EAAE,gBAAgB,EAAE,CAAC;IAC1B,OAAO,EAAE,gBAAgB,EAAE,CAAC;IAC5B,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B;AAuED;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS;IAC5B,iDAAiD;IACjD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;IAEvC;;;;OAIG;gBACS,IAAI,EAAE,MAAM;IAIxB;;;;;;;;;OASG;IACH,SAAS,CAAC,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IAInD;;;;;;;;;;;;;;OAcG;IACH,SAAS,CAAC,qBAAqB,CAC7B,OAAO,EAAE,gBAAgB,EACzB,KAAK,EAAE,MAAM,GACZ,KAAK,CAAC,YAAY;IAWrB;;;;;OAKG;IACI,eAAe,IAAI,KAAK,CAAC,YAAY,EAAE;IAI9C;;;;;OAKG;IACI,iBAAiB,IAAI,KAAK,CAAC,YAAY,EAAE;IAMhD;;;;;;OAMG;IACI,oBAAoB,IAAI,KAAK,CAAC,YAAY,EAAE;CAGpD"}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { type RenderToPipeableStreamOptions } from "react-dom/server";
|
|
2
|
+
import Extractor from "./Extractor.js";
|
|
3
|
+
import type { PipeableStreamResult, RendererOptions, ServerEntrypoint, ServerEntrypointProps } from "./types.js";
|
|
4
|
+
/**
|
|
5
|
+
* Server-side renderer for a React component.
|
|
6
|
+
*
|
|
7
|
+
* Accepts a React `ServerEntrypoint` component, optional initial data for
|
|
8
|
+
* hydration, and an optional HTML shell string (from a Vite build) whose
|
|
9
|
+
* `<head>` tags are extracted and injected into the rendered output.
|
|
10
|
+
*
|
|
11
|
+
* Three rendering strategies are available:
|
|
12
|
+
*
|
|
13
|
+
* - **ReadableStream** (`renderToReadableStream`) — returns a web `ReadableStream`.
|
|
14
|
+
* Works natively with Bun, Deno, Cloudflare Workers, and any runtime that
|
|
15
|
+
* supports the Web Streams API. Supports Suspense and progressive rendering.
|
|
16
|
+
*
|
|
17
|
+
* - **PipeableStream** (`renderToPipeableStream`) — returns a Node.js pipeable stream.
|
|
18
|
+
* Works with Express, Fastify, and Node's built-in `http` module. Supports Suspense
|
|
19
|
+
* and progressive rendering.
|
|
20
|
+
*
|
|
21
|
+
* - **String** (`renderToString`) — returns the full HTML as a string. All Suspense
|
|
22
|
+
* boundaries resolve synchronously. The output is cacheable and works with Vite
|
|
23
|
+
* HMR in dev mode.
|
|
24
|
+
*
|
|
25
|
+
* All strategies inject `<script>` and `<link>` tags from the HTML shell via
|
|
26
|
+
* React's `bootstrapScripts` / `bootstrapModules` mechanism, and embed
|
|
27
|
+
* `initialData` as a global `window.__INITIAL_DATA__` variable for client
|
|
28
|
+
* hydration.
|
|
29
|
+
*
|
|
30
|
+
* The renderer is transport-agnostic — it never writes to a response object.
|
|
31
|
+
* HTTP status codes and metadata are exposed via `statusCode` and `statusReady`
|
|
32
|
+
* for the consumer to use when constructing the response.
|
|
33
|
+
*
|
|
34
|
+
* @typeParam TComponent - The server entrypoint component type.
|
|
35
|
+
* @typeParam InitialData - Shape of the data embedded for client hydration.
|
|
36
|
+
*/
|
|
37
|
+
export default class JSXRenderer<TComponent extends ServerEntrypoint<InitialData>, InitialData extends Record<string, unknown>> {
|
|
38
|
+
protected readonly Component: TComponent;
|
|
39
|
+
protected readonly initialData: InitialData;
|
|
40
|
+
protected readonly options: RendererOptions;
|
|
41
|
+
protected extractor: Extractor | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* HTTP status code determined during rendering.
|
|
44
|
+
*
|
|
45
|
+
* Starts at 200 and is set to 500 if a shell error occurs during streaming.
|
|
46
|
+
* For `renderToString`, it is always 200 (errors throw instead).
|
|
47
|
+
*
|
|
48
|
+
* Read this after the render method returns (for `renderToReadableStream` and
|
|
49
|
+
* `renderToString`) or after awaiting `statusReady` (for `renderToPipeableStream`).
|
|
50
|
+
*/
|
|
51
|
+
statusCode: number;
|
|
52
|
+
/**
|
|
53
|
+
* Resolves when `statusCode` is determined.
|
|
54
|
+
*
|
|
55
|
+
* For `renderToReadableStream` and `renderToString`, this is already resolved
|
|
56
|
+
* by the time the method returns. For `renderToPipeableStream`, it resolves
|
|
57
|
+
* asynchronously when the shell is ready or errors.
|
|
58
|
+
*/
|
|
59
|
+
statusReady: Promise<void>;
|
|
60
|
+
/**
|
|
61
|
+
* Create a renderer bound to a specific component and initial data.
|
|
62
|
+
*
|
|
63
|
+
* If `options.htmlString` is provided, the HTML is parsed once to extract
|
|
64
|
+
* `<head>` elements. These elements are then available as React elements
|
|
65
|
+
* via `getComponentProps()` for injection during rendering.
|
|
66
|
+
*
|
|
67
|
+
* @param Component - The React server entrypoint component.
|
|
68
|
+
* @param initialData - Data to embed in `window.__INITIAL_DATA__` for client hydration.
|
|
69
|
+
* @param options - Renderer configuration: locale, HTML shell, and stream options.
|
|
70
|
+
*/
|
|
71
|
+
constructor(Component: TComponent, initialData?: InitialData, options?: RendererOptions);
|
|
72
|
+
/**
|
|
73
|
+
* Return the locale for the rendered page.
|
|
74
|
+
*
|
|
75
|
+
* Defaults to `"en"` when no `defaultLocale` was provided in options.
|
|
76
|
+
* The locale is passed as the `lang` prop to the server entrypoint component,
|
|
77
|
+
* which typically sets it as the `<html lang>` attribute.
|
|
78
|
+
*/
|
|
79
|
+
getLocale(): string;
|
|
80
|
+
/**
|
|
81
|
+
* Assemble the props passed to the server entrypoint component.
|
|
82
|
+
*
|
|
83
|
+
* Combines the locale, initial data, and (when an HTML shell was provided)
|
|
84
|
+
* the extracted script, link, and other head elements into a single props
|
|
85
|
+
* object conforming to `ServerEntrypointProps`.
|
|
86
|
+
*/
|
|
87
|
+
protected getComponentProps(): ServerEntrypointProps<InitialData>;
|
|
88
|
+
/**
|
|
89
|
+
* Extract `src` URLs from script elements that match a given loading strategy.
|
|
90
|
+
*
|
|
91
|
+
* Filters the provided React `<script>` elements by their `type` attribute:
|
|
92
|
+
* `"module"` selects ES module scripts, `"classic"` selects everything else.
|
|
93
|
+
* Returns only the `src` values, discarding inline scripts that have no `src`.
|
|
94
|
+
*
|
|
95
|
+
* @param scripts - React elements representing `<script>` tags.
|
|
96
|
+
* @param type - `"module"` for ES modules, `"classic"` for traditional scripts.
|
|
97
|
+
* @returns An array of script source URLs.
|
|
98
|
+
*/
|
|
99
|
+
protected getScriptSourcesByType(scripts: React.ReactElement[], type: "module" | "classic"): string[];
|
|
100
|
+
/**
|
|
101
|
+
* Merge renderer-managed options into the user-provided stream options.
|
|
102
|
+
*
|
|
103
|
+
* Populates three React streaming options unless the caller already supplied them:
|
|
104
|
+
*
|
|
105
|
+
* - `bootstrapScriptContent` — a `<script>` body that assigns `initialData` to
|
|
106
|
+
* `window.__INITIAL_DATA__`. The JSON is escaped to prevent `</script>` injection.
|
|
107
|
+
* - `bootstrapScripts` — `src` URLs for classic (non-module) scripts extracted from
|
|
108
|
+
* the HTML shell. React strips `<script>` tags during streaming, so these must
|
|
109
|
+
* be re-injected through this mechanism.
|
|
110
|
+
* - `bootstrapModules` — same as above, for ES module scripts.
|
|
111
|
+
*
|
|
112
|
+
* @param props - The assembled component props (used to read `initialData` and `scriptElements`).
|
|
113
|
+
* @returns A merged options object safe to pass to either streaming API.
|
|
114
|
+
*/
|
|
115
|
+
protected enrichRendererOptions(props: ServerEntrypointProps<InitialData>): RenderToPipeableStreamOptions;
|
|
116
|
+
/**
|
|
117
|
+
* Render the component to a web `ReadableStream`.
|
|
118
|
+
*
|
|
119
|
+
* Uses `react-dom/server.renderToReadableStream` for environments that support
|
|
120
|
+
* the Web Streams API (Bun, Deno, Cloudflare Workers, browsers). Supports
|
|
121
|
+
* Suspense and progressive rendering.
|
|
122
|
+
*
|
|
123
|
+
* On shell error, `statusCode` is set to 500 and a fallback HTML stream is
|
|
124
|
+
* returned. On success, `statusCode` is 200.
|
|
125
|
+
*
|
|
126
|
+
* @note This method is impure — it mutates `statusCode` and `statusReady`.
|
|
127
|
+
*
|
|
128
|
+
* @param signal - Optional `AbortSignal` for request cancellation.
|
|
129
|
+
* @returns A `ReadableStream` of the rendered HTML.
|
|
130
|
+
*/
|
|
131
|
+
renderToReadableStream: (signal?: AbortSignal) => Promise<ReadableStream>;
|
|
132
|
+
/**
|
|
133
|
+
* Render the component to a Node.js pipeable stream.
|
|
134
|
+
*
|
|
135
|
+
* Uses `react-dom/server.renderToPipeableStream` for Node.js environments
|
|
136
|
+
* (Express, Fastify, plain `http.createServer`). Supports Suspense and
|
|
137
|
+
* progressive rendering.
|
|
138
|
+
*
|
|
139
|
+
* Returns `{ pipe, abort }` synchronously. The `statusCode` is set
|
|
140
|
+
* asynchronously when the shell is ready or errors — await `statusReady`
|
|
141
|
+
* before reading it.
|
|
142
|
+
*
|
|
143
|
+
* @note This method is impure — it mutates `statusCode` and `statusReady`.
|
|
144
|
+
*
|
|
145
|
+
* @returns The pipe/abort handles for the rendered stream.
|
|
146
|
+
*/
|
|
147
|
+
renderToPipeableStream: () => PipeableStreamResult;
|
|
148
|
+
/**
|
|
149
|
+
* Render the component to a complete HTML string.
|
|
150
|
+
*
|
|
151
|
+
* Uses `react-dom/server.renderToString` to produce the full HTML
|
|
152
|
+
* synchronously. All Suspense boundaries resolve before the method returns.
|
|
153
|
+
* The output is cacheable and compatible with Vite's HMR in dev mode.
|
|
154
|
+
*
|
|
155
|
+
* Sets `statusCode` to 200 on success. On error, throws (consumer catches).
|
|
156
|
+
*
|
|
157
|
+
* @note This method is impure — it mutates `statusCode`.
|
|
158
|
+
*
|
|
159
|
+
* @returns The complete HTML string.
|
|
160
|
+
*/
|
|
161
|
+
renderToString: () => string;
|
|
162
|
+
}
|
|
163
|
+
//# sourceMappingURL=JSXRenderer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JSXRenderer.d.ts","sourceRoot":"","sources":["../../../../src/lib/renderer/JSXRenderer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,KAAK,6BAA6B,EAInC,MAAM,kBAAkB,CAAC;AAE1B,OAAO,SAAS,MAAM,gBAAgB,CAAC;AACvC,OAAO,KAAK,EACV,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AACH,MAAM,CAAC,OAAO,OAAO,WAAW,CAC9B,UAAU,SAAS,gBAAgB,CAAC,WAAW,CAAC,EAChD,WAAW,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAoCzC,SAAS,CAAC,QAAQ,CAAC,SAAS,EAAE,UAAU;IACxC,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW;IAC3C,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAe;IApC7C,SAAS,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,CAAC;IAE3C;;;;;;;;OAQG;IACI,UAAU,SAAO;IAExB;;;;;;OAMG;IACI,WAAW,EAAE,OAAO,CAAC,IAAI,CAAC,CAAqB;IAEtD;;;;;;;;;;OAUG;gBAEkB,SAAS,EAAE,UAAU,EACrB,WAAW,GAAE,WAA+B,EAC5C,OAAO,GAAE,eAAoB;IAOlD;;;;;;OAMG;IACI,SAAS,IAAI,MAAM;IAI1B;;;;;;OAMG;IACH,SAAS,CAAC,iBAAiB,IAAI,qBAAqB,CAAC,WAAW,CAAC;IAUjE;;;;;;;;;;OAUG;IACH,SAAS,CAAC,sBAAsB,CAC9B,OAAO,EAAE,KAAK,CAAC,YAAY,EAAE,EAC7B,IAAI,EAAE,QAAQ,GAAG,SAAS,GACzB,MAAM,EAAE;IAmBX;;;;;;;;;;;;;;OAcG;IACH,SAAS,CAAC,qBAAqB,CAC7B,KAAK,EAAE,qBAAqB,CAAC,WAAW,CAAC,GACxC,6BAA6B;IA8BhC;;;;;;;;;;;;;;OAcG;IACH,sBAAsB,GACpB,SAAS,WAAW,KACnB,OAAO,CAAC,cAAc,CAAC,CAuCxB;IAEF;;;;;;;;;;;;;;OAcG;IACH,sBAAsB,QAAO,oBAAoB,CA0C/C;IAEF;;;;;;;;;;;;OAYG;IACH,cAAc,QAAO,MAAM,CAOzB;CACH"}
|