@nestjs-ssr/react 0.3.4 → 0.3.5
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/client.d.mts +2 -2
- package/dist/client.d.ts +2 -2
- package/dist/client.js +50 -8
- package/dist/client.mjs +50 -8
- package/dist/{index-DdE--mA2.d.mts → index-CiYcz-1T.d.mts} +89 -4
- package/dist/{index-BzOLOiIZ.d.ts → index-Dq2qZSge.d.ts} +89 -4
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +54 -4
- package/dist/index.mjs +55 -5
- package/dist/render/index.d.mts +3 -3
- package/dist/render/index.d.ts +3 -3
- package/dist/render/index.js +35 -4
- package/dist/render/index.mjs +36 -5
- package/dist/{render-response.interface-CxbuKGnV.d.mts → render-response.interface-ClWJXKL4.d.mts} +19 -10
- package/dist/{render-response.interface-CxbuKGnV.d.ts → render-response.interface-ClWJXKL4.d.ts} +19 -10
- package/dist/templates/entry-client.tsx +23 -4
- package/dist/templates/entry-server.tsx +25 -8
- package/dist/{use-page-context-CGT9woWe.d.mts → use-page-context-CVC9DHcL.d.mts} +2 -1
- package/dist/{use-page-context-05ODF4zW.d.ts → use-page-context-DChgHhL9.d.ts} +2 -1
- package/package.json +1 -1
- package/src/templates/entry-client.tsx +23 -4
- package/src/templates/entry-server.tsx +25 -8
|
@@ -25,6 +25,13 @@ export function getRootLayout(): React.ComponentType<any> | null {
|
|
|
25
25
|
* Layouts are passed from the RenderInterceptor based on decorators.
|
|
26
26
|
* Each layout is wrapped with data-layout and data-outlet attributes
|
|
27
27
|
* for client-side navigation segment swapping.
|
|
28
|
+
*
|
|
29
|
+
* The layouts array is ordered [RootLayout, ControllerLayout, MethodLayout] (outer to inner).
|
|
30
|
+
* We iterate in REVERSE order because wrapping happens inside-out:
|
|
31
|
+
* - Start with Page
|
|
32
|
+
* - Wrap with innermost layout first (MethodLayout)
|
|
33
|
+
* - Then wrap with ControllerLayout
|
|
34
|
+
* - Finally wrap with RootLayout (outermost)
|
|
28
35
|
*/
|
|
29
36
|
function composeWithLayouts(
|
|
30
37
|
ViewComponent: React.ComponentType<any>,
|
|
@@ -35,11 +42,12 @@ function composeWithLayouts(
|
|
|
35
42
|
// Start with the page component
|
|
36
43
|
let result = <ViewComponent {...props} />;
|
|
37
44
|
|
|
38
|
-
// Wrap with each layout in
|
|
39
|
-
//
|
|
45
|
+
// Wrap with each layout in REVERSE order (innermost to outermost)
|
|
46
|
+
// This produces the correct nesting: RootLayout > ControllerLayout > Page
|
|
40
47
|
// Pass context to layouts so they can access path, params, etc. for navigation
|
|
41
48
|
// Each layout gets data-layout attribute and children are wrapped in data-outlet
|
|
42
|
-
for (
|
|
49
|
+
for (let i = layouts.length - 1; i >= 0; i--) {
|
|
50
|
+
const { layout: Layout, props: layoutProps } = layouts[i];
|
|
43
51
|
const layoutName = Layout.displayName || Layout.name || 'Layout';
|
|
44
52
|
result = (
|
|
45
53
|
<div data-layout={layoutName}>
|
|
@@ -80,19 +88,28 @@ export function renderComponent(
|
|
|
80
88
|
}
|
|
81
89
|
|
|
82
90
|
/**
|
|
83
|
-
* Render
|
|
84
|
-
*
|
|
91
|
+
* Render a segment for client-side navigation.
|
|
92
|
+
* Includes any layouts below the swap target (e.g., nested layouts).
|
|
93
|
+
* The swap target's outlet will receive this rendered content.
|
|
85
94
|
*/
|
|
86
95
|
export function renderSegment(
|
|
87
96
|
ViewComponent: React.ComponentType<any>,
|
|
88
97
|
data: any,
|
|
89
98
|
) {
|
|
90
|
-
const { data: pageData, __context: context } = data;
|
|
99
|
+
const { data: pageData, __context: context, __layouts: layouts } = data;
|
|
100
|
+
|
|
101
|
+
// Compose with filtered layouts (layouts below the swap target)
|
|
102
|
+
const composedElement = composeWithLayouts(
|
|
103
|
+
ViewComponent,
|
|
104
|
+
pageData,
|
|
105
|
+
layouts,
|
|
106
|
+
context,
|
|
107
|
+
);
|
|
91
108
|
|
|
92
|
-
//
|
|
109
|
+
// Wrap with PageContextProvider to make context available via hooks
|
|
93
110
|
const element = (
|
|
94
111
|
<PageContextProvider context={context}>
|
|
95
|
-
|
|
112
|
+
{composedElement}
|
|
96
113
|
</PageContextProvider>
|
|
97
114
|
);
|
|
98
115
|
|