@nestjs-ssr/react 0.3.0 → 0.3.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.
package/dist/index.js CHANGED
@@ -316,7 +316,7 @@ var StringRenderer = class _StringRenderer {
316
316
  }
317
317
  }
318
318
  const { data: pageData, __context: pageContext } = data;
319
- const html = await renderModule.renderComponent(viewComponent, data);
319
+ const html = await renderModule.renderSegment(viewComponent, data);
320
320
  const componentName = viewComponent.displayName || viewComponent.name || "Component";
321
321
  if (context.isDevelopment) {
322
322
  const duration = Date.now() - startTime;
@@ -1120,15 +1120,20 @@ exports.RenderInterceptor = class RenderInterceptor {
1120
1120
  } else if (renderOptions?.layout === false) {
1121
1121
  return layouts;
1122
1122
  }
1123
- if (controllerLayoutMeta) {
1124
- const mergedProps = {
1125
- ...controllerLayoutMeta.options?.props || {},
1126
- ...dynamicLayoutProps || {}
1127
- };
1128
- layouts.push({
1129
- layout: controllerLayoutMeta.layout,
1130
- props: mergedProps
1131
- });
1123
+ if (controllerLayoutMeta?.layout) {
1124
+ const rootLayoutName = rootLayout?.displayName || rootLayout?.name;
1125
+ const controllerLayoutName = controllerLayoutMeta.layout.displayName || controllerLayoutMeta.layout.name;
1126
+ const isDuplicateOfRoot = rootLayout && rootLayoutName && controllerLayoutName === rootLayoutName;
1127
+ if (!isDuplicateOfRoot) {
1128
+ const mergedProps = {
1129
+ ...controllerLayoutMeta.options?.props || {},
1130
+ ...dynamicLayoutProps || {}
1131
+ };
1132
+ layouts.push({
1133
+ layout: controllerLayoutMeta.layout,
1134
+ props: mergedProps
1135
+ });
1136
+ }
1132
1137
  }
1133
1138
  if (renderOptions?.layout) {
1134
1139
  const mergedProps = {
package/dist/index.mjs CHANGED
@@ -309,7 +309,7 @@ var StringRenderer = class _StringRenderer {
309
309
  }
310
310
  }
311
311
  const { data: pageData, __context: pageContext } = data;
312
- const html = await renderModule.renderComponent(viewComponent, data);
312
+ const html = await renderModule.renderSegment(viewComponent, data);
313
313
  const componentName = viewComponent.displayName || viewComponent.name || "Component";
314
314
  if (context.isDevelopment) {
315
315
  const duration = Date.now() - startTime;
@@ -1113,15 +1113,20 @@ var RenderInterceptor = class {
1113
1113
  } else if (renderOptions?.layout === false) {
1114
1114
  return layouts;
1115
1115
  }
1116
- if (controllerLayoutMeta) {
1117
- const mergedProps = {
1118
- ...controllerLayoutMeta.options?.props || {},
1119
- ...dynamicLayoutProps || {}
1120
- };
1121
- layouts.push({
1122
- layout: controllerLayoutMeta.layout,
1123
- props: mergedProps
1124
- });
1116
+ if (controllerLayoutMeta?.layout) {
1117
+ const rootLayoutName = rootLayout?.displayName || rootLayout?.name;
1118
+ const controllerLayoutName = controllerLayoutMeta.layout.displayName || controllerLayoutMeta.layout.name;
1119
+ const isDuplicateOfRoot = rootLayout && rootLayoutName && controllerLayoutName === rootLayoutName;
1120
+ if (!isDuplicateOfRoot) {
1121
+ const mergedProps = {
1122
+ ...controllerLayoutMeta.options?.props || {},
1123
+ ...dynamicLayoutProps || {}
1124
+ };
1125
+ layouts.push({
1126
+ layout: controllerLayoutMeta.layout,
1127
+ props: mergedProps
1128
+ });
1129
+ }
1125
1130
  }
1126
1131
  if (renderOptions?.layout) {
1127
1132
  const mergedProps = {
@@ -316,7 +316,7 @@ var StringRenderer = class _StringRenderer {
316
316
  }
317
317
  }
318
318
  const { data: pageData, __context: pageContext } = data;
319
- const html = await renderModule.renderComponent(viewComponent, data);
319
+ const html = await renderModule.renderSegment(viewComponent, data);
320
320
  const componentName = viewComponent.displayName || viewComponent.name || "Component";
321
321
  if (context.isDevelopment) {
322
322
  const duration = Date.now() - startTime;
@@ -1102,15 +1102,20 @@ exports.RenderInterceptor = class RenderInterceptor {
1102
1102
  } else if (renderOptions?.layout === false) {
1103
1103
  return layouts;
1104
1104
  }
1105
- if (controllerLayoutMeta) {
1106
- const mergedProps = {
1107
- ...controllerLayoutMeta.options?.props || {},
1108
- ...dynamicLayoutProps || {}
1109
- };
1110
- layouts.push({
1111
- layout: controllerLayoutMeta.layout,
1112
- props: mergedProps
1113
- });
1105
+ if (controllerLayoutMeta?.layout) {
1106
+ const rootLayoutName = rootLayout?.displayName || rootLayout?.name;
1107
+ const controllerLayoutName = controllerLayoutMeta.layout.displayName || controllerLayoutMeta.layout.name;
1108
+ const isDuplicateOfRoot = rootLayout && rootLayoutName && controllerLayoutName === rootLayoutName;
1109
+ if (!isDuplicateOfRoot) {
1110
+ const mergedProps = {
1111
+ ...controllerLayoutMeta.options?.props || {},
1112
+ ...dynamicLayoutProps || {}
1113
+ };
1114
+ layouts.push({
1115
+ layout: controllerLayoutMeta.layout,
1116
+ props: mergedProps
1117
+ });
1118
+ }
1114
1119
  }
1115
1120
  if (renderOptions?.layout) {
1116
1121
  const mergedProps = {
@@ -309,7 +309,7 @@ var StringRenderer = class _StringRenderer {
309
309
  }
310
310
  }
311
311
  const { data: pageData, __context: pageContext } = data;
312
- const html = await renderModule.renderComponent(viewComponent, data);
312
+ const html = await renderModule.renderSegment(viewComponent, data);
313
313
  const componentName = viewComponent.displayName || viewComponent.name || "Component";
314
314
  if (context.isDevelopment) {
315
315
  const duration = Date.now() - startTime;
@@ -1095,15 +1095,20 @@ var RenderInterceptor = class {
1095
1095
  } else if (renderOptions?.layout === false) {
1096
1096
  return layouts;
1097
1097
  }
1098
- if (controllerLayoutMeta) {
1099
- const mergedProps = {
1100
- ...controllerLayoutMeta.options?.props || {},
1101
- ...dynamicLayoutProps || {}
1102
- };
1103
- layouts.push({
1104
- layout: controllerLayoutMeta.layout,
1105
- props: mergedProps
1106
- });
1098
+ if (controllerLayoutMeta?.layout) {
1099
+ const rootLayoutName = rootLayout?.displayName || rootLayout?.name;
1100
+ const controllerLayoutName = controllerLayoutMeta.layout.displayName || controllerLayoutMeta.layout.name;
1101
+ const isDuplicateOfRoot = rootLayout && rootLayoutName && controllerLayoutName === rootLayoutName;
1102
+ if (!isDuplicateOfRoot) {
1103
+ const mergedProps = {
1104
+ ...controllerLayoutMeta.options?.props || {},
1105
+ ...dynamicLayoutProps || {}
1106
+ };
1107
+ layouts.push({
1108
+ layout: controllerLayoutMeta.layout,
1109
+ props: mergedProps
1110
+ });
1111
+ }
1107
1112
  }
1108
1113
  if (renderOptions?.layout) {
1109
1114
  const mergedProps = {
@@ -61,6 +61,26 @@ export function renderComponent(
61
61
  return renderToString(wrappedElement);
62
62
  }
63
63
 
64
+ /**
65
+ * Render just the page component for segment navigation.
66
+ * No layout wrappers - the layout already exists on the client.
67
+ */
68
+ export function renderSegment(
69
+ ViewComponent: React.ComponentType<any>,
70
+ data: any,
71
+ ) {
72
+ const { data: pageData, __context: context } = data;
73
+
74
+ // Render just the page component, no layout wrappers
75
+ const element = (
76
+ <PageContextProvider context={context}>
77
+ <ViewComponent {...pageData} />
78
+ </PageContextProvider>
79
+ );
80
+
81
+ return renderToString(element);
82
+ }
83
+
64
84
  /**
65
85
  * Streaming SSR (mode: 'stream' - default)
66
86
  * Modern approach with progressive rendering and Suspense support
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs-ssr/react",
3
- "version": "0.3.0",
3
+ "version": "0.3.2",
4
4
  "description": "React SSR for NestJS that respects Clean Architecture. Proper DI, SOLID principles, clear separation of concerns.",
5
5
  "keywords": [
6
6
  "nestjs",
@@ -61,6 +61,26 @@ export function renderComponent(
61
61
  return renderToString(wrappedElement);
62
62
  }
63
63
 
64
+ /**
65
+ * Render just the page component for segment navigation.
66
+ * No layout wrappers - the layout already exists on the client.
67
+ */
68
+ export function renderSegment(
69
+ ViewComponent: React.ComponentType<any>,
70
+ data: any,
71
+ ) {
72
+ const { data: pageData, __context: context } = data;
73
+
74
+ // Render just the page component, no layout wrappers
75
+ const element = (
76
+ <PageContextProvider context={context}>
77
+ <ViewComponent {...pageData} />
78
+ </PageContextProvider>
79
+ );
80
+
81
+ return renderToString(element);
82
+ }
83
+
64
84
  /**
65
85
  * Streaming SSR (mode: 'stream' - default)
66
86
  * Modern approach with progressive rendering and Suspense support