@nestjs-ssr/react 0.2.1 → 0.2.3
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/README.md +1 -1
- package/dist/cli/init.js +278 -107
- package/dist/cli/init.mjs +280 -109
- package/dist/client.d.mts +319 -0
- package/dist/client.d.ts +319 -0
- package/dist/client.js +207 -0
- package/dist/client.mjs +200 -0
- package/dist/{index-C5Knql-9.d.mts → index-CaGD266H.d.ts} +2 -104
- package/dist/{index-C5Knql-9.d.ts → index-Dq1yt0sX.d.mts} +2 -104
- package/dist/index.d.mts +9 -321
- package/dist/index.d.ts +9 -321
- package/dist/index.js +144 -91
- package/dist/index.mjs +115 -63
- package/dist/render/index.d.mts +2 -1
- package/dist/render/index.d.ts +2 -1
- package/dist/render/index.js +134 -81
- package/dist/render/index.mjs +115 -63
- package/dist/render-response.interface-Dc-Kwb09.d.mts +104 -0
- package/dist/render-response.interface-Dc-Kwb09.d.ts +104 -0
- package/dist/templates/entry-client.tsx +6 -3
- package/dist/templates/entry-server.tsx +33 -2
- package/dist/templates/index.html +15 -12
- package/package.json +27 -15
- package/src/templates/entry-client.tsx +6 -3
- package/src/templates/entry-server.tsx +33 -2
- package/src/templates/index.html +15 -12
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { renderToString } from 'react-dom/server';
|
|
3
|
-
import { PageContextProvider } from '
|
|
2
|
+
import { renderToString, renderToPipeableStream } from 'react-dom/server';
|
|
3
|
+
import { PageContextProvider } from '@nestjs-ssr/react';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Compose a component with its layouts from the interceptor
|
|
@@ -23,6 +23,10 @@ function composeWithLayouts(
|
|
|
23
23
|
return result;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* String-based SSR (mode: 'string')
|
|
28
|
+
* Simple, synchronous rendering
|
|
29
|
+
*/
|
|
26
30
|
export function renderComponent(
|
|
27
31
|
ViewComponent: React.ComponentType<any>,
|
|
28
32
|
data: any,
|
|
@@ -39,3 +43,30 @@ export function renderComponent(
|
|
|
39
43
|
|
|
40
44
|
return renderToString(wrappedElement);
|
|
41
45
|
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Streaming SSR (mode: 'stream' - default)
|
|
49
|
+
* Modern approach with progressive rendering and Suspense support
|
|
50
|
+
*/
|
|
51
|
+
export function renderComponentStream(
|
|
52
|
+
ViewComponent: React.ComponentType<any>,
|
|
53
|
+
data: any,
|
|
54
|
+
callbacks?: {
|
|
55
|
+
onShellReady?: () => void;
|
|
56
|
+
onShellError?: (error: unknown) => void;
|
|
57
|
+
onError?: (error: unknown) => void;
|
|
58
|
+
onAllReady?: () => void;
|
|
59
|
+
},
|
|
60
|
+
) {
|
|
61
|
+
const { data: pageData, __context: context, __layouts: layouts } = data;
|
|
62
|
+
const composedElement = composeWithLayouts(ViewComponent, pageData, layouts);
|
|
63
|
+
|
|
64
|
+
// Wrap with PageContextProvider to make context available via hooks
|
|
65
|
+
const wrappedElement = (
|
|
66
|
+
<PageContextProvider context={context}>
|
|
67
|
+
{composedElement}
|
|
68
|
+
</PageContextProvider>
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return renderToPipeableStream(wrappedElement, callbacks);
|
|
72
|
+
}
|
package/src/templates/index.html
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html lang="en">
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
+
<!--head-meta-->
|
|
8
|
+
<!--styles-->
|
|
9
|
+
</head>
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<div id="root"><!--app-html--></div>
|
|
13
|
+
<!--initial-state-->
|
|
14
|
+
<!--client-scripts-->
|
|
15
|
+
</body>
|
|
16
|
+
|
|
17
|
+
</html>
|