@nestjs-ssr/react 0.3.2 → 0.3.4
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/cli/init.js +5 -5
- package/dist/cli/init.mjs +5 -5
- package/dist/index.js +54 -46
- package/dist/index.mjs +24 -16
- package/dist/render/index.js +41 -34
- package/dist/render/index.mjs +23 -15
- package/dist/templates/entry-client.tsx +48 -25
- package/dist/templates/entry-server.tsx +18 -0
- package/etc/react.api.md +250 -262
- package/package.json +1 -1
- package/src/templates/entry-client.tsx +48 -25
- package/src/templates/entry-server.tsx +18 -0
package/README.md
CHANGED
package/dist/cli/init.js
CHANGED
|
@@ -39,7 +39,7 @@ var main = citty.defineCommand({
|
|
|
39
39
|
default: "5173"
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
-
|
|
42
|
+
run({ args }) {
|
|
43
43
|
const cwd = process.cwd();
|
|
44
44
|
const viewsDir = args.views;
|
|
45
45
|
const vitePort = parseInt(args.port, 10) || 5173;
|
|
@@ -419,17 +419,17 @@ export default defineConfig({
|
|
|
419
419
|
packageJson.scripts["start:dev"] = 'concurrently --raw -n vite,nest -c cyan,green "pnpm:dev:vite" "pnpm:dev:nest"';
|
|
420
420
|
shouldUpdate = true;
|
|
421
421
|
}
|
|
422
|
-
const existingBuild = packageJson.scripts
|
|
422
|
+
const existingBuild = packageJson.scripts["build"];
|
|
423
423
|
const recommendedBuild = "nest build && pnpm build:client && pnpm build:server";
|
|
424
424
|
if (!existingBuild) {
|
|
425
|
-
packageJson.scripts
|
|
425
|
+
packageJson.scripts["build"] = recommendedBuild;
|
|
426
426
|
shouldUpdate = true;
|
|
427
427
|
consola.consola.success("Created build script");
|
|
428
428
|
} else if (existingBuild !== recommendedBuild) {
|
|
429
429
|
if (!existingBuild.includes("build:client") || !existingBuild.includes("build:server")) {
|
|
430
430
|
consola.consola.warn(`Found existing build script: "${existingBuild}"`);
|
|
431
431
|
consola.consola.info(`Updating to: ${recommendedBuild}`);
|
|
432
|
-
packageJson.scripts
|
|
432
|
+
packageJson.scripts["build"] = recommendedBuild;
|
|
433
433
|
shouldUpdate = true;
|
|
434
434
|
} else {
|
|
435
435
|
consola.consola.info("Build scripts already configured");
|
|
@@ -528,4 +528,4 @@ export default defineConfig({
|
|
|
528
528
|
consola.consola.log(" Terminal 2: pnpm dev:nest");
|
|
529
529
|
}
|
|
530
530
|
});
|
|
531
|
-
citty.runMain(main);
|
|
531
|
+
void citty.runMain(main);
|
package/dist/cli/init.mjs
CHANGED
|
@@ -36,7 +36,7 @@ var main = defineCommand({
|
|
|
36
36
|
default: "5173"
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
|
-
|
|
39
|
+
run({ args }) {
|
|
40
40
|
const cwd = process.cwd();
|
|
41
41
|
const viewsDir = args.views;
|
|
42
42
|
const vitePort = parseInt(args.port, 10) || 5173;
|
|
@@ -416,17 +416,17 @@ export default defineConfig({
|
|
|
416
416
|
packageJson.scripts["start:dev"] = 'concurrently --raw -n vite,nest -c cyan,green "pnpm:dev:vite" "pnpm:dev:nest"';
|
|
417
417
|
shouldUpdate = true;
|
|
418
418
|
}
|
|
419
|
-
const existingBuild = packageJson.scripts
|
|
419
|
+
const existingBuild = packageJson.scripts["build"];
|
|
420
420
|
const recommendedBuild = "nest build && pnpm build:client && pnpm build:server";
|
|
421
421
|
if (!existingBuild) {
|
|
422
|
-
packageJson.scripts
|
|
422
|
+
packageJson.scripts["build"] = recommendedBuild;
|
|
423
423
|
shouldUpdate = true;
|
|
424
424
|
consola.success("Created build script");
|
|
425
425
|
} else if (existingBuild !== recommendedBuild) {
|
|
426
426
|
if (!existingBuild.includes("build:client") || !existingBuild.includes("build:server")) {
|
|
427
427
|
consola.warn(`Found existing build script: "${existingBuild}"`);
|
|
428
428
|
consola.info(`Updating to: ${recommendedBuild}`);
|
|
429
|
-
packageJson.scripts
|
|
429
|
+
packageJson.scripts["build"] = recommendedBuild;
|
|
430
430
|
shouldUpdate = true;
|
|
431
431
|
} else {
|
|
432
432
|
consola.info("Build scripts already configured");
|
|
@@ -525,4 +525,4 @@ export default defineConfig({
|
|
|
525
525
|
consola.log(" Terminal 2: pnpm dev:nest");
|
|
526
526
|
}
|
|
527
527
|
});
|
|
528
|
-
runMain(main);
|
|
528
|
+
void runMain(main);
|
package/dist/index.js
CHANGED
|
@@ -7,13 +7,13 @@ var path = require('path');
|
|
|
7
7
|
var devalue = require('devalue');
|
|
8
8
|
var escapeHtml = require('escape-html');
|
|
9
9
|
var server = require('react-dom/server');
|
|
10
|
-
var
|
|
10
|
+
var React2 = require('react');
|
|
11
11
|
var operators = require('rxjs/operators');
|
|
12
12
|
|
|
13
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
|
|
15
15
|
var escapeHtml__default = /*#__PURE__*/_interopDefault(escapeHtml);
|
|
16
|
-
var
|
|
16
|
+
var React2__default = /*#__PURE__*/_interopDefault(React2);
|
|
17
17
|
|
|
18
18
|
var __defProp = Object.defineProperty;
|
|
19
19
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -339,16 +339,18 @@ StringRenderer = _ts_decorate2([
|
|
|
339
339
|
typeof exports.TemplateParserService === "undefined" ? Object : exports.TemplateParserService
|
|
340
340
|
])
|
|
341
341
|
], StringRenderer);
|
|
342
|
+
|
|
343
|
+
// src/render/error-pages/error-page-development.tsx
|
|
342
344
|
function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
343
345
|
const stackLines = error.stack ? error.stack.split("\n").slice(1) : [];
|
|
344
|
-
return /* @__PURE__ */
|
|
346
|
+
return /* @__PURE__ */ React.createElement("html", {
|
|
345
347
|
lang: "en"
|
|
346
|
-
}, /* @__PURE__ */
|
|
348
|
+
}, /* @__PURE__ */ React.createElement("head", null, /* @__PURE__ */ React.createElement("meta", {
|
|
347
349
|
charSet: "UTF-8"
|
|
348
|
-
}), /* @__PURE__ */
|
|
350
|
+
}), /* @__PURE__ */ React.createElement("meta", {
|
|
349
351
|
name: "viewport",
|
|
350
352
|
content: "width=device-width, initial-scale=1.0"
|
|
351
|
-
}), /* @__PURE__ */
|
|
353
|
+
}), /* @__PURE__ */ React.createElement("title", null, `SSR Error - ${error.name}`), /* @__PURE__ */ React.createElement("style", {
|
|
352
354
|
dangerouslySetInnerHTML: {
|
|
353
355
|
__html: `
|
|
354
356
|
body {
|
|
@@ -399,28 +401,30 @@ function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
|
399
401
|
}
|
|
400
402
|
`
|
|
401
403
|
}
|
|
402
|
-
})), /* @__PURE__ */
|
|
404
|
+
})), /* @__PURE__ */ React.createElement("body", null, /* @__PURE__ */ React.createElement("div", {
|
|
403
405
|
className: "error-container"
|
|
404
|
-
}, /* @__PURE__ */
|
|
406
|
+
}, /* @__PURE__ */ React.createElement("h1", null, "Server-Side Rendering Error"), /* @__PURE__ */ React.createElement("div", {
|
|
405
407
|
className: "error-type"
|
|
406
|
-
}, error.name), /* @__PURE__ */
|
|
408
|
+
}, error.name), /* @__PURE__ */ React.createElement("div", {
|
|
407
409
|
className: "error-message"
|
|
408
|
-
}, error.message), /* @__PURE__ */
|
|
410
|
+
}, error.message), /* @__PURE__ */ React.createElement("h2", null, "Stack Trace"), /* @__PURE__ */ React.createElement("div", {
|
|
409
411
|
className: "stack-trace"
|
|
410
|
-
}, /* @__PURE__ */
|
|
412
|
+
}, /* @__PURE__ */ React.createElement("pre", null, stackLines.join("\n"))), /* @__PURE__ */ React.createElement("div", {
|
|
411
413
|
className: "meta"
|
|
412
|
-
}, /* @__PURE__ */
|
|
414
|
+
}, /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "View Path:"), " ", viewPath), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "Error Phase:"), " ", phase === "shell" ? "Shell (before streaming started)" : "Streaming (during content delivery)"), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "Environment:"), " Development")))));
|
|
413
415
|
}
|
|
414
416
|
__name(ErrorPageDevelopment, "ErrorPageDevelopment");
|
|
417
|
+
|
|
418
|
+
// src/render/error-pages/error-page-production.tsx
|
|
415
419
|
function ErrorPageProduction() {
|
|
416
|
-
return /* @__PURE__ */
|
|
420
|
+
return /* @__PURE__ */ React.createElement("html", {
|
|
417
421
|
lang: "en"
|
|
418
|
-
}, /* @__PURE__ */
|
|
422
|
+
}, /* @__PURE__ */ React.createElement("head", null, /* @__PURE__ */ React.createElement("meta", {
|
|
419
423
|
charSet: "UTF-8"
|
|
420
|
-
}), /* @__PURE__ */
|
|
424
|
+
}), /* @__PURE__ */ React.createElement("meta", {
|
|
421
425
|
name: "viewport",
|
|
422
426
|
content: "width=device-width, initial-scale=1.0"
|
|
423
|
-
}), /* @__PURE__ */
|
|
427
|
+
}), /* @__PURE__ */ React.createElement("title", null, "Error"), /* @__PURE__ */ React.createElement("style", {
|
|
424
428
|
dangerouslySetInnerHTML: {
|
|
425
429
|
__html: `
|
|
426
430
|
body {
|
|
@@ -447,9 +451,9 @@ function ErrorPageProduction() {
|
|
|
447
451
|
}
|
|
448
452
|
`
|
|
449
453
|
}
|
|
450
|
-
})), /* @__PURE__ */
|
|
454
|
+
})), /* @__PURE__ */ React.createElement("body", null, /* @__PURE__ */ React.createElement("div", {
|
|
451
455
|
className: "error-container"
|
|
452
|
-
}, /* @__PURE__ */
|
|
456
|
+
}, /* @__PURE__ */ React.createElement("h1", null, "500"), /* @__PURE__ */ React.createElement("p", null, "Internal Server Error"), /* @__PURE__ */ React.createElement("p", null, "Something went wrong while rendering this page."))));
|
|
453
457
|
}
|
|
454
458
|
__name(ErrorPageProduction, "ErrorPageProduction");
|
|
455
459
|
|
|
@@ -516,7 +520,7 @@ exports.StreamingErrorHandler = class _StreamingErrorHandler {
|
|
|
516
520
|
*/
|
|
517
521
|
renderDevelopmentErrorPage(error, viewPath, phase) {
|
|
518
522
|
const ErrorComponent = this.errorPageDevelopment || ErrorPageDevelopment;
|
|
519
|
-
const element =
|
|
523
|
+
const element = React2.createElement(ErrorComponent, {
|
|
520
524
|
error,
|
|
521
525
|
viewPath,
|
|
522
526
|
phase
|
|
@@ -528,7 +532,7 @@ exports.StreamingErrorHandler = class _StreamingErrorHandler {
|
|
|
528
532
|
*/
|
|
529
533
|
renderProductionErrorPage() {
|
|
530
534
|
const ErrorComponent = this.errorPageProduction || ErrorPageProduction;
|
|
531
|
-
const element =
|
|
535
|
+
const element = React2.createElement(ErrorComponent);
|
|
532
536
|
return "<!DOCTYPE html>\n" + server.renderToStaticMarkup(element);
|
|
533
537
|
}
|
|
534
538
|
/**
|
|
@@ -923,23 +927,27 @@ exports.RenderService = class _RenderService {
|
|
|
923
927
|
"src/views/_layout.tsx"
|
|
924
928
|
];
|
|
925
929
|
try {
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
930
|
+
if (this.vite) {
|
|
931
|
+
for (const path$1 of conventionalPaths) {
|
|
932
|
+
const absolutePath = path.join(process.cwd(), path$1);
|
|
933
|
+
if (!fs.existsSync(absolutePath)) {
|
|
934
|
+
continue;
|
|
935
|
+
}
|
|
936
|
+
this.logger.log(`\u2713 Found root layout at ${path$1}`);
|
|
933
937
|
const layoutModule = await this.vite.ssrLoadModule("/" + path$1);
|
|
934
938
|
this.rootLayout = layoutModule.default;
|
|
935
939
|
return this.rootLayout;
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
940
|
+
}
|
|
941
|
+
} else {
|
|
942
|
+
const entryServerPath = path.join(process.cwd(), "dist/server/entry-server.mjs");
|
|
943
|
+
if (fs.existsSync(entryServerPath)) {
|
|
944
|
+
const entryModule = await import(entryServerPath);
|
|
945
|
+
if (entryModule.getRootLayout) {
|
|
946
|
+
this.rootLayout = entryModule.getRootLayout();
|
|
947
|
+
if (this.rootLayout) {
|
|
948
|
+
this.logger.log(`\u2713 Loaded root layout from entry-server bundle`);
|
|
949
|
+
return this.rootLayout;
|
|
950
|
+
}
|
|
943
951
|
}
|
|
944
952
|
}
|
|
945
953
|
}
|
|
@@ -1699,7 +1707,7 @@ var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("nestjs-ssr.PageContext");
|
|
|
1699
1707
|
var globalStore = globalThis;
|
|
1700
1708
|
function getOrCreateContext() {
|
|
1701
1709
|
if (!globalStore[CONTEXT_KEY]) {
|
|
1702
|
-
globalStore[CONTEXT_KEY] = /* @__PURE__ */
|
|
1710
|
+
globalStore[CONTEXT_KEY] = /* @__PURE__ */ React2.createContext(null);
|
|
1703
1711
|
}
|
|
1704
1712
|
return globalStore[CONTEXT_KEY];
|
|
1705
1713
|
}
|
|
@@ -1709,12 +1717,12 @@ function registerPageContextState(setter) {
|
|
|
1709
1717
|
}
|
|
1710
1718
|
__name(registerPageContextState, "registerPageContextState");
|
|
1711
1719
|
function PageContextProvider({ context: initialContext, children, isSegment = false }) {
|
|
1712
|
-
const [context, setContext] =
|
|
1713
|
-
|
|
1720
|
+
const [context, setContext] = React2.useState(initialContext);
|
|
1721
|
+
React2.useEffect(() => {
|
|
1714
1722
|
}, [
|
|
1715
1723
|
isSegment
|
|
1716
1724
|
]);
|
|
1717
|
-
return /* @__PURE__ */
|
|
1725
|
+
return /* @__PURE__ */ React2__default.default.createElement(PageContext.Provider, {
|
|
1718
1726
|
value: context
|
|
1719
1727
|
}, children);
|
|
1720
1728
|
}
|
|
@@ -1726,7 +1734,7 @@ function createSSRHooks() {
|
|
|
1726
1734
|
* Contains URL metadata, headers, and any custom properties you've added.
|
|
1727
1735
|
*/
|
|
1728
1736
|
usePageContext: /* @__PURE__ */ __name(() => {
|
|
1729
|
-
const context =
|
|
1737
|
+
const context = React2.useContext(PageContext);
|
|
1730
1738
|
if (!context) {
|
|
1731
1739
|
throw new Error("usePageContext must be used within PageContextProvider");
|
|
1732
1740
|
}
|
|
@@ -1743,7 +1751,7 @@ function createSSRHooks() {
|
|
|
1743
1751
|
* ```
|
|
1744
1752
|
*/
|
|
1745
1753
|
useParams: /* @__PURE__ */ __name(() => {
|
|
1746
|
-
const context =
|
|
1754
|
+
const context = React2.useContext(PageContext);
|
|
1747
1755
|
if (!context) {
|
|
1748
1756
|
throw new Error("useParams must be used within PageContextProvider");
|
|
1749
1757
|
}
|
|
@@ -1761,7 +1769,7 @@ function createSSRHooks() {
|
|
|
1761
1769
|
* ```
|
|
1762
1770
|
*/
|
|
1763
1771
|
useQuery: /* @__PURE__ */ __name(() => {
|
|
1764
|
-
const context =
|
|
1772
|
+
const context = React2.useContext(PageContext);
|
|
1765
1773
|
if (!context) {
|
|
1766
1774
|
throw new Error("useQuery must be used within PageContextProvider");
|
|
1767
1775
|
}
|
|
@@ -1781,7 +1789,7 @@ function createSSRHooks() {
|
|
|
1781
1789
|
* ```
|
|
1782
1790
|
*/
|
|
1783
1791
|
useRequest: /* @__PURE__ */ __name(() => {
|
|
1784
|
-
const context =
|
|
1792
|
+
const context = React2.useContext(PageContext);
|
|
1785
1793
|
if (!context) {
|
|
1786
1794
|
throw new Error("useRequest must be used within PageContextProvider");
|
|
1787
1795
|
}
|
|
@@ -1807,7 +1815,7 @@ function createSSRHooks() {
|
|
|
1807
1815
|
* ```
|
|
1808
1816
|
*/
|
|
1809
1817
|
useHeaders: /* @__PURE__ */ __name(() => {
|
|
1810
|
-
const context =
|
|
1818
|
+
const context = React2.useContext(PageContext);
|
|
1811
1819
|
if (!context) {
|
|
1812
1820
|
throw new Error("useHeaders must be used within PageContextProvider");
|
|
1813
1821
|
}
|
|
@@ -1842,7 +1850,7 @@ function createSSRHooks() {
|
|
|
1842
1850
|
* ```
|
|
1843
1851
|
*/
|
|
1844
1852
|
useHeader: /* @__PURE__ */ __name((name) => {
|
|
1845
|
-
const context =
|
|
1853
|
+
const context = React2.useContext(PageContext);
|
|
1846
1854
|
if (!context) {
|
|
1847
1855
|
throw new Error("useHeader must be used within PageContextProvider");
|
|
1848
1856
|
}
|
|
@@ -1868,7 +1876,7 @@ function createSSRHooks() {
|
|
|
1868
1876
|
* ```
|
|
1869
1877
|
*/
|
|
1870
1878
|
useCookies: /* @__PURE__ */ __name(() => {
|
|
1871
|
-
const context =
|
|
1879
|
+
const context = React2.useContext(PageContext);
|
|
1872
1880
|
if (!context) {
|
|
1873
1881
|
throw new Error("useCookies must be used within PageContextProvider");
|
|
1874
1882
|
}
|
|
@@ -1890,7 +1898,7 @@ function createSSRHooks() {
|
|
|
1890
1898
|
* ```
|
|
1891
1899
|
*/
|
|
1892
1900
|
useCookie: /* @__PURE__ */ __name((name) => {
|
|
1893
|
-
const context =
|
|
1901
|
+
const context = React2.useContext(PageContext);
|
|
1894
1902
|
if (!context) {
|
|
1895
1903
|
throw new Error("useCookie must be used within PageContextProvider");
|
|
1896
1904
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { join, relative } from 'path';
|
|
|
5
5
|
import { uneval } from 'devalue';
|
|
6
6
|
import escapeHtml from 'escape-html';
|
|
7
7
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
8
|
-
import
|
|
8
|
+
import React2, { createElement, createContext, useContext, useState, useEffect } from 'react';
|
|
9
9
|
import { switchMap } from 'rxjs/operators';
|
|
10
10
|
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
@@ -332,6 +332,8 @@ StringRenderer = _ts_decorate2([
|
|
|
332
332
|
typeof TemplateParserService === "undefined" ? Object : TemplateParserService
|
|
333
333
|
])
|
|
334
334
|
], StringRenderer);
|
|
335
|
+
|
|
336
|
+
// src/render/error-pages/error-page-development.tsx
|
|
335
337
|
function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
336
338
|
const stackLines = error.stack ? error.stack.split("\n").slice(1) : [];
|
|
337
339
|
return /* @__PURE__ */ React.createElement("html", {
|
|
@@ -405,6 +407,8 @@ function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
|
405
407
|
}, /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "View Path:"), " ", viewPath), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "Error Phase:"), " ", phase === "shell" ? "Shell (before streaming started)" : "Streaming (during content delivery)"), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "Environment:"), " Development")))));
|
|
406
408
|
}
|
|
407
409
|
__name(ErrorPageDevelopment, "ErrorPageDevelopment");
|
|
410
|
+
|
|
411
|
+
// src/render/error-pages/error-page-production.tsx
|
|
408
412
|
function ErrorPageProduction() {
|
|
409
413
|
return /* @__PURE__ */ React.createElement("html", {
|
|
410
414
|
lang: "en"
|
|
@@ -916,23 +920,27 @@ var RenderService = class _RenderService {
|
|
|
916
920
|
"src/views/_layout.tsx"
|
|
917
921
|
];
|
|
918
922
|
try {
|
|
919
|
-
|
|
920
|
-
const
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
923
|
+
if (this.vite) {
|
|
924
|
+
for (const path of conventionalPaths) {
|
|
925
|
+
const absolutePath = join(process.cwd(), path);
|
|
926
|
+
if (!existsSync(absolutePath)) {
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
this.logger.log(`\u2713 Found root layout at ${path}`);
|
|
926
930
|
const layoutModule = await this.vite.ssrLoadModule("/" + path);
|
|
927
931
|
this.rootLayout = layoutModule.default;
|
|
928
932
|
return this.rootLayout;
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
933
|
+
}
|
|
934
|
+
} else {
|
|
935
|
+
const entryServerPath = join(process.cwd(), "dist/server/entry-server.mjs");
|
|
936
|
+
if (existsSync(entryServerPath)) {
|
|
937
|
+
const entryModule = await import(entryServerPath);
|
|
938
|
+
if (entryModule.getRootLayout) {
|
|
939
|
+
this.rootLayout = entryModule.getRootLayout();
|
|
940
|
+
if (this.rootLayout) {
|
|
941
|
+
this.logger.log(`\u2713 Loaded root layout from entry-server bundle`);
|
|
942
|
+
return this.rootLayout;
|
|
943
|
+
}
|
|
936
944
|
}
|
|
937
945
|
}
|
|
938
946
|
}
|
|
@@ -1707,7 +1715,7 @@ function PageContextProvider({ context: initialContext, children, isSegment = fa
|
|
|
1707
1715
|
}, [
|
|
1708
1716
|
isSegment
|
|
1709
1717
|
]);
|
|
1710
|
-
return /* @__PURE__ */
|
|
1718
|
+
return /* @__PURE__ */ React2.createElement(PageContext.Provider, {
|
|
1711
1719
|
value: context
|
|
1712
1720
|
}, children);
|
|
1713
1721
|
}
|
package/dist/render/index.js
CHANGED
|
@@ -7,13 +7,12 @@ var path = require('path');
|
|
|
7
7
|
var devalue = require('devalue');
|
|
8
8
|
var escapeHtml = require('escape-html');
|
|
9
9
|
var server = require('react-dom/server');
|
|
10
|
-
var
|
|
10
|
+
var react = require('react');
|
|
11
11
|
var operators = require('rxjs/operators');
|
|
12
12
|
|
|
13
13
|
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
14
14
|
|
|
15
15
|
var escapeHtml__default = /*#__PURE__*/_interopDefault(escapeHtml);
|
|
16
|
-
var React__default = /*#__PURE__*/_interopDefault(React);
|
|
17
16
|
|
|
18
17
|
var __defProp = Object.defineProperty;
|
|
19
18
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -339,16 +338,18 @@ StringRenderer = _ts_decorate2([
|
|
|
339
338
|
typeof exports.TemplateParserService === "undefined" ? Object : exports.TemplateParserService
|
|
340
339
|
])
|
|
341
340
|
], StringRenderer);
|
|
341
|
+
|
|
342
|
+
// src/render/error-pages/error-page-development.tsx
|
|
342
343
|
function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
343
344
|
const stackLines = error.stack ? error.stack.split("\n").slice(1) : [];
|
|
344
|
-
return /* @__PURE__ */
|
|
345
|
+
return /* @__PURE__ */ React.createElement("html", {
|
|
345
346
|
lang: "en"
|
|
346
|
-
}, /* @__PURE__ */
|
|
347
|
+
}, /* @__PURE__ */ React.createElement("head", null, /* @__PURE__ */ React.createElement("meta", {
|
|
347
348
|
charSet: "UTF-8"
|
|
348
|
-
}), /* @__PURE__ */
|
|
349
|
+
}), /* @__PURE__ */ React.createElement("meta", {
|
|
349
350
|
name: "viewport",
|
|
350
351
|
content: "width=device-width, initial-scale=1.0"
|
|
351
|
-
}), /* @__PURE__ */
|
|
352
|
+
}), /* @__PURE__ */ React.createElement("title", null, `SSR Error - ${error.name}`), /* @__PURE__ */ React.createElement("style", {
|
|
352
353
|
dangerouslySetInnerHTML: {
|
|
353
354
|
__html: `
|
|
354
355
|
body {
|
|
@@ -399,28 +400,30 @@ function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
|
399
400
|
}
|
|
400
401
|
`
|
|
401
402
|
}
|
|
402
|
-
})), /* @__PURE__ */
|
|
403
|
+
})), /* @__PURE__ */ React.createElement("body", null, /* @__PURE__ */ React.createElement("div", {
|
|
403
404
|
className: "error-container"
|
|
404
|
-
}, /* @__PURE__ */
|
|
405
|
+
}, /* @__PURE__ */ React.createElement("h1", null, "Server-Side Rendering Error"), /* @__PURE__ */ React.createElement("div", {
|
|
405
406
|
className: "error-type"
|
|
406
|
-
}, error.name), /* @__PURE__ */
|
|
407
|
+
}, error.name), /* @__PURE__ */ React.createElement("div", {
|
|
407
408
|
className: "error-message"
|
|
408
|
-
}, error.message), /* @__PURE__ */
|
|
409
|
+
}, error.message), /* @__PURE__ */ React.createElement("h2", null, "Stack Trace"), /* @__PURE__ */ React.createElement("div", {
|
|
409
410
|
className: "stack-trace"
|
|
410
|
-
}, /* @__PURE__ */
|
|
411
|
+
}, /* @__PURE__ */ React.createElement("pre", null, stackLines.join("\n"))), /* @__PURE__ */ React.createElement("div", {
|
|
411
412
|
className: "meta"
|
|
412
|
-
}, /* @__PURE__ */
|
|
413
|
+
}, /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "View Path:"), " ", viewPath), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "Error Phase:"), " ", phase === "shell" ? "Shell (before streaming started)" : "Streaming (during content delivery)"), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "Environment:"), " Development")))));
|
|
413
414
|
}
|
|
414
415
|
__name(ErrorPageDevelopment, "ErrorPageDevelopment");
|
|
416
|
+
|
|
417
|
+
// src/render/error-pages/error-page-production.tsx
|
|
415
418
|
function ErrorPageProduction() {
|
|
416
|
-
return /* @__PURE__ */
|
|
419
|
+
return /* @__PURE__ */ React.createElement("html", {
|
|
417
420
|
lang: "en"
|
|
418
|
-
}, /* @__PURE__ */
|
|
421
|
+
}, /* @__PURE__ */ React.createElement("head", null, /* @__PURE__ */ React.createElement("meta", {
|
|
419
422
|
charSet: "UTF-8"
|
|
420
|
-
}), /* @__PURE__ */
|
|
423
|
+
}), /* @__PURE__ */ React.createElement("meta", {
|
|
421
424
|
name: "viewport",
|
|
422
425
|
content: "width=device-width, initial-scale=1.0"
|
|
423
|
-
}), /* @__PURE__ */
|
|
426
|
+
}), /* @__PURE__ */ React.createElement("title", null, "Error"), /* @__PURE__ */ React.createElement("style", {
|
|
424
427
|
dangerouslySetInnerHTML: {
|
|
425
428
|
__html: `
|
|
426
429
|
body {
|
|
@@ -447,9 +450,9 @@ function ErrorPageProduction() {
|
|
|
447
450
|
}
|
|
448
451
|
`
|
|
449
452
|
}
|
|
450
|
-
})), /* @__PURE__ */
|
|
453
|
+
})), /* @__PURE__ */ React.createElement("body", null, /* @__PURE__ */ React.createElement("div", {
|
|
451
454
|
className: "error-container"
|
|
452
|
-
}, /* @__PURE__ */
|
|
455
|
+
}, /* @__PURE__ */ React.createElement("h1", null, "500"), /* @__PURE__ */ React.createElement("p", null, "Internal Server Error"), /* @__PURE__ */ React.createElement("p", null, "Something went wrong while rendering this page."))));
|
|
453
456
|
}
|
|
454
457
|
__name(ErrorPageProduction, "ErrorPageProduction");
|
|
455
458
|
|
|
@@ -516,7 +519,7 @@ exports.StreamingErrorHandler = class _StreamingErrorHandler {
|
|
|
516
519
|
*/
|
|
517
520
|
renderDevelopmentErrorPage(error, viewPath, phase) {
|
|
518
521
|
const ErrorComponent = this.errorPageDevelopment || ErrorPageDevelopment;
|
|
519
|
-
const element =
|
|
522
|
+
const element = react.createElement(ErrorComponent, {
|
|
520
523
|
error,
|
|
521
524
|
viewPath,
|
|
522
525
|
phase
|
|
@@ -528,7 +531,7 @@ exports.StreamingErrorHandler = class _StreamingErrorHandler {
|
|
|
528
531
|
*/
|
|
529
532
|
renderProductionErrorPage() {
|
|
530
533
|
const ErrorComponent = this.errorPageProduction || ErrorPageProduction;
|
|
531
|
-
const element =
|
|
534
|
+
const element = react.createElement(ErrorComponent);
|
|
532
535
|
return "<!DOCTYPE html>\n" + server.renderToStaticMarkup(element);
|
|
533
536
|
}
|
|
534
537
|
/**
|
|
@@ -923,23 +926,27 @@ exports.RenderService = class _RenderService {
|
|
|
923
926
|
"src/views/_layout.tsx"
|
|
924
927
|
];
|
|
925
928
|
try {
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
929
|
+
if (this.vite) {
|
|
930
|
+
for (const path$1 of conventionalPaths) {
|
|
931
|
+
const absolutePath = path.join(process.cwd(), path$1);
|
|
932
|
+
if (!fs.existsSync(absolutePath)) {
|
|
933
|
+
continue;
|
|
934
|
+
}
|
|
935
|
+
this.logger.log(`\u2713 Found root layout at ${path$1}`);
|
|
933
936
|
const layoutModule = await this.vite.ssrLoadModule("/" + path$1);
|
|
934
937
|
this.rootLayout = layoutModule.default;
|
|
935
938
|
return this.rootLayout;
|
|
936
|
-
}
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
939
|
+
}
|
|
940
|
+
} else {
|
|
941
|
+
const entryServerPath = path.join(process.cwd(), "dist/server/entry-server.mjs");
|
|
942
|
+
if (fs.existsSync(entryServerPath)) {
|
|
943
|
+
const entryModule = await import(entryServerPath);
|
|
944
|
+
if (entryModule.getRootLayout) {
|
|
945
|
+
this.rootLayout = entryModule.getRootLayout();
|
|
946
|
+
if (this.rootLayout) {
|
|
947
|
+
this.logger.log(`\u2713 Loaded root layout from entry-server bundle`);
|
|
948
|
+
return this.rootLayout;
|
|
949
|
+
}
|
|
943
950
|
}
|
|
944
951
|
}
|
|
945
952
|
}
|
package/dist/render/index.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { join, relative } from 'path';
|
|
|
5
5
|
import { uneval } from 'devalue';
|
|
6
6
|
import escapeHtml from 'escape-html';
|
|
7
7
|
import { renderToStaticMarkup } from 'react-dom/server';
|
|
8
|
-
import
|
|
8
|
+
import { createElement } from 'react';
|
|
9
9
|
import { switchMap } from 'rxjs/operators';
|
|
10
10
|
|
|
11
11
|
var __defProp = Object.defineProperty;
|
|
@@ -332,6 +332,8 @@ StringRenderer = _ts_decorate2([
|
|
|
332
332
|
typeof TemplateParserService === "undefined" ? Object : TemplateParserService
|
|
333
333
|
])
|
|
334
334
|
], StringRenderer);
|
|
335
|
+
|
|
336
|
+
// src/render/error-pages/error-page-development.tsx
|
|
335
337
|
function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
336
338
|
const stackLines = error.stack ? error.stack.split("\n").slice(1) : [];
|
|
337
339
|
return /* @__PURE__ */ React.createElement("html", {
|
|
@@ -405,6 +407,8 @@ function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
|
405
407
|
}, /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "View Path:"), " ", viewPath), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "Error Phase:"), " ", phase === "shell" ? "Shell (before streaming started)" : "Streaming (during content delivery)"), /* @__PURE__ */ React.createElement("p", null, /* @__PURE__ */ React.createElement("strong", null, "Environment:"), " Development")))));
|
|
406
408
|
}
|
|
407
409
|
__name(ErrorPageDevelopment, "ErrorPageDevelopment");
|
|
410
|
+
|
|
411
|
+
// src/render/error-pages/error-page-production.tsx
|
|
408
412
|
function ErrorPageProduction() {
|
|
409
413
|
return /* @__PURE__ */ React.createElement("html", {
|
|
410
414
|
lang: "en"
|
|
@@ -916,23 +920,27 @@ var RenderService = class _RenderService {
|
|
|
916
920
|
"src/views/_layout.tsx"
|
|
917
921
|
];
|
|
918
922
|
try {
|
|
919
|
-
|
|
920
|
-
const
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
923
|
+
if (this.vite) {
|
|
924
|
+
for (const path of conventionalPaths) {
|
|
925
|
+
const absolutePath = join(process.cwd(), path);
|
|
926
|
+
if (!existsSync(absolutePath)) {
|
|
927
|
+
continue;
|
|
928
|
+
}
|
|
929
|
+
this.logger.log(`\u2713 Found root layout at ${path}`);
|
|
926
930
|
const layoutModule = await this.vite.ssrLoadModule("/" + path);
|
|
927
931
|
this.rootLayout = layoutModule.default;
|
|
928
932
|
return this.rootLayout;
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
933
|
+
}
|
|
934
|
+
} else {
|
|
935
|
+
const entryServerPath = join(process.cwd(), "dist/server/entry-server.mjs");
|
|
936
|
+
if (existsSync(entryServerPath)) {
|
|
937
|
+
const entryModule = await import(entryServerPath);
|
|
938
|
+
if (entryModule.getRootLayout) {
|
|
939
|
+
this.rootLayout = entryModule.getRootLayout();
|
|
940
|
+
if (this.rootLayout) {
|
|
941
|
+
this.logger.log(`\u2713 Loaded root layout from entry-server bundle`);
|
|
942
|
+
return this.rootLayout;
|
|
943
|
+
}
|
|
936
944
|
}
|
|
937
945
|
}
|
|
938
946
|
}
|