@nestjs-ssr/react 0.3.1 → 0.3.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 CHANGED
@@ -23,9 +23,9 @@ async getProduct(@Param('id') id: string) {
23
23
 
24
24
  ```tsx
25
25
  export default function ProductDetail({
26
- data,
26
+ product,
27
27
  }: PageProps<{ product: Product }>) {
28
- return <h1>{data.product.name}</h1>;
28
+ return <h1>{product.name}</h1>;
29
29
  }
30
30
  ```
31
31
 
package/dist/index.js CHANGED
@@ -923,23 +923,27 @@ exports.RenderService = class _RenderService {
923
923
  "src/views/_layout.tsx"
924
924
  ];
925
925
  try {
926
- for (const path$1 of conventionalPaths) {
927
- const absolutePath = path.join(process.cwd(), path$1);
928
- if (!fs.existsSync(absolutePath)) {
929
- continue;
930
- }
931
- this.logger.log(`\u2713 Found root layout at ${path$1}`);
932
- if (this.vite) {
926
+ if (this.vite) {
927
+ for (const path$1 of conventionalPaths) {
928
+ const absolutePath = path.join(process.cwd(), path$1);
929
+ if (!fs.existsSync(absolutePath)) {
930
+ continue;
931
+ }
932
+ this.logger.log(`\u2713 Found root layout at ${path$1}`);
933
933
  const layoutModule = await this.vite.ssrLoadModule("/" + path$1);
934
934
  this.rootLayout = layoutModule.default;
935
935
  return this.rootLayout;
936
- } else {
937
- const prodPath = path$1.replace("src/views", "dist/server/views").replace(".tsx", ".js");
938
- const absoluteProdPath = path.join(process.cwd(), prodPath);
939
- if (fs.existsSync(absoluteProdPath)) {
940
- const layoutModule = await import(absoluteProdPath);
941
- this.rootLayout = layoutModule.default;
942
- return this.rootLayout;
936
+ }
937
+ } else {
938
+ const entryServerPath = path.join(process.cwd(), "dist/server/entry-server.mjs");
939
+ if (fs.existsSync(entryServerPath)) {
940
+ const entryModule = await import(entryServerPath);
941
+ if (entryModule.getRootLayout) {
942
+ this.rootLayout = entryModule.getRootLayout();
943
+ if (this.rootLayout) {
944
+ this.logger.log(`\u2713 Loaded root layout from entry-server bundle`);
945
+ return this.rootLayout;
946
+ }
943
947
  }
944
948
  }
945
949
  }
package/dist/index.mjs CHANGED
@@ -916,23 +916,27 @@ var RenderService = class _RenderService {
916
916
  "src/views/_layout.tsx"
917
917
  ];
918
918
  try {
919
- for (const path of conventionalPaths) {
920
- const absolutePath = join(process.cwd(), path);
921
- if (!existsSync(absolutePath)) {
922
- continue;
923
- }
924
- this.logger.log(`\u2713 Found root layout at ${path}`);
925
- if (this.vite) {
919
+ if (this.vite) {
920
+ for (const path of conventionalPaths) {
921
+ const absolutePath = join(process.cwd(), path);
922
+ if (!existsSync(absolutePath)) {
923
+ continue;
924
+ }
925
+ this.logger.log(`\u2713 Found root layout at ${path}`);
926
926
  const layoutModule = await this.vite.ssrLoadModule("/" + path);
927
927
  this.rootLayout = layoutModule.default;
928
928
  return this.rootLayout;
929
- } else {
930
- const prodPath = path.replace("src/views", "dist/server/views").replace(".tsx", ".js");
931
- const absoluteProdPath = join(process.cwd(), prodPath);
932
- if (existsSync(absoluteProdPath)) {
933
- const layoutModule = await import(absoluteProdPath);
934
- this.rootLayout = layoutModule.default;
935
- return this.rootLayout;
929
+ }
930
+ } else {
931
+ const entryServerPath = join(process.cwd(), "dist/server/entry-server.mjs");
932
+ if (existsSync(entryServerPath)) {
933
+ const entryModule = await import(entryServerPath);
934
+ if (entryModule.getRootLayout) {
935
+ this.rootLayout = entryModule.getRootLayout();
936
+ if (this.rootLayout) {
937
+ this.logger.log(`\u2713 Loaded root layout from entry-server bundle`);
938
+ return this.rootLayout;
939
+ }
936
940
  }
937
941
  }
938
942
  }
@@ -923,23 +923,27 @@ exports.RenderService = class _RenderService {
923
923
  "src/views/_layout.tsx"
924
924
  ];
925
925
  try {
926
- for (const path$1 of conventionalPaths) {
927
- const absolutePath = path.join(process.cwd(), path$1);
928
- if (!fs.existsSync(absolutePath)) {
929
- continue;
930
- }
931
- this.logger.log(`\u2713 Found root layout at ${path$1}`);
932
- if (this.vite) {
926
+ if (this.vite) {
927
+ for (const path$1 of conventionalPaths) {
928
+ const absolutePath = path.join(process.cwd(), path$1);
929
+ if (!fs.existsSync(absolutePath)) {
930
+ continue;
931
+ }
932
+ this.logger.log(`\u2713 Found root layout at ${path$1}`);
933
933
  const layoutModule = await this.vite.ssrLoadModule("/" + path$1);
934
934
  this.rootLayout = layoutModule.default;
935
935
  return this.rootLayout;
936
- } else {
937
- const prodPath = path$1.replace("src/views", "dist/server/views").replace(".tsx", ".js");
938
- const absoluteProdPath = path.join(process.cwd(), prodPath);
939
- if (fs.existsSync(absoluteProdPath)) {
940
- const layoutModule = await import(absoluteProdPath);
941
- this.rootLayout = layoutModule.default;
942
- return this.rootLayout;
936
+ }
937
+ } else {
938
+ const entryServerPath = path.join(process.cwd(), "dist/server/entry-server.mjs");
939
+ if (fs.existsSync(entryServerPath)) {
940
+ const entryModule = await import(entryServerPath);
941
+ if (entryModule.getRootLayout) {
942
+ this.rootLayout = entryModule.getRootLayout();
943
+ if (this.rootLayout) {
944
+ this.logger.log(`\u2713 Loaded root layout from entry-server bundle`);
945
+ return this.rootLayout;
946
+ }
943
947
  }
944
948
  }
945
949
  }
@@ -916,23 +916,27 @@ var RenderService = class _RenderService {
916
916
  "src/views/_layout.tsx"
917
917
  ];
918
918
  try {
919
- for (const path of conventionalPaths) {
920
- const absolutePath = join(process.cwd(), path);
921
- if (!existsSync(absolutePath)) {
922
- continue;
923
- }
924
- this.logger.log(`\u2713 Found root layout at ${path}`);
925
- if (this.vite) {
919
+ if (this.vite) {
920
+ for (const path of conventionalPaths) {
921
+ const absolutePath = join(process.cwd(), path);
922
+ if (!existsSync(absolutePath)) {
923
+ continue;
924
+ }
925
+ this.logger.log(`\u2713 Found root layout at ${path}`);
926
926
  const layoutModule = await this.vite.ssrLoadModule("/" + path);
927
927
  this.rootLayout = layoutModule.default;
928
928
  return this.rootLayout;
929
- } else {
930
- const prodPath = path.replace("src/views", "dist/server/views").replace(".tsx", ".js");
931
- const absoluteProdPath = join(process.cwd(), prodPath);
932
- if (existsSync(absoluteProdPath)) {
933
- const layoutModule = await import(absoluteProdPath);
934
- this.rootLayout = layoutModule.default;
935
- return this.rootLayout;
929
+ }
930
+ } else {
931
+ const entryServerPath = join(process.cwd(), "dist/server/entry-server.mjs");
932
+ if (existsSync(entryServerPath)) {
933
+ const entryModule = await import(entryServerPath);
934
+ if (entryModule.getRootLayout) {
935
+ this.rootLayout = entryModule.getRootLayout();
936
+ if (this.rootLayout) {
937
+ this.logger.log(`\u2713 Loaded root layout from entry-server bundle`);
938
+ return this.rootLayout;
939
+ }
936
940
  }
937
941
  }
938
942
  }
@@ -2,6 +2,24 @@ import React from 'react';
2
2
  import { renderToString, renderToPipeableStream } from 'react-dom/server';
3
3
  import { PageContextProvider } from '@nestjs-ssr/react/client';
4
4
 
5
+ // Auto-discover root layout using Vite's glob import
6
+ // This eagerly loads layout if it exists, null otherwise
7
+ // @ts-ignore - Vite-specific API
8
+ const layoutModules = import.meta.glob('@/views/layout.tsx', {
9
+ eager: true,
10
+ }) as Record<string, { default: React.ComponentType<any> }>;
11
+
12
+ const layoutPath = Object.keys(layoutModules)[0];
13
+ const RootLayout = layoutPath ? layoutModules[layoutPath].default : null;
14
+
15
+ /**
16
+ * Get the root layout component.
17
+ * Used by RenderService in production when dynamic import isn't available.
18
+ */
19
+ export function getRootLayout(): React.ComponentType<any> | null {
20
+ return RootLayout;
21
+ }
22
+
5
23
  /**
6
24
  * Compose a component with its layouts from the interceptor.
7
25
  * Layouts are passed from the RenderInterceptor based on decorators.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestjs-ssr/react",
3
- "version": "0.3.1",
3
+ "version": "0.3.3",
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",
@@ -2,6 +2,24 @@ import React from 'react';
2
2
  import { renderToString, renderToPipeableStream } from 'react-dom/server';
3
3
  import { PageContextProvider } from '@nestjs-ssr/react/client';
4
4
 
5
+ // Auto-discover root layout using Vite's glob import
6
+ // This eagerly loads layout if it exists, null otherwise
7
+ // @ts-ignore - Vite-specific API
8
+ const layoutModules = import.meta.glob('@/views/layout.tsx', {
9
+ eager: true,
10
+ }) as Record<string, { default: React.ComponentType<any> }>;
11
+
12
+ const layoutPath = Object.keys(layoutModules)[0];
13
+ const RootLayout = layoutPath ? layoutModules[layoutPath].default : null;
14
+
15
+ /**
16
+ * Get the root layout component.
17
+ * Used by RenderService in production when dynamic import isn't available.
18
+ */
19
+ export function getRootLayout(): React.ComponentType<any> | null {
20
+ return RootLayout;
21
+ }
22
+
5
23
  /**
6
24
  * Compose a component with its layouts from the interceptor.
7
25
  * Layouts are passed from the RenderInterceptor based on decorators.