@tramvai/module-render 1.9.8 → 1.10.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.
@@ -1,2 +1,2 @@
1
1
  export declare const getFileContentLength: (url: string) => Promise<string>;
2
- export declare const getFile: (url: string) => Promise<string>;
2
+ export declare const getFile: (url: string) => Promise<string | undefined>;
@@ -10,6 +10,7 @@ export declare type ResourcesRegistryCache = {
10
10
  filesCache: Cache;
11
11
  sizeCache: Cache;
12
12
  requestsCache: Cache;
13
+ disabledUrlsCache: any;
13
14
  };
14
15
  /**
15
16
  * @description
package/lib/server.es.js CHANGED
@@ -40,8 +40,11 @@ const getFileContentLength = async (url) => {
40
40
  };
41
41
  const getFile = async (url) => {
42
42
  const fileResponse = await fetch(url, { timeout: thirtySeconds });
43
- const file = await fileResponse.text();
44
- return file;
43
+ if (fileResponse.ok) {
44
+ const file = await fileResponse.text();
45
+ return file;
46
+ }
47
+ return undefined;
45
48
  };
46
49
 
47
50
  const URL_OCCURRENCES_RE = /(url\((['"]?))(.*?)(\2\))/gi;
@@ -90,13 +93,19 @@ class ResourcesInliner {
90
93
  this.scheduleFileLoad = (resource, resourceInlineThreshold) => {
91
94
  const url = getResourceUrl(resource);
92
95
  const requestKey = `file${url}`;
93
- if (!this.resourcesRegistryCache.requestsCache.get(requestKey)) {
96
+ const urlIsDisabled = this.resourcesRegistryCache.disabledUrlsCache.get(url);
97
+ const requestIsInProgress = this.resourcesRegistryCache.requestsCache.get(requestKey);
98
+ if (!requestIsInProgress && !urlIsDisabled) {
94
99
  const result = this.resourcesRegistryCache.filesCache.get(url);
95
100
  if (result) {
96
101
  return result;
97
102
  }
98
103
  const getFilePromise = getFile(url)
99
104
  .then((file) => {
105
+ if (file === undefined) {
106
+ this.resourcesRegistryCache.disabledUrlsCache.set(url, true);
107
+ return;
108
+ }
100
109
  const size = file.length;
101
110
  if (size < resourceInlineThreshold) {
102
111
  this.resourcesRegistryCache.filesCache.set(url, processFile(resource, file));
@@ -712,6 +721,7 @@ RenderModule = RenderModule_1 = __decorate([
712
721
  filesCache: createCache('memory', { max: 50, maxAge: thirtyMinutes }),
713
722
  sizeCache: createCache('memory', { max: 100, maxAge: thirtyMinutes }),
714
723
  requestsCache: createCache('memory', { max: 150, maxAge: 1000 * 60 * 5 }),
724
+ disabledUrlsCache: createCache('memory', { max: 150, maxAge: 1000 * 60 * 5 }),
715
725
  };
716
726
  },
717
727
  deps: {
package/lib/server.js CHANGED
@@ -79,8 +79,11 @@ const getFileContentLength = async (url) => {
79
79
  };
80
80
  const getFile = async (url) => {
81
81
  const fileResponse = await fetch__default["default"](url, { timeout: thirtySeconds });
82
- const file = await fileResponse.text();
83
- return file;
82
+ if (fileResponse.ok) {
83
+ const file = await fileResponse.text();
84
+ return file;
85
+ }
86
+ return undefined;
84
87
  };
85
88
 
86
89
  const URL_OCCURRENCES_RE = /(url\((['"]?))(.*?)(\2\))/gi;
@@ -129,13 +132,19 @@ class ResourcesInliner {
129
132
  this.scheduleFileLoad = (resource, resourceInlineThreshold) => {
130
133
  const url = getResourceUrl(resource);
131
134
  const requestKey = `file${url}`;
132
- if (!this.resourcesRegistryCache.requestsCache.get(requestKey)) {
135
+ const urlIsDisabled = this.resourcesRegistryCache.disabledUrlsCache.get(url);
136
+ const requestIsInProgress = this.resourcesRegistryCache.requestsCache.get(requestKey);
137
+ if (!requestIsInProgress && !urlIsDisabled) {
133
138
  const result = this.resourcesRegistryCache.filesCache.get(url);
134
139
  if (result) {
135
140
  return result;
136
141
  }
137
142
  const getFilePromise = getFile(url)
138
143
  .then((file) => {
144
+ if (file === undefined) {
145
+ this.resourcesRegistryCache.disabledUrlsCache.set(url, true);
146
+ return;
147
+ }
139
148
  const size = file.length;
140
149
  if (size < resourceInlineThreshold) {
141
150
  this.resourcesRegistryCache.filesCache.set(url, processFile(resource, file));
@@ -751,6 +760,7 @@ exports.RenderModule = RenderModule_1 = tslib.__decorate([
751
760
  filesCache: createCache('memory', { max: 50, maxAge: thirtyMinutes }),
752
761
  sizeCache: createCache('memory', { max: 100, maxAge: thirtyMinutes }),
753
762
  requestsCache: createCache('memory', { max: 150, maxAge: 1000 * 60 * 5 }),
763
+ disabledUrlsCache: createCache('memory', { max: 150, maxAge: 1000 * 60 * 5 }),
754
764
  };
755
765
  },
756
766
  deps: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-render",
3
- "version": "1.9.8",
3
+ "version": "1.10.0",
4
4
  "description": "",
5
5
  "browser": "lib/browser.js",
6
6
  "main": "lib/server.js",
@@ -24,25 +24,25 @@
24
24
  "@tinkoff/htmlpagebuilder": "0.4.22",
25
25
  "@tinkoff/layout-factory": "0.2.27",
26
26
  "@tinkoff/url": "0.7.36",
27
- "@tinkoff/user-agent": "0.3.95",
28
- "@tramvai/module-client-hints": "1.9.8",
29
- "@tramvai/module-router": "1.9.8",
30
- "@tramvai/react": "1.9.8",
27
+ "@tinkoff/user-agent": "0.3.99",
28
+ "@tramvai/module-client-hints": "1.10.0",
29
+ "@tramvai/module-router": "1.10.0",
30
+ "@tramvai/react": "1.10.0",
31
31
  "@tramvai/safe-strings": "0.4.2",
32
- "@tramvai/tokens-render": "1.9.8",
32
+ "@tramvai/tokens-render": "1.10.0",
33
33
  "@types/loadable__server": "^5.12.6",
34
34
  "node-fetch": "^2.6.1"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@tinkoff/dippy": "0.7.35",
38
38
  "@tinkoff/utils": "^2.1.2",
39
- "@tramvai/cli": "1.9.8",
40
- "@tramvai/core": "1.9.8",
41
- "@tramvai/module-common": "1.9.8",
42
- "@tramvai/state": "1.9.8",
43
- "@tramvai/test-helpers": "1.9.8",
44
- "@tramvai/tokens-common": "1.9.8",
45
- "@tramvai/tokens-router": "1.9.8",
39
+ "@tramvai/cli": "1.10.0",
40
+ "@tramvai/core": "1.10.0",
41
+ "@tramvai/module-common": "1.10.0",
42
+ "@tramvai/state": "1.10.0",
43
+ "@tramvai/test-helpers": "1.10.0",
44
+ "@tramvai/tokens-common": "1.10.0",
45
+ "@tramvai/tokens-router": "1.10.0",
46
46
  "prop-types": "^15.6.2",
47
47
  "react": ">=16.8.0",
48
48
  "react-dom": ">=16.8.0",