@tramvai/module-render 1.71.0 → 1.72.2
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/server/PageBuilder.d.ts +2 -3
- package/lib/server.es.js +36 -10
- package/lib/server.js +35 -9
- package/package.json +15 -15
|
@@ -8,9 +8,8 @@ export declare class PageBuilder {
|
|
|
8
8
|
private reactRender;
|
|
9
9
|
private htmlAttrs;
|
|
10
10
|
private polyfillCondition;
|
|
11
|
-
private userAgent;
|
|
12
11
|
private modern;
|
|
13
|
-
constructor({ renderSlots, pageService, resourcesRegistry, context, reactRender, htmlPageSchema, polyfillCondition,
|
|
12
|
+
constructor({ renderSlots, pageService, resourcesRegistry, context, reactRender, htmlPageSchema, polyfillCondition, htmlAttrs, modern, }: {
|
|
14
13
|
renderSlots: any;
|
|
15
14
|
pageService: any;
|
|
16
15
|
resourcesRegistry: any;
|
|
@@ -18,8 +17,8 @@ export declare class PageBuilder {
|
|
|
18
17
|
reactRender: any;
|
|
19
18
|
htmlPageSchema: any;
|
|
20
19
|
polyfillCondition: any;
|
|
21
|
-
userAgent: any;
|
|
22
20
|
htmlAttrs: any;
|
|
21
|
+
modern: any;
|
|
23
22
|
});
|
|
24
23
|
flow(): Promise<string>;
|
|
25
24
|
dehydrateState(): void;
|
package/lib/server.es.js
CHANGED
|
@@ -11,19 +11,19 @@ import { createToken, Scope } from '@tinkoff/dippy';
|
|
|
11
11
|
import { WEB_APP_AFTER_INIT_TOKEN } from '@tramvai/tokens-server';
|
|
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
|
+
import { satisfies } from '@tinkoff/user-agent';
|
|
14
15
|
import isUndefined from '@tinkoff/utils/is/undefined';
|
|
15
16
|
import isEmpty from '@tinkoff/utils/is/empty';
|
|
16
17
|
import fetch from 'node-fetch';
|
|
17
18
|
import startsWith from '@tinkoff/utils/string/startsWith';
|
|
18
19
|
import toArray from '@tinkoff/utils/array/toArray';
|
|
19
20
|
import flatten from '@tinkoff/utils/array/flatten';
|
|
20
|
-
import { satisfies } from '@tinkoff/user-agent';
|
|
21
21
|
import { buildPage, staticRender, dynamicRender } from '@tinkoff/htmlpagebuilder';
|
|
22
22
|
import { safeDehydrate } from '@tramvai/safe-strings';
|
|
23
23
|
import { ChunkExtractor } from '@loadable/server';
|
|
24
24
|
import has from '@tinkoff/utils/object/has';
|
|
25
25
|
import last from '@tinkoff/utils/array/last';
|
|
26
|
-
import { isFileSystemPageComponent } from '@tramvai/experiments';
|
|
26
|
+
import { isFileSystemPageComponent, fileSystemPageToWebpackChunkName } from '@tramvai/experiments';
|
|
27
27
|
import uniq from '@tinkoff/utils/array/uniq';
|
|
28
28
|
import * as path from 'path';
|
|
29
29
|
import each from '@tinkoff/utils/array/each';
|
|
@@ -393,15 +393,15 @@ const fetchWebpackStats = async ({ modern, } = {}) => {
|
|
|
393
393
|
};
|
|
394
394
|
|
|
395
395
|
const bundleResource = async ({ bundle, modern, extractor, pageComponent, }) => {
|
|
396
|
-
// file-system pages
|
|
396
|
+
// for file-system pages preload page chunk against bundle chunk
|
|
397
397
|
const chunkNameFromBundle = isFileSystemPageComponent(pageComponent)
|
|
398
|
-
?
|
|
398
|
+
? fileSystemPageToWebpackChunkName(pageComponent)
|
|
399
399
|
: last(bundle.split('/'));
|
|
400
400
|
const webpackStats = await fetchWebpackStats({ modern });
|
|
401
401
|
const { publicPath, assetsByChunkName } = webpackStats;
|
|
402
|
-
const bundles =
|
|
402
|
+
const bundles = has('common-chunk', assetsByChunkName)
|
|
403
403
|
? ['common-chunk', chunkNameFromBundle]
|
|
404
|
-
: [chunkNameFromBundle]
|
|
404
|
+
: [chunkNameFromBundle];
|
|
405
405
|
const lazyChunks = extractor.getMainAssets().map((entry) => entry.chunk);
|
|
406
406
|
const { scripts: baseScripts } = flushFiles(['vendor'], webpackStats, {
|
|
407
407
|
ignoreDependencies: true,
|
|
@@ -510,7 +510,7 @@ const mapResourcesToSlots = (resources) => resources.reduce((acc, resource) => {
|
|
|
510
510
|
return acc;
|
|
511
511
|
}, {});
|
|
512
512
|
class PageBuilder {
|
|
513
|
-
constructor({ renderSlots, pageService, resourcesRegistry, context, reactRender, htmlPageSchema, polyfillCondition,
|
|
513
|
+
constructor({ renderSlots, pageService, resourcesRegistry, context, reactRender, htmlPageSchema, polyfillCondition, htmlAttrs, modern, }) {
|
|
514
514
|
this.htmlAttrs = htmlAttrs;
|
|
515
515
|
this.renderSlots = flatten(renderSlots || []);
|
|
516
516
|
this.pageService = pageService;
|
|
@@ -519,8 +519,7 @@ class PageBuilder {
|
|
|
519
519
|
this.reactRender = reactRender;
|
|
520
520
|
this.htmlPageSchema = htmlPageSchema;
|
|
521
521
|
this.polyfillCondition = polyfillCondition;
|
|
522
|
-
this.
|
|
523
|
-
this.modern = satisfies(this.userAgent, null, { env: 'modern' });
|
|
522
|
+
this.modern = modern;
|
|
524
523
|
}
|
|
525
524
|
async flow() {
|
|
526
525
|
const stats = await fetchWebpackStats({ modern: this.modern });
|
|
@@ -825,8 +824,8 @@ RenderModule = RenderModule_1 = __decorate([
|
|
|
825
824
|
htmlPageSchema: 'htmlPageSchema',
|
|
826
825
|
renderSlots: { token: RENDER_SLOTS, optional: true },
|
|
827
826
|
polyfillCondition: POLYFILL_CONDITION,
|
|
828
|
-
userAgent: USER_AGENT_TOKEN,
|
|
829
827
|
htmlAttrs: HTML_ATTRS,
|
|
828
|
+
modern: 'modernSatisfies',
|
|
830
829
|
},
|
|
831
830
|
}),
|
|
832
831
|
provide({
|
|
@@ -912,6 +911,33 @@ RenderModule = RenderModule_1 = __decorate([
|
|
|
912
911
|
logger: LOGGER_TOKEN,
|
|
913
912
|
},
|
|
914
913
|
}),
|
|
914
|
+
provide({
|
|
915
|
+
provide: 'modernSatisfies',
|
|
916
|
+
useFactory: ({ requestManager, userAgent, cache }) => {
|
|
917
|
+
const reqUserAgent = requestManager.getHeader('user-agent');
|
|
918
|
+
if (cache.has(reqUserAgent)) {
|
|
919
|
+
return cache.get(reqUserAgent);
|
|
920
|
+
}
|
|
921
|
+
const result = satisfies(userAgent, null, { env: 'modern' });
|
|
922
|
+
cache.set(reqUserAgent, result);
|
|
923
|
+
return result;
|
|
924
|
+
},
|
|
925
|
+
deps: {
|
|
926
|
+
requestManager: REQUEST_MANAGER_TOKEN,
|
|
927
|
+
userAgent: USER_AGENT_TOKEN,
|
|
928
|
+
cache: 'modernSatisfiesLruCache',
|
|
929
|
+
},
|
|
930
|
+
}),
|
|
931
|
+
provide({
|
|
932
|
+
provide: 'modernSatisfiesLruCache',
|
|
933
|
+
scope: Scope.SINGLETON,
|
|
934
|
+
useFactory: ({ createCache }) => {
|
|
935
|
+
return createCache('modernSatisfies', { max: 50 });
|
|
936
|
+
},
|
|
937
|
+
deps: {
|
|
938
|
+
createCache: CREATE_CACHE_TOKEN,
|
|
939
|
+
},
|
|
940
|
+
}),
|
|
915
941
|
],
|
|
916
942
|
})
|
|
917
943
|
], RenderModule);
|
package/lib/server.js
CHANGED
|
@@ -14,13 +14,13 @@ var dippy = require('@tinkoff/dippy');
|
|
|
14
14
|
var tokensServer = require('@tramvai/tokens-server');
|
|
15
15
|
var react = require('@tramvai/react');
|
|
16
16
|
var url = require('@tinkoff/url');
|
|
17
|
+
var userAgent = require('@tinkoff/user-agent');
|
|
17
18
|
var isUndefined = require('@tinkoff/utils/is/undefined');
|
|
18
19
|
var isEmpty = require('@tinkoff/utils/is/empty');
|
|
19
20
|
var fetch = require('node-fetch');
|
|
20
21
|
var startsWith = require('@tinkoff/utils/string/startsWith');
|
|
21
22
|
var toArray = require('@tinkoff/utils/array/toArray');
|
|
22
23
|
var flatten = require('@tinkoff/utils/array/flatten');
|
|
23
|
-
var userAgent = require('@tinkoff/user-agent');
|
|
24
24
|
var htmlpagebuilder = require('@tinkoff/htmlpagebuilder');
|
|
25
25
|
var safeStrings = require('@tramvai/safe-strings');
|
|
26
26
|
var server = require('@loadable/server');
|
|
@@ -430,15 +430,15 @@ const fetchWebpackStats = async ({ modern, } = {}) => {
|
|
|
430
430
|
};
|
|
431
431
|
|
|
432
432
|
const bundleResource = async ({ bundle, modern, extractor, pageComponent, }) => {
|
|
433
|
-
// file-system pages
|
|
433
|
+
// for file-system pages preload page chunk against bundle chunk
|
|
434
434
|
const chunkNameFromBundle = experiments.isFileSystemPageComponent(pageComponent)
|
|
435
|
-
?
|
|
435
|
+
? experiments.fileSystemPageToWebpackChunkName(pageComponent)
|
|
436
436
|
: last__default["default"](bundle.split('/'));
|
|
437
437
|
const webpackStats = await fetchWebpackStats({ modern });
|
|
438
438
|
const { publicPath, assetsByChunkName } = webpackStats;
|
|
439
|
-
const bundles =
|
|
439
|
+
const bundles = has__default["default"]('common-chunk', assetsByChunkName)
|
|
440
440
|
? ['common-chunk', chunkNameFromBundle]
|
|
441
|
-
: [chunkNameFromBundle]
|
|
441
|
+
: [chunkNameFromBundle];
|
|
442
442
|
const lazyChunks = extractor.getMainAssets().map((entry) => entry.chunk);
|
|
443
443
|
const { scripts: baseScripts } = flushFiles(['vendor'], webpackStats, {
|
|
444
444
|
ignoreDependencies: true,
|
|
@@ -547,7 +547,7 @@ const mapResourcesToSlots = (resources) => resources.reduce((acc, resource) => {
|
|
|
547
547
|
return acc;
|
|
548
548
|
}, {});
|
|
549
549
|
class PageBuilder {
|
|
550
|
-
constructor({ renderSlots, pageService, resourcesRegistry, context, reactRender, htmlPageSchema, polyfillCondition,
|
|
550
|
+
constructor({ renderSlots, pageService, resourcesRegistry, context, reactRender, htmlPageSchema, polyfillCondition, htmlAttrs, modern, }) {
|
|
551
551
|
this.htmlAttrs = htmlAttrs;
|
|
552
552
|
this.renderSlots = flatten__default["default"](renderSlots || []);
|
|
553
553
|
this.pageService = pageService;
|
|
@@ -556,8 +556,7 @@ class PageBuilder {
|
|
|
556
556
|
this.reactRender = reactRender;
|
|
557
557
|
this.htmlPageSchema = htmlPageSchema;
|
|
558
558
|
this.polyfillCondition = polyfillCondition;
|
|
559
|
-
this.
|
|
560
|
-
this.modern = userAgent.satisfies(this.userAgent, null, { env: 'modern' });
|
|
559
|
+
this.modern = modern;
|
|
561
560
|
}
|
|
562
561
|
async flow() {
|
|
563
562
|
const stats = await fetchWebpackStats({ modern: this.modern });
|
|
@@ -862,8 +861,8 @@ exports.RenderModule = RenderModule_1 = tslib.__decorate([
|
|
|
862
861
|
htmlPageSchema: 'htmlPageSchema',
|
|
863
862
|
renderSlots: { token: tokensRender.RENDER_SLOTS, optional: true },
|
|
864
863
|
polyfillCondition: tokensRender.POLYFILL_CONDITION,
|
|
865
|
-
userAgent: moduleClientHints.USER_AGENT_TOKEN,
|
|
866
864
|
htmlAttrs: tokensRender.HTML_ATTRS,
|
|
865
|
+
modern: 'modernSatisfies',
|
|
867
866
|
},
|
|
868
867
|
}),
|
|
869
868
|
core.provide({
|
|
@@ -949,6 +948,33 @@ exports.RenderModule = RenderModule_1 = tslib.__decorate([
|
|
|
949
948
|
logger: moduleCommon.LOGGER_TOKEN,
|
|
950
949
|
},
|
|
951
950
|
}),
|
|
951
|
+
core.provide({
|
|
952
|
+
provide: 'modernSatisfies',
|
|
953
|
+
useFactory: ({ requestManager, userAgent: userAgent$1, cache }) => {
|
|
954
|
+
const reqUserAgent = requestManager.getHeader('user-agent');
|
|
955
|
+
if (cache.has(reqUserAgent)) {
|
|
956
|
+
return cache.get(reqUserAgent);
|
|
957
|
+
}
|
|
958
|
+
const result = userAgent.satisfies(userAgent$1, null, { env: 'modern' });
|
|
959
|
+
cache.set(reqUserAgent, result);
|
|
960
|
+
return result;
|
|
961
|
+
},
|
|
962
|
+
deps: {
|
|
963
|
+
requestManager: moduleCommon.REQUEST_MANAGER_TOKEN,
|
|
964
|
+
userAgent: moduleClientHints.USER_AGENT_TOKEN,
|
|
965
|
+
cache: 'modernSatisfiesLruCache',
|
|
966
|
+
},
|
|
967
|
+
}),
|
|
968
|
+
core.provide({
|
|
969
|
+
provide: 'modernSatisfiesLruCache',
|
|
970
|
+
scope: dippy.Scope.SINGLETON,
|
|
971
|
+
useFactory: ({ createCache }) => {
|
|
972
|
+
return createCache('modernSatisfies', { max: 50 });
|
|
973
|
+
},
|
|
974
|
+
deps: {
|
|
975
|
+
createCache: moduleCommon.CREATE_CACHE_TOKEN,
|
|
976
|
+
},
|
|
977
|
+
}),
|
|
952
978
|
],
|
|
953
979
|
})
|
|
954
980
|
], exports.RenderModule);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tramvai/module-render",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.72.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"browser": "lib/browser.js",
|
|
6
6
|
"main": "lib/server.js",
|
|
@@ -24,27 +24,27 @@
|
|
|
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.266",
|
|
28
|
+
"@tramvai/module-client-hints": "1.72.2",
|
|
29
|
+
"@tramvai/module-router": "1.72.2",
|
|
30
|
+
"@tramvai/react": "1.72.2",
|
|
31
31
|
"@tramvai/safe-strings": "0.4.3",
|
|
32
|
-
"@tramvai/tokens-render": "1.
|
|
33
|
-
"@tramvai/experiments": "1.
|
|
32
|
+
"@tramvai/tokens-render": "1.72.2",
|
|
33
|
+
"@tramvai/experiments": "1.72.2",
|
|
34
34
|
"@types/loadable__server": "^5.12.6",
|
|
35
35
|
"node-fetch": "^2.6.1"
|
|
36
36
|
},
|
|
37
37
|
"peerDependencies": {
|
|
38
38
|
"@tinkoff/dippy": "0.7.38",
|
|
39
39
|
"@tinkoff/utils": "^2.1.2",
|
|
40
|
-
"@tramvai/cli": "1.
|
|
41
|
-
"@tramvai/core": "1.
|
|
42
|
-
"@tramvai/module-common": "1.
|
|
43
|
-
"@tramvai/state": "1.
|
|
44
|
-
"@tramvai/test-helpers": "1.
|
|
45
|
-
"@tramvai/tokens-common": "1.
|
|
46
|
-
"@tramvai/tokens-router": "1.
|
|
47
|
-
"@tramvai/tokens-server": "1.
|
|
40
|
+
"@tramvai/cli": "1.72.2",
|
|
41
|
+
"@tramvai/core": "1.72.2",
|
|
42
|
+
"@tramvai/module-common": "1.72.2",
|
|
43
|
+
"@tramvai/state": "1.72.2",
|
|
44
|
+
"@tramvai/test-helpers": "1.72.2",
|
|
45
|
+
"@tramvai/tokens-common": "1.72.2",
|
|
46
|
+
"@tramvai/tokens-router": "1.72.2",
|
|
47
|
+
"@tramvai/tokens-server": "1.72.2",
|
|
48
48
|
"express": "^4.17.1",
|
|
49
49
|
"prop-types": "^15.6.2",
|
|
50
50
|
"react": ">=16.8.0",
|