@tramvai/module-render 4.21.0 → 4.23.0

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 CHANGED
@@ -125,6 +125,37 @@ provide({
125
125
  }),
126
126
  ```
127
127
 
128
+ Under the hood resource inliner cached all fetched resources.
129
+
130
+ By default cache size are:
131
+ - 300 - for fetched content
132
+ - 300 - for content sizes
133
+ - 300 - for disabled urls of unavailable resources
134
+
135
+ You can configure cache sizes with `cacheSize`:
136
+
137
+ ```js
138
+ import { RESOURCE_INLINE_OPTIONS } from '@tramvai/tokens-render';
139
+ import { ResourceType } from '@tramvai/tokens-render';
140
+ import { provide } from '@tramvai/core';
141
+
142
+ provide({
143
+ provide: RESOURCE_INLINE_OPTIONS,
144
+ useValue: {
145
+ types: [ResourceType.script, ResourceType.style], // Turn on for a CSS and JS files
146
+ threshold: 1024, // 1kb unzipped
147
+ cacheSize: {
148
+ files: 50,
149
+ size: 100,
150
+ disabledUrl: 150,
151
+ },
152
+ },
153
+ }),
154
+ ```
155
+
156
+ Be aware of memory consumption of resources - they are uncompressed. So with 5kb threshold and 1000 entities in cache
157
+ you will get +5Mb on the heap.
158
+
128
159
  #### Peculiarities
129
160
 
130
161
  All scripts and styles (depending on the settings) registered through the `ResourcesRegistry` are inlined.
package/lib/server.es.js CHANGED
@@ -25,6 +25,15 @@ import { fetchWebpackStats } from './server/blocks/utils/fetchWebpackStats.es.js
25
25
 
26
26
  var RenderModule_1;
27
27
  const REQUEST_TTL = 5 * 60 * 1000;
28
+ /**
29
+ * @description
30
+ * Default sizes for resource inliner cache
31
+ */
32
+ const RESOURCES_REGISTRY_FILES_CACHE_SIZE = 300;
33
+ const RESOURCES_REGISTRY_SIZE_CACHE_SIZE = 300;
34
+ const RESOURCES_REGISTRY_DISABLED_URL_CACHE_SIZE = 300;
35
+ const RESOURCES_REGISTRY_FILES_CACHE_TTL = 24 * 60 * 60 * 1000; // 24h
36
+ const RESOURCES_REGISTRY_SIZE_CACHE_TTL = 24 * 60 * 60 * 1000; // 24h
28
37
  const DEFAULT_POLYFILL_CONDITION = '!window.Promise.prototype.finally || !window.URL || !window.AbortController || !window.IntersectionObserver || !Object.fromEntries || !window.ResizeObserver';
29
38
  let RenderModule = RenderModule_1 = class RenderModule {
30
39
  static forRoot({ polyfillCondition }) {
@@ -56,15 +65,33 @@ RenderModule = RenderModule_1 = __decorate([
56
65
  provide({
57
66
  provide: RESOURCES_REGISTRY_CACHE,
58
67
  scope: Scope.SINGLETON,
59
- useFactory: ({ createCache }) => {
68
+ useFactory: ({ createCache, resourceInlineOptions }) => {
69
+ let filesCacheSize = RESOURCES_REGISTRY_FILES_CACHE_SIZE;
70
+ let sizeCacheSize = RESOURCES_REGISTRY_SIZE_CACHE_SIZE;
71
+ let disabledUrlCacheSize = RESOURCES_REGISTRY_DISABLED_URL_CACHE_SIZE;
72
+ if (resourceInlineOptions && resourceInlineOptions.cacheSize) {
73
+ filesCacheSize = resourceInlineOptions.cacheSize.files;
74
+ sizeCacheSize = resourceInlineOptions.cacheSize.size;
75
+ disabledUrlCacheSize = resourceInlineOptions.cacheSize.disabledUrl;
76
+ }
60
77
  return {
61
- filesCache: createCache('memory', { max: 50 }),
62
- sizeCache: createCache('memory', { max: 100 }),
63
- disabledUrlsCache: createCache('memory', { max: 150, ttl: REQUEST_TTL }),
78
+ filesCache: createCache('memory', {
79
+ max: filesCacheSize,
80
+ ttl: RESOURCES_REGISTRY_FILES_CACHE_TTL,
81
+ }),
82
+ sizeCache: createCache('memory', {
83
+ max: sizeCacheSize,
84
+ ttl: RESOURCES_REGISTRY_SIZE_CACHE_TTL,
85
+ }),
86
+ disabledUrlsCache: createCache('memory', {
87
+ max: disabledUrlCacheSize,
88
+ ttl: REQUEST_TTL,
89
+ }),
64
90
  };
65
91
  },
66
92
  deps: {
67
93
  createCache: CREATE_CACHE_TOKEN,
94
+ resourceInlineOptions: { token: RESOURCE_INLINE_OPTIONS, optional: true },
68
95
  },
69
96
  }),
70
97
  provide({
@@ -255,6 +282,11 @@ Page Error Boundary will be rendered for the client`,
255
282
  useValue: {
256
283
  threshold: 40960,
257
284
  types: [ResourceType.style],
285
+ cacheSize: {
286
+ files: RESOURCES_REGISTRY_FILES_CACHE_SIZE,
287
+ size: RESOURCES_REGISTRY_SIZE_CACHE_SIZE,
288
+ disabledUrl: RESOURCES_REGISTRY_DISABLED_URL_CACHE_SIZE,
289
+ },
258
290
  },
