@zubyjs/react 1.0.31 → 1.0.33
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/index.js +1 -2
- package/package.json +1 -1
- package/render.d.ts +11 -2
- package/render.js +17 -7
- package/templates/error.d.ts +1 -1
- package/templates/error.js +1 -1
package/index.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import render from './render.js';
|
|
2
1
|
import { fileURLToPath } from 'url';
|
|
3
2
|
import { dirname, resolve } from 'path';
|
|
4
3
|
import { normalizePath } from 'zuby/utils/pathUtils.js';
|
|
@@ -12,6 +11,6 @@ export default () => ({
|
|
|
12
11
|
layoutTemplateFile: normalizePath(resolve(__dirname, 'templates', 'layout.js')),
|
|
13
12
|
innerLayoutTemplateFile: normalizePath(resolve(__dirname, 'templates', 'innerLayout.js')),
|
|
14
13
|
errorTemplateFile: normalizePath(resolve(__dirname, 'templates', 'error.js')),
|
|
15
|
-
render,
|
|
14
|
+
renderFile: normalizePath(resolve(__dirname, 'render.js')),
|
|
16
15
|
getPlugins: () => react(),
|
|
17
16
|
});
|
package/package.json
CHANGED
package/render.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RenderToString, RenderToStream } from 'zuby/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a ReadableStream to a string.
|
|
4
|
+
* @param {NodeJS.ReadableStream} stream
|
|
5
|
+
*/
|
|
6
|
+
export declare const streamToString: (stream: NodeJS.ReadableStream) => Promise<string>;
|
|
7
|
+
/**
|
|
8
|
+
* @param {ReactElement} vnode The root JSX element to render (eg: `<App />`)
|
|
9
|
+
*/
|
|
10
|
+
export declare const renderToStream: RenderToStream;
|
|
2
11
|
/**
|
|
3
12
|
* @param {ReactElement} vnode The root JSX element to render (eg: `<App />`)
|
|
4
13
|
*/
|
|
5
|
-
export
|
|
14
|
+
export declare const renderToString: RenderToString;
|
package/render.js
CHANGED
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { renderToStaticNodeStream } from 'react-dom/server';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* Converts a ReadableStream to a string.
|
|
4
|
+
* @param {NodeJS.ReadableStream} stream
|
|
4
5
|
*/
|
|
5
|
-
export
|
|
6
|
-
const stream = renderToStaticNodeStream(vnode);
|
|
7
|
-
return await streamToString(stream);
|
|
8
|
-
}
|
|
9
|
-
function streamToString(stream) {
|
|
6
|
+
export const streamToString = (stream) => {
|
|
10
7
|
const chunks = [];
|
|
11
8
|
return new Promise((resolve, reject) => {
|
|
12
9
|
stream.on('data', (chunk) => chunks.push(Buffer.from(chunk)));
|
|
13
10
|
stream.on('error', (e) => reject(e));
|
|
14
11
|
stream.on('end', () => resolve(Buffer.concat(chunks).toString('utf8')));
|
|
15
12
|
});
|
|
16
|
-
}
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* @param {ReactElement} vnode The root JSX element to render (eg: `<App />`)
|
|
16
|
+
*/
|
|
17
|
+
export const renderToStream = async (vnode) => {
|
|
18
|
+
return renderToStaticNodeStream(vnode);
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @param {ReactElement} vnode The root JSX element to render (eg: `<App />`)
|
|
22
|
+
*/
|
|
23
|
+
export const renderToString = async (vnode) => {
|
|
24
|
+
const stream = renderToStaticNodeStream(vnode);
|
|
25
|
+
return await streamToString(stream);
|
|
26
|
+
};
|
package/templates/error.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { PropsWithChildren } from 'react';
|
|
2
|
-
export default function
|
|
2
|
+
export default function Error({ children }: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
package/templates/error.js
CHANGED