@tramvai/module-render 1.84.0 → 1.89.1
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/lib/browser.js +28 -20
- package/lib/client/index.d.ts +3 -1
- package/lib/react/index.d.ts +2 -1
- package/lib/server.es.js +28 -34
- package/lib/server.js +34 -41
- package/lib/test/unit/resources.d.ts +1 -1
- package/package.json +16 -18
package/lib/browser.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
2
|
import { Module, provide, commandLineListTokens, DI_TOKEN } from '@tramvai/core';
|
|
3
|
-
import { STORE_TOKEN, LOGGER_TOKEN, CONTEXT_TOKEN } from '@tramvai/
|
|
3
|
+
import { COMBINE_REDUCERS, STORE_TOKEN, LOGGER_TOKEN, CONTEXT_TOKEN, INITIAL_APP_STATE_TOKEN } from '@tramvai/tokens-common';
|
|
4
4
|
import { DEFAULT_LAYOUT_COMPONENT, LAYOUT_OPTIONS, DEFAULT_FOOTER_COMPONENT, DEFAULT_HEADER_COMPONENT, TRAMVAI_RENDER_MODE, RESOURCES_REGISTRY, CUSTOM_RENDER, EXTEND_RENDER, RENDERER_CALLBACK, USE_REACT_STRICT_MODE, RENDER_MODE } from '@tramvai/tokens-render';
|
|
5
5
|
export * from '@tramvai/tokens-render';
|
|
6
6
|
import { ROUTER_TOKEN, PAGE_SERVICE_TOKEN } from '@tramvai/tokens-router';
|
|
7
7
|
import each from '@tinkoff/utils/array/each';
|
|
8
|
-
import
|
|
8
|
+
import { PureComponent, useMemo, createElement, StrictMode } from 'react';
|
|
9
|
+
import { jsx } from 'react/jsx-runtime';
|
|
9
10
|
import { createEvent, createReducer, useStore, Provider } from '@tramvai/state';
|
|
10
11
|
import { useDi, ERROR_BOUNDARY_TOKEN, ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN, UniversalErrorBoundary, DIContext } from '@tramvai/react';
|
|
11
12
|
import { useRoute, useUrl } from '@tramvai/module-router';
|
|
12
13
|
import { useIsomorphicLayoutEffect } from '@tinkoff/react-hooks';
|
|
13
14
|
import { composeLayoutOptions, createLayout } from '@tinkoff/layout-factory';
|
|
14
|
-
import { COMBINE_REDUCERS } from '@tramvai/tokens-common';
|
|
15
15
|
|
|
16
16
|
function serializeError(error) {
|
|
17
17
|
return {
|
|
@@ -38,14 +38,12 @@ const PageErrorBoundary = (props) => {
|
|
|
38
38
|
}, [serializedError]);
|
|
39
39
|
const errorHandlers = useDi({ token: ERROR_BOUNDARY_TOKEN, optional: true });
|
|
40
40
|
const fallbackFromDi = useDi({ token: ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN, optional: true });
|
|
41
|
-
return (
|
|
41
|
+
return (jsx(UniversalErrorBoundary, Object.assign({ url: url, error: error, errorHandlers: errorHandlers, fallback: fallback, fallbackFromDi: fallbackFromDi }, { children: children }), void 0));
|
|
42
42
|
};
|
|
43
43
|
class RootComponent extends PureComponent {
|
|
44
44
|
render() {
|
|
45
45
|
const { LayoutComponent, PageComponent, HeaderComponent, FooterComponent, ErrorBoundaryComponent, } = this.props;
|
|
46
|
-
return (
|
|
47
|
-
React.createElement(PageErrorBoundary, { fallback: ErrorBoundaryComponent },
|
|
48
|
-
React.createElement(PageComponent, null))));
|
|
46
|
+
return (jsx(LayoutComponent, Object.assign({ Header: HeaderComponent, Footer: FooterComponent }, { children: jsx(PageErrorBoundary, Object.assign({ fallback: ErrorBoundaryComponent }, { children: jsx(PageComponent, {}, void 0) }), void 0) }), void 0));
|
|
49
47
|
}
|
|
50
48
|
}
|
|
51
49
|
const Root = ({ pageService }) => {
|
|
@@ -63,35 +61,44 @@ const Root = ({ pageService }) => {
|
|
|
63
61
|
const HeaderComponent = pageService.resolveComponentFromConfig('header');
|
|
64
62
|
const FooterComponent = pageService.resolveComponentFromConfig('footer');
|
|
65
63
|
const ErrorBoundaryComponent = pageService.resolveComponentFromConfig('errorBoundary');
|
|
66
|
-
return (
|
|
64
|
+
return (jsx(RootComponent, { HeaderComponent: HeaderComponent, FooterComponent: FooterComponent, LayoutComponent: LayoutComponent, PageComponent: PageComponent, ErrorBoundaryComponent: ErrorBoundaryComponent }, void 0));
|
|
67
65
|
};
|
|
68
66
|
|
|
69
|
-
function renderReact({ pageService, di }, context) {
|
|
70
|
-
return (
|
|
71
|
-
React.createElement(DIContext.Provider, { value: di },
|
|
72
|
-
React.createElement(Root, { pageService: pageService }))));
|
|
67
|
+
function renderReact({ pageService, di, initialState }, context) {
|
|
68
|
+
return (jsx(Provider, Object.assign({ context: context, serverState: initialState === null || initialState === void 0 ? void 0 : initialState.stores }, { children: jsx(DIContext.Provider, Object.assign({ value: di }, { children: jsx(Root, { pageService: pageService }, void 0) }), void 0) }), void 0));
|
|
73
69
|
}
|
|
74
70
|
|
|
75
|
-
|
|
71
|
+
let hydrateRoot;
|
|
72
|
+
try {
|
|
73
|
+
// eslint-disable-next-line import/no-unresolved, import/extensions
|
|
74
|
+
hydrateRoot = require('react-dom/client').hydrateRoot;
|
|
75
|
+
}
|
|
76
|
+
catch { }
|
|
77
|
+
const ExecuteRenderCallback = ({ children, callback, }) => {
|
|
76
78
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
77
79
|
useIsomorphicLayoutEffect(callback, []);
|
|
78
80
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
79
81
|
return children;
|
|
80
82
|
};
|
|
81
|
-
const renderer = ({ element, container, callback }) => {
|
|
82
|
-
if (process.env.__TRAMVAI_CONCURRENT_FEATURES) {
|
|
83
|
+
const renderer = ({ element, container, callback, log }) => {
|
|
84
|
+
if (process.env.__TRAMVAI_CONCURRENT_FEATURES !== 'false' && typeof hydrateRoot === 'function') {
|
|
83
85
|
const wrappedElement = createElement(ExecuteRenderCallback, { callback }, element);
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
return hydrateRoot(container, wrappedElement, {
|
|
87
|
+
onRecoverableError: (error) => {
|
|
88
|
+
log.error({
|
|
89
|
+
error,
|
|
90
|
+
event: 'hydrate:recover-after-error',
|
|
91
|
+
});
|
|
92
|
+
},
|
|
93
|
+
});
|
|
87
94
|
}
|
|
88
95
|
const { hydrate } = require('react-dom');
|
|
89
96
|
return hydrate(element, container, callback);
|
|
90
97
|
};
|
|
91
98
|
|
|
92
|
-
function rendering({ pageService, log, consumerContext, customRender, extendRender, di, useStrictMode, rendererCallback, }) {
|
|
99
|
+
function rendering({ pageService, log, consumerContext, customRender, extendRender, di, useStrictMode, rendererCallback, initialState, }) {
|
|
93
100
|
return new Promise((resolve, reject) => {
|
|
94
|
-
let renderResult = renderReact({ pageService, di }, consumerContext);
|
|
101
|
+
let renderResult = renderReact({ pageService, di, initialState }, consumerContext);
|
|
95
102
|
if (extendRender) {
|
|
96
103
|
each((render) => {
|
|
97
104
|
renderResult = render(renderResult);
|
|
@@ -245,6 +252,7 @@ RenderModule = RenderModule_1 = __decorate([
|
|
|
245
252
|
consumerContext: CONTEXT_TOKEN,
|
|
246
253
|
di: DI_TOKEN,
|
|
247
254
|
useStrictMode: USE_REACT_STRICT_MODE,
|
|
255
|
+
initialState: INITIAL_APP_STATE_TOKEN,
|
|
248
256
|
},
|
|
249
257
|
multi: true,
|
|
250
258
|
}),
|
package/lib/client/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { EXTEND_RENDER, RENDERER_CALLBACK, USE_REACT_STRICT_MODE } from '@tramvai/tokens-render';
|
|
2
2
|
import type { PAGE_SERVICE_TOKEN } from '@tramvai/tokens-router';
|
|
3
|
-
|
|
3
|
+
import type { INITIAL_APP_STATE_TOKEN } from '@tramvai/tokens-common';
|
|
4
|
+
export declare function rendering({ pageService, log, consumerContext, customRender, extendRender, di, useStrictMode, rendererCallback, initialState, }: {
|
|
4
5
|
pageService: typeof PAGE_SERVICE_TOKEN;
|
|
5
6
|
log: any;
|
|
6
7
|
consumerContext: any;
|
|
@@ -9,4 +10,5 @@ export declare function rendering({ pageService, log, consumerContext, customRen
|
|
|
9
10
|
di: any;
|
|
10
11
|
useStrictMode: typeof USE_REACT_STRICT_MODE;
|
|
11
12
|
rendererCallback?: typeof RENDERER_CALLBACK;
|
|
13
|
+
initialState?: typeof INITIAL_APP_STATE_TOKEN;
|
|
12
14
|
}): Promise<void>;
|
package/lib/react/index.d.ts
CHANGED
package/lib/server.es.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __decorate } from 'tslib';
|
|
2
|
-
import
|
|
2
|
+
import { PureComponent, useMemo, createElement } from 'react';
|
|
3
3
|
import { renderToString } from 'react-dom/server';
|
|
4
4
|
import { Module, provide, commandLineListTokens, DI_TOKEN } from '@tramvai/core';
|
|
5
5
|
import { CREATE_CACHE_TOKEN, LOGGER_TOKEN, REQUEST_MANAGER_TOKEN, RESPONSE_MANAGER_TOKEN, CONTEXT_TOKEN } from '@tramvai/module-common';
|
|
@@ -8,7 +8,7 @@ import { ClientHintsModule, USER_AGENT_TOKEN } from '@tramvai/module-client-hint
|
|
|
8
8
|
import { ResourceType, ResourceSlot, DEFAULT_LAYOUT_COMPONENT, LAYOUT_OPTIONS, DEFAULT_FOOTER_COMPONENT, DEFAULT_HEADER_COMPONENT, TRAMVAI_RENDER_MODE, RESOURCES_REGISTRY, RESOURCE_INLINE_OPTIONS, RENDER_SLOTS, POLYFILL_CONDITION, HTML_ATTRS, CUSTOM_RENDER, EXTEND_RENDER } from '@tramvai/tokens-render';
|
|
9
9
|
export * from '@tramvai/tokens-render';
|
|
10
10
|
import { createToken, Scope } from '@tinkoff/dippy';
|
|
11
|
-
import {
|
|
11
|
+
import { WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN } from '@tramvai/tokens-server-private';
|
|
12
12
|
import { useDi, ERROR_BOUNDARY_TOKEN, ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN, UniversalErrorBoundary, DIContext, ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN } from '@tramvai/react';
|
|
13
13
|
import { resolve, isAbsoluteUrl as isAbsoluteUrl$1, parse } from '@tinkoff/url';
|
|
14
14
|
import { satisfies } from '@tinkoff/user-agent';
|
|
@@ -29,6 +29,7 @@ import * as path from 'path';
|
|
|
29
29
|
import each from '@tinkoff/utils/array/each';
|
|
30
30
|
import path$1 from '@tinkoff/utils/object/path';
|
|
31
31
|
import { o as onload } from './server_inline.inline.es.js';
|
|
32
|
+
import { jsx } from 'react/jsx-runtime';
|
|
32
33
|
import { createEvent, createReducer, useStore, Provider } from '@tramvai/state';
|
|
33
34
|
import { useRoute, useUrl } from '@tramvai/module-router';
|
|
34
35
|
import { composeLayoutOptions, createLayout } from '@tinkoff/layout-factory';
|
|
@@ -625,14 +626,12 @@ const PageErrorBoundary = (props) => {
|
|
|
625
626
|
}, [serializedError]);
|
|
626
627
|
const errorHandlers = useDi({ token: ERROR_BOUNDARY_TOKEN, optional: true });
|
|
627
628
|
const fallbackFromDi = useDi({ token: ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN, optional: true });
|
|
628
|
-
return (
|
|
629
|
+
return (jsx(UniversalErrorBoundary, Object.assign({ url: url, error: error, errorHandlers: errorHandlers, fallback: fallback, fallbackFromDi: fallbackFromDi }, { children: children }), void 0));
|
|
629
630
|
};
|
|
630
631
|
class RootComponent extends PureComponent {
|
|
631
632
|
render() {
|
|
632
633
|
const { LayoutComponent, PageComponent, HeaderComponent, FooterComponent, ErrorBoundaryComponent, } = this.props;
|
|
633
|
-
return (
|
|
634
|
-
React.createElement(PageErrorBoundary, { fallback: ErrorBoundaryComponent },
|
|
635
|
-
React.createElement(PageComponent, null))));
|
|
634
|
+
return (jsx(LayoutComponent, Object.assign({ Header: HeaderComponent, Footer: FooterComponent }, { children: jsx(PageErrorBoundary, Object.assign({ fallback: ErrorBoundaryComponent }, { children: jsx(PageComponent, {}, void 0) }), void 0) }), void 0));
|
|
636
635
|
}
|
|
637
636
|
}
|
|
638
637
|
const Root = ({ pageService }) => {
|
|
@@ -650,13 +649,11 @@ const Root = ({ pageService }) => {
|
|
|
650
649
|
const HeaderComponent = pageService.resolveComponentFromConfig('header');
|
|
651
650
|
const FooterComponent = pageService.resolveComponentFromConfig('footer');
|
|
652
651
|
const ErrorBoundaryComponent = pageService.resolveComponentFromConfig('errorBoundary');
|
|
653
|
-
return (
|
|
652
|
+
return (jsx(RootComponent, { HeaderComponent: HeaderComponent, FooterComponent: FooterComponent, LayoutComponent: LayoutComponent, PageComponent: PageComponent, ErrorBoundaryComponent: ErrorBoundaryComponent }, void 0));
|
|
654
653
|
};
|
|
655
654
|
|
|
656
|
-
function renderReact({ pageService, di }, context) {
|
|
657
|
-
return (
|
|
658
|
-
React.createElement(DIContext.Provider, { value: di },
|
|
659
|
-
React.createElement(Root, { pageService: pageService }))));
|
|
655
|
+
function renderReact({ pageService, di, initialState }, context) {
|
|
656
|
+
return (jsx(Provider, Object.assign({ context: context, serverState: initialState === null || initialState === void 0 ? void 0 : initialState.stores }, { children: jsx(DIContext.Provider, Object.assign({ value: di }, { children: jsx(Root, { pageService: pageService }, void 0) }), void 0) }), void 0));
|
|
660
657
|
}
|
|
661
658
|
|
|
662
659
|
class ReactRenderServer {
|
|
@@ -669,7 +666,7 @@ class ReactRenderServer {
|
|
|
669
666
|
}
|
|
670
667
|
render(extractor) {
|
|
671
668
|
var _a;
|
|
672
|
-
let renderResult = renderReact({ pageService: this.pageService, di: this.di }, this.context);
|
|
669
|
+
let renderResult = renderReact({ pageService: this.pageService, di: this.di, initialState: null }, this.context);
|
|
673
670
|
each((render) => {
|
|
674
671
|
renderResult = render(renderResult);
|
|
675
672
|
}, (_a = this.extendRender) !== null && _a !== void 0 ? _a : []);
|
|
@@ -884,30 +881,27 @@ RenderModule = RenderModule_1 = __decorate([
|
|
|
884
881
|
},
|
|
885
882
|
}),
|
|
886
883
|
provide({
|
|
887
|
-
provide:
|
|
884
|
+
provide: WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN,
|
|
888
885
|
multi: true,
|
|
889
|
-
useFactory: ({ RootErrorBoundary, logger }) => {
|
|
886
|
+
useFactory: ({ RootErrorBoundary, logger, }) => {
|
|
890
887
|
const log = logger('module-render:error-handler');
|
|
891
|
-
return (
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
return next(err);
|
|
909
|
-
}
|
|
910
|
-
});
|
|
888
|
+
return (error, request, reply) => {
|
|
889
|
+
if (!RootErrorBoundary) {
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
let body;
|
|
893
|
+
try {
|
|
894
|
+
log.info({ event: 'render-root-boundary' });
|
|
895
|
+
body = renderToString(createElement(RootErrorBoundary, { error, url: parse(request.url) }));
|
|
896
|
+
reply.status(error.httpStatus || error.status || 500);
|
|
897
|
+
reply.header('Content-Type', 'text/html; charset=utf-8');
|
|
898
|
+
reply.header('Content-Length', Buffer.byteLength(body, 'utf8'));
|
|
899
|
+
reply.header('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
900
|
+
return body;
|
|
901
|
+
}
|
|
902
|
+
catch (e) {
|
|
903
|
+
log.warn({ event: 'render-root-boundary-error', error: e });
|
|
904
|
+
}
|
|
911
905
|
};
|
|
912
906
|
},
|
|
913
907
|
deps: {
|
package/lib/server.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var tslib = require('tslib');
|
|
6
|
-
var
|
|
6
|
+
var react = require('react');
|
|
7
7
|
var server$1 = require('react-dom/server');
|
|
8
8
|
var core = require('@tramvai/core');
|
|
9
9
|
var moduleCommon = require('@tramvai/module-common');
|
|
@@ -11,8 +11,8 @@ var tokensRouter = require('@tramvai/tokens-router');
|
|
|
11
11
|
var moduleClientHints = require('@tramvai/module-client-hints');
|
|
12
12
|
var tokensRender = require('@tramvai/tokens-render');
|
|
13
13
|
var dippy = require('@tinkoff/dippy');
|
|
14
|
-
var
|
|
15
|
-
var react = require('@tramvai/react');
|
|
14
|
+
var tokensServerPrivate = require('@tramvai/tokens-server-private');
|
|
15
|
+
var react$1 = require('@tramvai/react');
|
|
16
16
|
var url = require('@tinkoff/url');
|
|
17
17
|
var userAgent = require('@tinkoff/user-agent');
|
|
18
18
|
var isUndefined = require('@tinkoff/utils/is/undefined');
|
|
@@ -32,6 +32,7 @@ var path = require('path');
|
|
|
32
32
|
var each = require('@tinkoff/utils/array/each');
|
|
33
33
|
var path$1 = require('@tinkoff/utils/object/path');
|
|
34
34
|
var inline_inline = require('./server_inline.inline.js');
|
|
35
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
35
36
|
var state = require('@tramvai/state');
|
|
36
37
|
var moduleRouter = require('@tramvai/module-router');
|
|
37
38
|
var layoutFactory = require('@tinkoff/layout-factory');
|
|
@@ -57,7 +58,6 @@ function _interopNamespace(e) {
|
|
|
57
58
|
return n;
|
|
58
59
|
}
|
|
59
60
|
|
|
60
|
-
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
61
61
|
var isUndefined__default = /*#__PURE__*/_interopDefaultLegacy(isUndefined);
|
|
62
62
|
var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
|
|
63
63
|
var fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
@@ -657,19 +657,17 @@ const PageErrorBoundary = (props) => {
|
|
|
657
657
|
const { children, fallback } = props;
|
|
658
658
|
const url = moduleRouter.useUrl();
|
|
659
659
|
const serializedError = state.useStore(PageErrorStore);
|
|
660
|
-
const error =
|
|
660
|
+
const error = react.useMemo(() => {
|
|
661
661
|
return serializedError && deserializeError(serializedError);
|
|
662
662
|
}, [serializedError]);
|
|
663
|
-
const errorHandlers = react.useDi({ token: react.ERROR_BOUNDARY_TOKEN, optional: true });
|
|
664
|
-
const fallbackFromDi = react.useDi({ token: react.ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN, optional: true });
|
|
665
|
-
return (
|
|
663
|
+
const errorHandlers = react$1.useDi({ token: react$1.ERROR_BOUNDARY_TOKEN, optional: true });
|
|
664
|
+
const fallbackFromDi = react$1.useDi({ token: react$1.ERROR_BOUNDARY_FALLBACK_COMPONENT_TOKEN, optional: true });
|
|
665
|
+
return (jsxRuntime.jsx(react$1.UniversalErrorBoundary, Object.assign({ url: url, error: error, errorHandlers: errorHandlers, fallback: fallback, fallbackFromDi: fallbackFromDi }, { children: children }), void 0));
|
|
666
666
|
};
|
|
667
|
-
class RootComponent extends
|
|
667
|
+
class RootComponent extends react.PureComponent {
|
|
668
668
|
render() {
|
|
669
669
|
const { LayoutComponent, PageComponent, HeaderComponent, FooterComponent, ErrorBoundaryComponent, } = this.props;
|
|
670
|
-
return (
|
|
671
|
-
React__default["default"].createElement(PageErrorBoundary, { fallback: ErrorBoundaryComponent },
|
|
672
|
-
React__default["default"].createElement(PageComponent, null))));
|
|
670
|
+
return (jsxRuntime.jsx(LayoutComponent, Object.assign({ Header: HeaderComponent, Footer: FooterComponent }, { children: jsxRuntime.jsx(PageErrorBoundary, Object.assign({ fallback: ErrorBoundaryComponent }, { children: jsxRuntime.jsx(PageComponent, {}, void 0) }), void 0) }), void 0));
|
|
673
671
|
}
|
|
674
672
|
}
|
|
675
673
|
const Root = ({ pageService }) => {
|
|
@@ -687,13 +685,11 @@ const Root = ({ pageService }) => {
|
|
|
687
685
|
const HeaderComponent = pageService.resolveComponentFromConfig('header');
|
|
688
686
|
const FooterComponent = pageService.resolveComponentFromConfig('footer');
|
|
689
687
|
const ErrorBoundaryComponent = pageService.resolveComponentFromConfig('errorBoundary');
|
|
690
|
-
return (
|
|
688
|
+
return (jsxRuntime.jsx(RootComponent, { HeaderComponent: HeaderComponent, FooterComponent: FooterComponent, LayoutComponent: LayoutComponent, PageComponent: PageComponent, ErrorBoundaryComponent: ErrorBoundaryComponent }, void 0));
|
|
691
689
|
};
|
|
692
690
|
|
|
693
|
-
function renderReact({ pageService, di }, context) {
|
|
694
|
-
return (
|
|
695
|
-
React__default["default"].createElement(react.DIContext.Provider, { value: di },
|
|
696
|
-
React__default["default"].createElement(Root, { pageService: pageService }))));
|
|
691
|
+
function renderReact({ pageService, di, initialState }, context) {
|
|
692
|
+
return (jsxRuntime.jsx(state.Provider, Object.assign({ context: context, serverState: initialState === null || initialState === void 0 ? void 0 : initialState.stores }, { children: jsxRuntime.jsx(react$1.DIContext.Provider, Object.assign({ value: di }, { children: jsxRuntime.jsx(Root, { pageService: pageService }, void 0) }), void 0) }), void 0));
|
|
697
693
|
}
|
|
698
694
|
|
|
699
695
|
class ReactRenderServer {
|
|
@@ -706,7 +702,7 @@ class ReactRenderServer {
|
|
|
706
702
|
}
|
|
707
703
|
render(extractor) {
|
|
708
704
|
var _a;
|
|
709
|
-
let renderResult = renderReact({ pageService: this.pageService, di: this.di }, this.context);
|
|
705
|
+
let renderResult = renderReact({ pageService: this.pageService, di: this.di, initialState: null }, this.context);
|
|
710
706
|
each__default["default"]((render) => {
|
|
711
707
|
renderResult = render(renderResult);
|
|
712
708
|
}, (_a = this.extendRender) !== null && _a !== void 0 ? _a : []);
|
|
@@ -921,34 +917,31 @@ exports.RenderModule = RenderModule_1 = tslib.__decorate([
|
|
|
921
917
|
},
|
|
922
918
|
}),
|
|
923
919
|
core.provide({
|
|
924
|
-
provide:
|
|
920
|
+
provide: tokensServerPrivate.WEB_FASTIFY_APP_BEFORE_ERROR_TOKEN,
|
|
925
921
|
multi: true,
|
|
926
|
-
useFactory: ({ RootErrorBoundary, logger }) => {
|
|
922
|
+
useFactory: ({ RootErrorBoundary, logger, }) => {
|
|
927
923
|
const log = logger('module-render:error-handler');
|
|
928
|
-
return (
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
return next(err);
|
|
946
|
-
}
|
|
947
|
-
});
|
|
924
|
+
return (error, request, reply) => {
|
|
925
|
+
if (!RootErrorBoundary) {
|
|
926
|
+
return;
|
|
927
|
+
}
|
|
928
|
+
let body;
|
|
929
|
+
try {
|
|
930
|
+
log.info({ event: 'render-root-boundary' });
|
|
931
|
+
body = server$1.renderToString(react.createElement(RootErrorBoundary, { error, url: url.parse(request.url) }));
|
|
932
|
+
reply.status(error.httpStatus || error.status || 500);
|
|
933
|
+
reply.header('Content-Type', 'text/html; charset=utf-8');
|
|
934
|
+
reply.header('Content-Length', Buffer.byteLength(body, 'utf8'));
|
|
935
|
+
reply.header('Cache-Control', 'no-cache, no-store, must-revalidate');
|
|
936
|
+
return body;
|
|
937
|
+
}
|
|
938
|
+
catch (e) {
|
|
939
|
+
log.warn({ event: 'render-root-boundary-error', error: e });
|
|
940
|
+
}
|
|
948
941
|
};
|
|
949
942
|
},
|
|
950
943
|
deps: {
|
|
951
|
-
RootErrorBoundary: { token: react.ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN, optional: true },
|
|
944
|
+
RootErrorBoundary: { token: react$1.ROOT_ERROR_BOUNDARY_COMPONENT_TOKEN, optional: true },
|
|
952
945
|
logger: moduleCommon.LOGGER_TOKEN,
|
|
953
946
|
},
|
|
954
947
|
}),
|
|
@@ -3,8 +3,8 @@ declare type Options = Parameters<typeof getDiWrapper>[0];
|
|
|
3
3
|
export declare const testPageResources: (options: Options) => {
|
|
4
4
|
render: () => {
|
|
5
5
|
parsed: import("node-html-parser").HTMLElement;
|
|
6
|
-
head: string;
|
|
7
6
|
body: string;
|
|
7
|
+
head: string;
|
|
8
8
|
application: string;
|
|
9
9
|
};
|
|
10
10
|
di: import("@tinkoff/dippy").Container;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-render",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.89.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"browser": "lib/browser.js",
|
|
6
6
|
"main": "lib/server.js",
|
|
@@ -24,13 +24,13 @@
|
|
|
24
24
|
"@tinkoff/htmlpagebuilder": "0.4.22",
|
|
25
25
|
"@tinkoff/layout-factory": "0.2.28",
|
|
26
26
|
"@tinkoff/url": "0.7.37",
|
|
27
|
-
"@tinkoff/user-agent": "0.3.
|
|
28
|
-
"@tramvai/module-client-hints": "1.
|
|
29
|
-
"@tramvai/module-router": "1.
|
|
30
|
-
"@tramvai/react": "1.
|
|
27
|
+
"@tinkoff/user-agent": "0.3.300",
|
|
28
|
+
"@tramvai/module-client-hints": "1.89.1",
|
|
29
|
+
"@tramvai/module-router": "1.89.1",
|
|
30
|
+
"@tramvai/react": "1.89.1",
|
|
31
31
|
"@tramvai/safe-strings": "0.4.3",
|
|
32
|
-
"@tramvai/tokens-render": "1.
|
|
33
|
-
"@tramvai/experiments": "1.
|
|
32
|
+
"@tramvai/tokens-render": "1.89.1",
|
|
33
|
+
"@tramvai/experiments": "1.89.1",
|
|
34
34
|
"@types/loadable__server": "^5.12.6",
|
|
35
35
|
"node-fetch": "^2.6.1"
|
|
36
36
|
},
|
|
@@ -38,23 +38,21 @@
|
|
|
38
38
|
"@tinkoff/dippy": "0.7.39",
|
|
39
39
|
"@tinkoff/utils": "^2.1.2",
|
|
40
40
|
"@tinkoff/react-hooks": "0.0.24",
|
|
41
|
-
"@tramvai/cli": "1.
|
|
42
|
-
"@tramvai/core": "1.
|
|
43
|
-
"@tramvai/module-common": "1.
|
|
44
|
-
"@tramvai/state": "1.
|
|
45
|
-
"@tramvai/test-helpers": "1.
|
|
46
|
-
"@tramvai/tokens-common": "1.
|
|
47
|
-
"@tramvai/tokens-router": "1.
|
|
48
|
-
"@tramvai/tokens-server": "1.
|
|
41
|
+
"@tramvai/cli": "1.89.1",
|
|
42
|
+
"@tramvai/core": "1.89.1",
|
|
43
|
+
"@tramvai/module-common": "1.89.1",
|
|
44
|
+
"@tramvai/state": "1.89.1",
|
|
45
|
+
"@tramvai/test-helpers": "1.89.1",
|
|
46
|
+
"@tramvai/tokens-common": "1.89.1",
|
|
47
|
+
"@tramvai/tokens-router": "1.89.1",
|
|
48
|
+
"@tramvai/tokens-server-private": "1.89.1",
|
|
49
49
|
"express": "^4.17.1",
|
|
50
50
|
"prop-types": "^15.6.2",
|
|
51
51
|
"react": ">=16.8.0",
|
|
52
52
|
"react-dom": ">=16.8.0",
|
|
53
53
|
"tslib": "^2.0.3"
|
|
54
54
|
},
|
|
55
|
-
"devDependencies": {
|
|
56
|
-
"@types/express": "^4.17.9"
|
|
57
|
-
},
|
|
55
|
+
"devDependencies": {},
|
|
58
56
|
"gitHead": "8e826a214c87b188fc4d254cdd8f2a2b2c55f3a8",
|
|
59
57
|
"module": "lib/server.es.js",
|
|
60
58
|
"license": "Apache-2.0"
|