259
291
  }),
260
292
  provide({
package/lib/server.js CHANGED
@@ -26,6 +26,15 @@ var fetchWebpackStats = require('./server/blocks/utils/fetchWebpackStats.js');
26
26
 
27
27
  var RenderModule_1;
28
28
  const REQUEST_TTL = 5 * 60 * 1000;
29
+ /**
30
+ * @description
31
+ * Default sizes for resource inliner cache
32
+ */
33
+ const RESOURCES_REGISTRY_FILES_CACHE_SIZE = 300;
34
+ const RESOURCES_REGISTRY_SIZE_CACHE_SIZE = 300;
35
+ const RESOURCES_REGISTRY_DISABLED_URL_CACHE_SIZE = 300;
36
+ const RESOURCES_REGISTRY_FILES_CACHE_TTL = 24 * 60 * 60 * 1000; // 24h
37
+ const RESOURCES_REGISTRY_SIZE_CACHE_TTL = 24 * 60 * 60 * 1000; // 24h
29
38
  const DEFAULT_POLYFILL_CONDITION = '!window.Promise.prototype.finally || !window.URL || !window.AbortController || !window.IntersectionObserver || !Object.fromEntries || !window.ResizeObserver';
30
39
  exports.RenderModule = RenderModule_1 = class RenderModule {
31
40
  static forRoot({ polyfillCondition }) {
@@ -57,15 +66,33 @@ exports.RenderModule = RenderModule_1 = tslib.__decorate([
57
66
  core.provide({
58
67
  provide: tokens.RESOURCES_REGISTRY_CACHE,
59
68
  scope: dippy.Scope.SINGLETON,
60
- useFactory: ({ createCache }) => {
69
+ useFactory: ({ createCache, resourceInlineOptions }) => {
70
+ let filesCacheSize = RESOURCES_REGISTRY_FILES_CACHE_SIZE;
71
+ let sizeCacheSize = RESOURCES_REGISTRY_SIZE_CACHE_SIZE;
72
+ let disabledUrlCacheSize = RESOURCES_REGISTRY_DISABLED_URL_CACHE_SIZE;
73
+ if (resourceInlineOptions && resourceInlineOptions.cacheSize) {
74
+ filesCacheSize = resourceInlineOptions.cacheSize.files;
75
+ sizeCacheSize = resourceInlineOptions.cacheSize.size;
76
+ disabledUrlCacheSize = resourceInlineOptions.cacheSize.disabledUrl;
77
+ }
61
78
  return {
62
- filesCache: createCache('memory', { max: 50 }),
63
- sizeCache: createCache('memory', { max: 100 }),
64
- disabledUrlsCache: createCache('memory', { max: 150, ttl: REQUEST_TTL }),
79
+ filesCache: createCache('memory', {
80
+ max: filesCacheSize,
81
+ ttl: RESOURCES_REGISTRY_FILES_CACHE_TTL,
82
+ }),
83
+ sizeCache: createCache('memory', {
84
+ max: sizeCacheSize,
85
+ ttl: RESOURCES_REGISTRY_SIZE_CACHE_TTL,
86
+ }),
87
+ disabledUrlsCache: createCache('memory', {
88
+ max: disabledUrlCacheSize,
89
+ ttl: REQUEST_TTL,
90
+ }),
65
91
  };
66
92
  },
67
93
  deps: {
68
94
  createCache: tokensCommon.CREATE_CACHE_TOKEN,
95
+ resourceInlineOptions: { token: tokensRender.RESOURCE_INLINE_OPTIONS, optional: true },
69
96
  },
70
97
  }),
71
98
  core.provide({
@@ -256,6 +283,11 @@ Page Error Boundary will be rendered for the client`,
256
283
  useValue: {
257
284
  threshold: 40960,
258
285
  types: [tokensRender.ResourceType.style],
286
+ cacheSize: {
287
+ files: RESOURCES_REGISTRY_FILES_CACHE_SIZE,
288
+ size: RESOURCES_REGISTRY_SIZE_CACHE_SIZE,
289
+ disabledUrl: RESOURCES_REGISTRY_DISABLED_URL_CACHE_SIZE,
290
+ },
259
291
  },
260
292
  }),
261
293
  core.provide({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-render",
3
- "version": "4.21.0",
3
+ "version": "4.23.0",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -26,28 +26,28 @@
26
26
  "@tinkoff/layout-factory": "0.5.1",
27
27
  "@tinkoff/errors": "0.5.1",
28
28
  "@tinkoff/url": "0.10.1",
29
- "@tinkoff/user-agent": "0.6.74",
30
- "@tramvai/module-client-hints": "4.21.0",
31
- "@tramvai/module-router": "4.21.0",
32
- "@tramvai/react": "4.21.0",
29
+ "@tinkoff/user-agent": "0.6.76",
30
+ "@tramvai/module-client-hints": "4.23.0",
31
+ "@tramvai/module-router": "4.23.0",
32
+ "@tramvai/react": "4.23.0",
33
33
  "@tramvai/safe-strings": "0.7.2",
34
- "@tramvai/tokens-render": "4.21.0",
35
- "@tramvai/experiments": "4.21.0",
34
+ "@tramvai/tokens-render": "4.23.0",
35
+ "@tramvai/experiments": "4.23.0",
36
36
  "@types/loadable__server": "^5.12.6",
37
37
  "node-fetch": "^2.6.1"
38
38
  },
39
39
  "peerDependencies": {
40
- "@tinkoff/dippy": "0.10.7",
40
+ "@tinkoff/dippy": "0.10.8",
41
41
  "@tinkoff/utils": "^2.1.2",
42
42
  "@tinkoff/react-hooks": "0.3.1",
43
- "@tramvai/cli": "4.21.0",
44
- "@tramvai/core": "4.21.0",
45
- "@tramvai/module-common": "4.21.0",
46
- "@tramvai/state": "4.21.0",
47
- "@tramvai/test-helpers": "4.21.0",
48
- "@tramvai/tokens-common": "4.21.0",
49
- "@tramvai/tokens-router": "4.21.0",
50
- "@tramvai/tokens-server-private": "4.21.0",
43
+ "@tramvai/cli": "4.23.0",
44
+ "@tramvai/core": "4.23.0",
45
+ "@tramvai/module-common": "4.23.0",
46
+ "@tramvai/state": "4.23.0",
47
+ "@tramvai/test-helpers": "4.23.0",
48
+ "@tramvai/tokens-common": "4.23.0",
49
+ "@tramvai/tokens-router": "4.23.0",
50
+ "@tramvai/tokens-server-private": "4.23.0",
51
51
  "express": "^4.17.1",
52
52
  "prop-types": "^15.6.2",
53
53
  "react": ">=16.14.0",