@nestjs-ssr/react 0.3.3 → 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/cli/init.js +5 -5
- package/dist/cli/init.mjs +5 -5
- 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 +90 -36
- package/dist/index.mjs +61 -7
- package/dist/render/index.d.mts +3 -3
- package/dist/render/index.d.ts +3 -3
- package/dist/render/index.js +58 -24
- package/dist/render/index.mjs +41 -6
- 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 +69 -27
- 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/etc/react.api.md +250 -262
- package/package.json +1 -1
- package/src/templates/entry-client.tsx +69 -27
- package/src/templates/entry-server.tsx +25 -8
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 });
|
|
@@ -315,9 +315,13 @@ var StringRenderer = class _StringRenderer {
|
|
|
315
315
|
throw new Error("Server bundle not found in manifest. Run `pnpm build:server` to generate the server bundle.");
|
|
316
316
|
}
|
|
317
317
|
}
|
|
318
|
-
const { data: pageData, __context: pageContext } = data;
|
|
318
|
+
const { data: pageData, __context: pageContext, __layouts: layouts } = data;
|
|
319
319
|
const html = await renderModule.renderSegment(viewComponent, data);
|
|
320
320
|
const componentName = viewComponent.displayName || viewComponent.name || "Component";
|
|
321
|
+
const layoutMetadata = layouts ? layouts.map((l) => ({
|
|
322
|
+
name: l.layout.displayName || l.layout.name || "default",
|
|
323
|
+
props: l.props
|
|
324
|
+
})) : [];
|
|
321
325
|
if (context.isDevelopment) {
|
|
322
326
|
const duration = Date.now() - startTime;
|
|
323
327
|
this.logger.log(`[SSR] ${componentName} segment rendered in ${duration}ms`);
|
|
@@ -328,7 +332,8 @@ var StringRenderer = class _StringRenderer {
|
|
|
328
332
|
props: pageData,
|
|
329
333
|
swapTarget,
|
|
330
334
|
componentName,
|
|
331
|
-
context: pageContext
|
|
335
|
+
context: pageContext,
|
|
336
|
+
layouts: layoutMetadata
|
|
332
337
|
};
|
|
333
338
|
}
|
|
334
339
|
};
|
|
@@ -339,16 +344,18 @@ StringRenderer = _ts_decorate2([
|
|
|
339
344
|
typeof exports.TemplateParserService === "undefined" ? Object : exports.TemplateParserService
|
|
340
345
|
])
|
|
341
346
|
], StringRenderer);
|
|
347
|
+
|
|
348
|
+
// src/render/error-pages/error-page-development.tsx
|
|
342
349
|
function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
343
350
|
const stackLines = error.stack ? error.stack.split("\n").slice(1) : [];
|
|
344
|
-
return /* @__PURE__ */
|
|
351
|
+
return /* @__PURE__ */ React.createElement("html", {
|
|
345
352
|
lang: "en"
|
|
346
|
-
}, /* @__PURE__ */
|
|
353
|
+
}, /* @__PURE__ */ React.createElement("head", null, /* @__PURE__ */ React.createElement("meta", {
|
|
347
354
|
charSet: "UTF-8"
|
|
348
|
-
}), /* @__PURE__ */
|
|
355
|
+
}), /* @__PURE__ */ React.createElement("meta", {
|
|
349
356
|
name: "viewport",
|
|
350
357
|
content: "width=device-width, initial-scale=1.0"
|
|
351
|
-
}), /* @__PURE__ */
|
|
358
|
+
}), /* @__PURE__ */ React.createElement("title", null, `SSR Error - ${error.name}`), /* @__PURE__ */ React.createElement("style", {
|
|
352
359
|
dangerouslySetInnerHTML: {
|
|
353
360
|
__html: `
|
|
354
361
|
body {
|
|
@@ -399,28 +406,30 @@ function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
|
399
406
|
}
|
|
400
407
|
`
|
|
401
408
|
}
|
|
402
|
-
})), /* @__PURE__ */
|
|
409
|
+
})), /* @__PURE__ */ React.createElement("body", null, /* @__PURE__ */ React.createElement("div", {
|
|
403
410
|
className: "error-container"
|
|
404
|
-
}, /* @__PURE__ */
|
|
411
|
+
}, /* @__PURE__ */ React.createElement("h1", null, "Server-Side Rendering Error"), /* @__PURE__ */ React.createElement("div", {
|
|
405
412
|
className: "error-type"
|
|
406
|
-
}, error.name), /* @__PURE__ */
|
|
413
|
+
}, error.name), /* @__PURE__ */ React.createElement("div", {
|
|
407
414
|
className: "error-message"
|
|
408
|
-
}, error.message), /* @__PURE__ */
|
|
415
|
+
}, error.message), /* @__PURE__ */ React.createElement("h2", null, "Stack Trace"), /* @__PURE__ */ React.createElement("div", {
|
|
409
416
|
className: "stack-trace"
|
|
410
|
-
}, /* @__PURE__ */
|
|
417
|
+
}, /* @__PURE__ */ React.createElement("pre", null, stackLines.join("\n"))), /* @__PURE__ */ React.createElement("div", {
|
|
411
418
|
className: "meta"
|
|
412
|
-
}, /* @__PURE__ */
|
|
419
|
+
}, /* @__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
420
|
}
|
|
414
421
|
__name(ErrorPageDevelopment, "ErrorPageDevelopment");
|
|
422
|
+
|
|
423
|
+
// src/render/error-pages/error-page-production.tsx
|
|
415
424
|
function ErrorPageProduction() {
|
|
416
|
-
return /* @__PURE__ */
|
|
425
|
+
return /* @__PURE__ */ React.createElement("html", {
|
|
417
426
|
lang: "en"
|
|
418
|
-
}, /* @__PURE__ */
|
|
427
|
+
}, /* @__PURE__ */ React.createElement("head", null, /* @__PURE__ */ React.createElement("meta", {
|
|
419
428
|
charSet: "UTF-8"
|
|
420
|
-
}), /* @__PURE__ */
|
|
429
|
+
}), /* @__PURE__ */ React.createElement("meta", {
|
|
421
430
|
name: "viewport",
|
|
422
431
|
content: "width=device-width, initial-scale=1.0"
|
|
423
|
-
}), /* @__PURE__ */
|
|
432
|
+
}), /* @__PURE__ */ React.createElement("title", null, "Error"), /* @__PURE__ */ React.createElement("style", {
|
|
424
433
|
dangerouslySetInnerHTML: {
|
|
425
434
|
__html: `
|
|
426
435
|
body {
|
|
@@ -447,9 +456,9 @@ function ErrorPageProduction() {
|
|
|
447
456
|
}
|
|
448
457
|
`
|
|
449
458
|
}
|
|
450
|
-
})), /* @__PURE__ */
|
|
459
|
+
})), /* @__PURE__ */ React.createElement("body", null, /* @__PURE__ */ React.createElement("div", {
|
|
451
460
|
className: "error-container"
|
|
452
|
-
}, /* @__PURE__ */
|
|
461
|
+
}, /* @__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
462
|
}
|
|
454
463
|
__name(ErrorPageProduction, "ErrorPageProduction");
|
|
455
464
|
|
|
@@ -516,7 +525,7 @@ exports.StreamingErrorHandler = class _StreamingErrorHandler {
|
|
|
516
525
|
*/
|
|
517
526
|
renderDevelopmentErrorPage(error, viewPath, phase) {
|
|
518
527
|
const ErrorComponent = this.errorPageDevelopment || ErrorPageDevelopment;
|
|
519
|
-
const element =
|
|
528
|
+
const element = React2.createElement(ErrorComponent, {
|
|
520
529
|
error,
|
|
521
530
|
viewPath,
|
|
522
531
|
phase
|
|
@@ -528,7 +537,7 @@ exports.StreamingErrorHandler = class _StreamingErrorHandler {
|
|
|
528
537
|
*/
|
|
529
538
|
renderProductionErrorPage() {
|
|
530
539
|
const ErrorComponent = this.errorPageProduction || ErrorPageProduction;
|
|
531
|
-
const element =
|
|
540
|
+
const element = React2.createElement(ErrorComponent);
|
|
532
541
|
return "<!DOCTYPE html>\n" + server.renderToStaticMarkup(element);
|
|
533
542
|
}
|
|
534
543
|
/**
|
|
@@ -1093,11 +1102,13 @@ exports.RenderInterceptor = class RenderInterceptor {
|
|
|
1093
1102
|
renderService;
|
|
1094
1103
|
allowedHeaders;
|
|
1095
1104
|
allowedCookies;
|
|
1096
|
-
|
|
1105
|
+
contextFactory;
|
|
1106
|
+
constructor(reflector, renderService, allowedHeaders, allowedCookies, contextFactory) {
|
|
1097
1107
|
this.reflector = reflector;
|
|
1098
1108
|
this.renderService = renderService;
|
|
1099
1109
|
this.allowedHeaders = allowedHeaders;
|
|
1100
1110
|
this.allowedCookies = allowedCookies;
|
|
1111
|
+
this.contextFactory = contextFactory;
|
|
1101
1112
|
}
|
|
1102
1113
|
/**
|
|
1103
1114
|
* Resolve the layout hierarchy for a given route
|
|
@@ -1237,6 +1248,14 @@ exports.RenderInterceptor = class RenderInterceptor {
|
|
|
1237
1248
|
renderContext.cookies = cookies;
|
|
1238
1249
|
}
|
|
1239
1250
|
}
|
|
1251
|
+
if (this.contextFactory) {
|
|
1252
|
+
const customContext = await this.contextFactory({
|
|
1253
|
+
req: request
|
|
1254
|
+
});
|
|
1255
|
+
if (customContext) {
|
|
1256
|
+
Object.assign(renderContext, customContext);
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1240
1259
|
const renderResponse = isRenderResponse(data) ? data : {
|
|
1241
1260
|
props: data
|
|
1242
1261
|
};
|
|
@@ -1283,12 +1302,15 @@ exports.RenderInterceptor = _ts_decorate6([
|
|
|
1283
1302
|
_ts_param3(2, common.Inject("ALLOWED_HEADERS")),
|
|
1284
1303
|
_ts_param3(3, common.Optional()),
|
|
1285
1304
|
_ts_param3(3, common.Inject("ALLOWED_COOKIES")),
|
|
1305
|
+
_ts_param3(4, common.Optional()),
|
|
1306
|
+
_ts_param3(4, common.Inject("CONTEXT_FACTORY")),
|
|
1286
1307
|
_ts_metadata5("design:type", Function),
|
|
1287
1308
|
_ts_metadata5("design:paramtypes", [
|
|
1288
1309
|
typeof core.Reflector === "undefined" ? Object : core.Reflector,
|
|
1289
1310
|
typeof exports.RenderService === "undefined" ? Object : exports.RenderService,
|
|
1290
1311
|
Array,
|
|
1291
|
-
Array
|
|
1312
|
+
Array,
|
|
1313
|
+
typeof ContextFactory === "undefined" ? Object : ContextFactory
|
|
1292
1314
|
])
|
|
1293
1315
|
], exports.RenderInterceptor);
|
|
1294
1316
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
@@ -1532,6 +1554,12 @@ exports.RenderModule = class _RenderModule {
|
|
|
1532
1554
|
provide: "ALLOWED_COOKIES",
|
|
1533
1555
|
useValue: config?.allowedCookies || []
|
|
1534
1556
|
});
|
|
1557
|
+
if (config?.context) {
|
|
1558
|
+
providers.push({
|
|
1559
|
+
provide: "CONTEXT_FACTORY",
|
|
1560
|
+
useValue: config.context
|
|
1561
|
+
});
|
|
1562
|
+
}
|
|
1535
1563
|
return {
|
|
1536
1564
|
global: true,
|
|
1537
1565
|
module: _RenderModule,
|
|
@@ -1650,6 +1678,13 @@ exports.RenderModule = class _RenderModule {
|
|
|
1650
1678
|
inject: [
|
|
1651
1679
|
"RENDER_CONFIG"
|
|
1652
1680
|
]
|
|
1681
|
+
},
|
|
1682
|
+
{
|
|
1683
|
+
provide: "CONTEXT_FACTORY",
|
|
1684
|
+
useFactory: /* @__PURE__ */ __name((config) => config?.context, "useFactory"),
|
|
1685
|
+
inject: [
|
|
1686
|
+
"RENDER_CONFIG"
|
|
1687
|
+
]
|
|
1653
1688
|
}
|
|
1654
1689
|
];
|
|
1655
1690
|
return {
|
|
@@ -1703,7 +1738,7 @@ var CONTEXT_KEY = /* @__PURE__ */ Symbol.for("nestjs-ssr.PageContext");
|
|
|
1703
1738
|
var globalStore = globalThis;
|
|
1704
1739
|
function getOrCreateContext() {
|
|
1705
1740
|
if (!globalStore[CONTEXT_KEY]) {
|
|
1706
|
-
globalStore[CONTEXT_KEY] = /* @__PURE__ */
|
|
1741
|
+
globalStore[CONTEXT_KEY] = /* @__PURE__ */ React2.createContext(null);
|
|
1707
1742
|
}
|
|
1708
1743
|
return globalStore[CONTEXT_KEY];
|
|
1709
1744
|
}
|
|
@@ -1712,13 +1747,32 @@ var PageContext = getOrCreateContext();
|
|
|
1712
1747
|
function registerPageContextState(setter) {
|
|
1713
1748
|
}
|
|
1714
1749
|
__name(registerPageContextState, "registerPageContextState");
|
|
1750
|
+
var segmentSetters = /* @__PURE__ */ new Set();
|
|
1751
|
+
function registerSegmentSetter(setter) {
|
|
1752
|
+
segmentSetters.add(setter);
|
|
1753
|
+
}
|
|
1754
|
+
__name(registerSegmentSetter, "registerSegmentSetter");
|
|
1755
|
+
function unregisterSegmentSetter(setter) {
|
|
1756
|
+
segmentSetters.delete(setter);
|
|
1757
|
+
}
|
|
1758
|
+
__name(unregisterSegmentSetter, "unregisterSegmentSetter");
|
|
1759
|
+
function broadcastToSegments(context) {
|
|
1760
|
+
segmentSetters.forEach((setter) => setter(context));
|
|
1761
|
+
}
|
|
1762
|
+
__name(broadcastToSegments, "broadcastToSegments");
|
|
1715
1763
|
function PageContextProvider({ context: initialContext, children, isSegment = false }) {
|
|
1716
|
-
const [context, setContext] =
|
|
1717
|
-
|
|
1764
|
+
const [context, setContext] = React2.useState(initialContext);
|
|
1765
|
+
React2.useEffect(() => {
|
|
1766
|
+
if (!isSegment) {
|
|
1767
|
+
return void 0;
|
|
1768
|
+
} else {
|
|
1769
|
+
registerSegmentSetter(setContext);
|
|
1770
|
+
return () => unregisterSegmentSetter(setContext);
|
|
1771
|
+
}
|
|
1718
1772
|
}, [
|
|
1719
1773
|
isSegment
|
|
1720
1774
|
]);
|
|
1721
|
-
return /* @__PURE__ */
|
|
1775
|
+
return /* @__PURE__ */ React2__default.default.createElement(PageContext.Provider, {
|
|
1722
1776
|
value: context
|
|
1723
1777
|
}, children);
|
|
1724
1778
|
}
|
|
@@ -1730,7 +1784,7 @@ function createSSRHooks() {
|
|
|
1730
1784
|
* Contains URL metadata, headers, and any custom properties you've added.
|
|
1731
1785
|
*/
|
|
1732
1786
|
usePageContext: /* @__PURE__ */ __name(() => {
|
|
1733
|
-
const context =
|
|
1787
|
+
const context = React2.useContext(PageContext);
|
|
1734
1788
|
if (!context) {
|
|
1735
1789
|
throw new Error("usePageContext must be used within PageContextProvider");
|
|
1736
1790
|
}
|
|
@@ -1747,7 +1801,7 @@ function createSSRHooks() {
|
|
|
1747
1801
|
* ```
|
|
1748
1802
|
*/
|
|
1749
1803
|
useParams: /* @__PURE__ */ __name(() => {
|
|
1750
|
-
const context =
|
|
1804
|
+
const context = React2.useContext(PageContext);
|
|
1751
1805
|
if (!context) {
|
|
1752
1806
|
throw new Error("useParams must be used within PageContextProvider");
|
|
1753
1807
|
}
|
|
@@ -1765,7 +1819,7 @@ function createSSRHooks() {
|
|
|
1765
1819
|
* ```
|
|
1766
1820
|
*/
|
|
1767
1821
|
useQuery: /* @__PURE__ */ __name(() => {
|
|
1768
|
-
const context =
|
|
1822
|
+
const context = React2.useContext(PageContext);
|
|
1769
1823
|
if (!context) {
|
|
1770
1824
|
throw new Error("useQuery must be used within PageContextProvider");
|
|
1771
1825
|
}
|
|
@@ -1785,7 +1839,7 @@ function createSSRHooks() {
|
|
|
1785
1839
|
* ```
|
|
1786
1840
|
*/
|
|
1787
1841
|
useRequest: /* @__PURE__ */ __name(() => {
|
|
1788
|
-
const context =
|
|
1842
|
+
const context = React2.useContext(PageContext);
|
|
1789
1843
|
if (!context) {
|
|
1790
1844
|
throw new Error("useRequest must be used within PageContextProvider");
|
|
1791
1845
|
}
|
|
@@ -1811,7 +1865,7 @@ function createSSRHooks() {
|
|
|
1811
1865
|
* ```
|
|
1812
1866
|
*/
|
|
1813
1867
|
useHeaders: /* @__PURE__ */ __name(() => {
|
|
1814
|
-
const context =
|
|
1868
|
+
const context = React2.useContext(PageContext);
|
|
1815
1869
|
if (!context) {
|
|
1816
1870
|
throw new Error("useHeaders must be used within PageContextProvider");
|
|
1817
1871
|
}
|
|
@@ -1846,7 +1900,7 @@ function createSSRHooks() {
|
|
|
1846
1900
|
* ```
|
|
1847
1901
|
*/
|
|
1848
1902
|
useHeader: /* @__PURE__ */ __name((name) => {
|
|
1849
|
-
const context =
|
|
1903
|
+
const context = React2.useContext(PageContext);
|
|
1850
1904
|
if (!context) {
|
|
1851
1905
|
throw new Error("useHeader must be used within PageContextProvider");
|
|
1852
1906
|
}
|
|
@@ -1872,7 +1926,7 @@ function createSSRHooks() {
|
|
|
1872
1926
|
* ```
|
|
1873
1927
|
*/
|
|
1874
1928
|
useCookies: /* @__PURE__ */ __name(() => {
|
|
1875
|
-
const context =
|
|
1929
|
+
const context = React2.useContext(PageContext);
|
|
1876
1930
|
if (!context) {
|
|
1877
1931
|
throw new Error("useCookies must be used within PageContextProvider");
|
|
1878
1932
|
}
|
|
@@ -1894,7 +1948,7 @@ function createSSRHooks() {
|
|
|
1894
1948
|
* ```
|
|
1895
1949
|
*/
|
|
1896
1950
|
useCookie: /* @__PURE__ */ __name((name) => {
|
|
1897
|
-
const context =
|
|
1951
|
+
const context = React2.useContext(PageContext);
|
|
1898
1952
|
if (!context) {
|
|
1899
1953
|
throw new Error("useCookie must be used within PageContextProvider");
|
|
1900
1954
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Injectable, Logger, Optional, Inject, Global, Module, SetMetadata } from '@nestjs/common';
|
|
2
|
-
import { HttpAdapterHost, APP_INTERCEPTOR
|
|
2
|
+
import { Reflector, HttpAdapterHost, APP_INTERCEPTOR } from '@nestjs/core';
|
|
3
3
|
import { existsSync, readFileSync } from 'fs';
|
|
4
4
|
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;
|
|
@@ -308,9 +308,13 @@ var StringRenderer = class _StringRenderer {
|
|
|
308
308
|
throw new Error("Server bundle not found in manifest. Run `pnpm build:server` to generate the server bundle.");
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
|
-
const { data: pageData, __context: pageContext } = data;
|
|
311
|
+
const { data: pageData, __context: pageContext, __layouts: layouts } = data;
|
|
312
312
|
const html = await renderModule.renderSegment(viewComponent, data);
|
|
313
313
|
const componentName = viewComponent.displayName || viewComponent.name || "Component";
|
|
314
|
+
const layoutMetadata = layouts ? layouts.map((l) => ({
|
|
315
|
+
name: l.layout.displayName || l.layout.name || "default",
|
|
316
|
+
props: l.props
|
|
317
|
+
})) : [];
|
|
314
318
|
if (context.isDevelopment) {
|
|
315
319
|
const duration = Date.now() - startTime;
|
|
316
320
|
this.logger.log(`[SSR] ${componentName} segment rendered in ${duration}ms`);
|
|
@@ -321,7 +325,8 @@ var StringRenderer = class _StringRenderer {
|
|
|
321
325
|
props: pageData,
|
|
322
326
|
swapTarget,
|
|
323
327
|
componentName,
|
|
324
|
-
context: pageContext
|
|
328
|
+
context: pageContext,
|
|
329
|
+
layouts: layoutMetadata
|
|
325
330
|
};
|
|
326
331
|
}
|
|
327
332
|
};
|
|
@@ -332,6 +337,8 @@ StringRenderer = _ts_decorate2([
|
|
|
332
337
|
typeof TemplateParserService === "undefined" ? Object : TemplateParserService
|
|
333
338
|
])
|
|
334
339
|
], StringRenderer);
|
|
340
|
+
|
|
341
|
+
// src/render/error-pages/error-page-development.tsx
|
|
335
342
|
function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
336
343
|
const stackLines = error.stack ? error.stack.split("\n").slice(1) : [];
|
|
337
344
|
return /* @__PURE__ */ React.createElement("html", {
|
|
@@ -405,6 +412,8 @@ function ErrorPageDevelopment({ error, viewPath, phase }) {
|
|
|
405
412
|
}, /* @__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
413
|
}
|
|
407
414
|
__name(ErrorPageDevelopment, "ErrorPageDevelopment");
|
|
415
|
+
|
|
416
|
+
// src/render/error-pages/error-page-production.tsx
|
|
408
417
|
function ErrorPageProduction() {
|
|
409
418
|
return /* @__PURE__ */ React.createElement("html", {
|
|
410
419
|
lang: "en"
|
|
@@ -1086,11 +1095,13 @@ var RenderInterceptor = class {
|
|
|
1086
1095
|
renderService;
|
|
1087
1096
|
allowedHeaders;
|
|
1088
1097
|
allowedCookies;
|
|
1089
|
-
|
|
1098
|
+
contextFactory;
|
|
1099
|
+
constructor(reflector, renderService, allowedHeaders, allowedCookies, contextFactory) {
|
|
1090
1100
|
this.reflector = reflector;
|
|
1091
1101
|
this.renderService = renderService;
|
|
1092
1102
|
this.allowedHeaders = allowedHeaders;
|
|
1093
1103
|
this.allowedCookies = allowedCookies;
|
|
1104
|
+
this.contextFactory = contextFactory;
|
|
1094
1105
|
}
|
|
1095
1106
|
/**
|
|
1096
1107
|
* Resolve the layout hierarchy for a given route
|
|
@@ -1230,6 +1241,14 @@ var RenderInterceptor = class {
|
|
|
1230
1241
|
renderContext.cookies = cookies;
|
|
1231
1242
|
}
|
|
1232
1243
|
}
|
|
1244
|
+
if (this.contextFactory) {
|
|
1245
|
+
const customContext = await this.contextFactory({
|
|
1246
|
+
req: request
|
|
1247
|
+
});
|
|
1248
|
+
if (customContext) {
|
|
1249
|
+
Object.assign(renderContext, customContext);
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1233
1252
|
const renderResponse = isRenderResponse(data) ? data : {
|
|
1234
1253
|
props: data
|
|
1235
1254
|
};
|
|
@@ -1276,12 +1295,15 @@ RenderInterceptor = _ts_decorate6([
|
|
|
1276
1295
|
_ts_param3(2, Inject("ALLOWED_HEADERS")),
|
|
1277
1296
|
_ts_param3(3, Optional()),
|
|
1278
1297
|
_ts_param3(3, Inject("ALLOWED_COOKIES")),
|
|
1298
|
+
_ts_param3(4, Optional()),
|
|
1299
|
+
_ts_param3(4, Inject("CONTEXT_FACTORY")),
|
|
1279
1300
|
_ts_metadata5("design:type", Function),
|
|
1280
1301
|
_ts_metadata5("design:paramtypes", [
|
|
1281
1302
|
typeof Reflector === "undefined" ? Object : Reflector,
|
|
1282
1303
|
typeof RenderService === "undefined" ? Object : RenderService,
|
|
1283
1304
|
Array,
|
|
1284
|
-
Array
|
|
1305
|
+
Array,
|
|
1306
|
+
typeof ContextFactory === "undefined" ? Object : ContextFactory
|
|
1285
1307
|
])
|
|
1286
1308
|
], RenderInterceptor);
|
|
1287
1309
|
function _ts_decorate7(decorators, target, key, desc) {
|
|
@@ -1525,6 +1547,12 @@ var RenderModule = class _RenderModule {
|
|
|
1525
1547
|
provide: "ALLOWED_COOKIES",
|
|
1526
1548
|
useValue: config?.allowedCookies || []
|
|
1527
1549
|
});
|
|
1550
|
+
if (config?.context) {
|
|
1551
|
+
providers.push({
|
|
1552
|
+
provide: "CONTEXT_FACTORY",
|
|
1553
|
+
useValue: config.context
|
|
1554
|
+
});
|
|
1555
|
+
}
|
|
1528
1556
|
return {
|
|
1529
1557
|
global: true,
|
|
1530
1558
|
module: _RenderModule,
|
|
@@ -1643,6 +1671,13 @@ var RenderModule = class _RenderModule {
|
|
|
1643
1671
|
inject: [
|
|
1644
1672
|
"RENDER_CONFIG"
|
|
1645
1673
|
]
|
|
1674
|
+
},
|
|
1675
|
+
{
|
|
1676
|
+
provide: "CONTEXT_FACTORY",
|
|
1677
|
+
useFactory: /* @__PURE__ */ __name((config) => config?.context, "useFactory"),
|
|
1678
|
+
inject: [
|
|
1679
|
+
"RENDER_CONFIG"
|
|
1680
|
+
]
|
|
1646
1681
|
}
|
|
1647
1682
|
];
|
|
1648
1683
|
return {
|
|
@@ -1705,13 +1740,32 @@ var PageContext = getOrCreateContext();
|
|
|
1705
1740
|
function registerPageContextState(setter) {
|
|
1706
1741
|
}
|
|
1707
1742
|
__name(registerPageContextState, "registerPageContextState");
|
|
1743
|
+
var segmentSetters = /* @__PURE__ */ new Set();
|
|
1744
|
+
function registerSegmentSetter(setter) {
|
|
1745
|
+
segmentSetters.add(setter);
|
|
1746
|
+
}
|
|
1747
|
+
__name(registerSegmentSetter, "registerSegmentSetter");
|
|
1748
|
+
function unregisterSegmentSetter(setter) {
|
|
1749
|
+
segmentSetters.delete(setter);
|
|
1750
|
+
}
|
|
1751
|
+
__name(unregisterSegmentSetter, "unregisterSegmentSetter");
|
|
1752
|
+
function broadcastToSegments(context) {
|
|
1753
|
+
segmentSetters.forEach((setter) => setter(context));
|
|
1754
|
+
}
|
|
1755
|
+
__name(broadcastToSegments, "broadcastToSegments");
|
|
1708
1756
|
function PageContextProvider({ context: initialContext, children, isSegment = false }) {
|
|
1709
1757
|
const [context, setContext] = useState(initialContext);
|
|
1710
1758
|
useEffect(() => {
|
|
1759
|
+
if (!isSegment) {
|
|
1760
|
+
return void 0;
|
|
1761
|
+
} else {
|
|
1762
|
+
registerSegmentSetter(setContext);
|
|
1763
|
+
return () => unregisterSegmentSetter(setContext);
|
|
1764
|
+
}
|
|
1711
1765
|
}, [
|
|
1712
1766
|
isSegment
|
|
1713
1767
|
]);
|
|
1714
|
-
return /* @__PURE__ */
|
|
1768
|
+
return /* @__PURE__ */ React2.createElement(PageContext.Provider, {
|
|
1715
1769
|
value: context
|
|
1716
1770
|
}, children);
|
|
1717
1771
|
}
|
package/dist/render/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { E as ErrorPageDevelopment, e as ErrorPageProduction, b as RenderInterceptor, R as RenderModule, a as RenderService, S as StreamingErrorHandler, T as TemplateParserService } from '../index-
|
|
1
|
+
export { E as ErrorPageDevelopment, e as ErrorPageProduction, b as RenderInterceptor, R as RenderModule, a as RenderService, S as StreamingErrorHandler, T as TemplateParserService } from '../index-CiYcz-1T.mjs';
|
|
2
2
|
import '@nestjs/common';
|
|
3
3
|
import 'react';
|
|
4
|
-
import '../render-response.interface-CxbuKGnV.mjs';
|
|
5
|
-
import 'vite';
|
|
6
4
|
import 'express';
|
|
5
|
+
import '../render-response.interface-ClWJXKL4.mjs';
|
|
6
|
+
import 'vite';
|
|
7
7
|
import '@nestjs/core';
|
|
8
8
|
import 'rxjs';
|
|
9
9
|
import 'react/jsx-runtime';
|
package/dist/render/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export { E as ErrorPageDevelopment, e as ErrorPageProduction, b as RenderInterceptor, R as RenderModule, a as RenderService, S as StreamingErrorHandler, T as TemplateParserService } from '../index-
|
|
1
|
+
export { E as ErrorPageDevelopment, e as ErrorPageProduction, b as RenderInterceptor, R as RenderModule, a as RenderService, S as StreamingErrorHandler, T as TemplateParserService } from '../index-Dq2qZSge.js';
|
|
2
2
|
import '@nestjs/common';
|
|
3
3
|
import 'react';
|
|
4
|
-
import '../render-response.interface-CxbuKGnV.js';
|
|
5
|
-
import 'vite';
|
|
6
4
|
import 'express';
|
|
5
|
+
import '../render-response.interface-ClWJXKL4.js';
|
|
6
|
+
import 'vite';
|
|
7
7
|
import '@nestjs/core';
|
|
8
8
|
import 'rxjs';
|
|
9
9
|
import 'react/jsx-runtime';
|