@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 +2 -2
- package/dist/index.js +18 -14
- package/dist/index.mjs +18 -14
- package/dist/render/index.js +18 -14
- package/dist/render/index.mjs +18 -14
- package/dist/templates/entry-server.tsx +18 -0
- package/package.json +1 -1
- package/src/templates/entry-server.tsx +18 -0
package/README.md
CHANGED
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
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
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
|
-
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
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
|
-
|
|
920
|
-
const
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
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
|
-
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
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
|
}
|
package/dist/render/index.js
CHANGED
|
@@ -923,23 +923,27 @@ exports.RenderService = class _RenderService {
|
|
|
923
923
|
"src/views/_layout.tsx"
|
|
924
924
|
];
|
|
925
925
|
try {
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
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
|
-
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
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/render/index.mjs
CHANGED
|
@@ -916,23 +916,27 @@ var RenderService = class _RenderService {
|
|
|
916
916
|
"src/views/_layout.tsx"
|
|
917
917
|
];
|
|
918
918
|
try {
|
|
919
|
-
|
|
920
|
-
const
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
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
|
-
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
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
|
@@ -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.
|