@nestjs-ssr/react 0.2.1 → 0.2.2

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.
@@ -1,6 +1,6 @@
1
1
  import React from 'react';
2
- import { renderToString } from 'react-dom/server';
3
- import { PageContextProvider } from '../react/hooks/use-page-context';
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
+ }
@@ -1,14 +1,17 @@
1
1
  <!DOCTYPE html>
2
2
  <html lang="en">
3
- <head>
4
- <meta charset="UTF-8" />
5
- <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
- <title>NestJS React SSR</title>
7
- <!--styles-->
8
- </head>
9
- <body>
10
- <div id="root"><!--app-html--></div>
11
- <!--initial-state-->
12
- <!--client-scripts-->
13
- </body>
14
- </html>
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>