chayns-api 3.4.0 → 3.4.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.
@@ -6,6 +6,34 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.loadModule = exports.default = void 0;
7
7
  var _react = _interopRequireDefault(require("react"));
8
8
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
9
+ const ERROR_CACHE_TIME = 60000;
10
+ const errorResetTimeouts = new Set();
11
+ const normalizeUrl = url => {
12
+ try {
13
+ return new URL(url).toString();
14
+ } catch {
15
+ return url;
16
+ }
17
+ };
18
+ const resetAfterCacheTime = (scope, module, url) => {
19
+ const key = `${scope}\n${module}\n${url}`;
20
+ if (errorResetTimeouts.has(key)) {
21
+ return;
22
+ }
23
+ errorResetTimeouts.add(key);
24
+ setTimeout(() => {
25
+ var _componentMap$scope;
26
+ const {
27
+ registeredScopes,
28
+ componentMap
29
+ } = globalThis.moduleFederationScopes;
30
+ if (registeredScopes[scope] === url) {
31
+ registeredScopes[scope] = '';
32
+ }
33
+ (_componentMap$scope = componentMap[scope]) === null || _componentMap$scope === void 0 || delete _componentMap$scope[module];
34
+ errorResetTimeouts.delete(key);
35
+ }, ERROR_CACHE_TIME);
36
+ };
9
37
  const loadModule = (scope, module, url, preventSingleton = false) => {
10
38
  if (!globalThis.moduleFederationRuntime || !globalThis.moduleFederationScopes) {
11
39
  throw new Error('[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.');
@@ -19,12 +47,10 @@ const loadModule = (scope, module, url, preventSingleton = false) => {
19
47
  moduleMap,
20
48
  componentMap
21
49
  } = globalThis.moduleFederationScopes;
22
- try {
23
- url = new URL(url).toString();
24
- } catch {}
25
- if (registeredScopes[scope] !== url || preventSingleton) {
50
+ const remoteUrl = normalizeUrl(url);
51
+ if (registeredScopes[scope] !== remoteUrl || preventSingleton) {
26
52
  if (scope in registeredScopes) {
27
- console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${url}`);
53
+ console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${remoteUrl}`);
28
54
  }
29
55
  registerRemotes([{
30
56
  shareScope: url.endsWith('v2.remoteEntry.js') || url.endsWith('mf-manifest.json') ? 'chayns-api' : 'default',
@@ -33,7 +59,7 @@ const loadModule = (scope, module, url, preventSingleton = false) => {
33
59
  }], {
34
60
  force: scope in registeredScopes || preventSingleton
35
61
  });
36
- registeredScopes[scope] = url;
62
+ registeredScopes[scope] = remoteUrl;
37
63
  moduleMap[scope] = {};
38
64
  componentMap[scope] = {};
39
65
  }
@@ -41,8 +67,8 @@ const loadModule = (scope, module, url, preventSingleton = false) => {
41
67
  const path = `${scope}/${module.replace(/^\.\//, '')}`;
42
68
  const promise = loadRemote(path);
43
69
  promise.catch(e => {
44
- console.error("[chayns-api] Failed to load module", scope, url, e);
45
- registeredScopes[scope] = '';
70
+ console.error("[chayns-api] Failed to load module", scope, remoteUrl, e);
71
+ resetAfterCacheTime(scope, module, remoteUrl);
46
72
  });
47
73
  return promise;
48
74
  }
@@ -108,7 +134,6 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
108
134
  });
109
135
  promise.catch(e => {
110
136
  console.error("[chayns-api] Failed to load component", scope, url, e);
111
- delete componentMap[scope][module];
112
137
  });
113
138
  componentMap[scope][module] = _react.default.lazy(() => promise);
114
139
  }
@@ -2,6 +2,34 @@ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object
2
2
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
3
3
  function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
4
4
  import React from "react";
5
+ const ERROR_CACHE_TIME = 60000;
6
+ const errorResetTimeouts = new Set();
7
+ const normalizeUrl = url => {
8
+ try {
9
+ return new URL(url).toString();
10
+ } catch {
11
+ return url;
12
+ }
13
+ };
14
+ const resetAfterCacheTime = (scope, module, url) => {
15
+ const key = `${scope}\n${module}\n${url}`;
16
+ if (errorResetTimeouts.has(key)) {
17
+ return;
18
+ }
19
+ errorResetTimeouts.add(key);
20
+ setTimeout(() => {
21
+ var _componentMap$scope;
22
+ const {
23
+ registeredScopes,
24
+ componentMap
25
+ } = globalThis.moduleFederationScopes;
26
+ if (registeredScopes[scope] === url) {
27
+ registeredScopes[scope] = '';
28
+ }
29
+ (_componentMap$scope = componentMap[scope]) === null || _componentMap$scope === void 0 || delete _componentMap$scope[module];
30
+ errorResetTimeouts.delete(key);
31
+ }, ERROR_CACHE_TIME);
32
+ };
5
33
  export const loadModule = (scope, module, url, preventSingleton = false) => {
6
34
  if (!globalThis.moduleFederationRuntime || !globalThis.moduleFederationScopes) {
7
35
  throw new Error('[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.');
@@ -15,12 +43,10 @@ export const loadModule = (scope, module, url, preventSingleton = false) => {
15
43
  moduleMap,
16
44
  componentMap
17
45
  } = globalThis.moduleFederationScopes;
18
- try {
19
- url = new URL(url).toString();
20
- } catch {}
21
- if (registeredScopes[scope] !== url || preventSingleton) {
46
+ const remoteUrl = normalizeUrl(url);
47
+ if (registeredScopes[scope] !== remoteUrl || preventSingleton) {
22
48
  if (scope in registeredScopes) {
23
- console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${url}`);
49
+ console.error(`[chayns-api] call registerRemote with force for scope ${scope}. url: ${remoteUrl}`);
24
50
  }
25
51
  registerRemotes([{
26
52
  shareScope: url.endsWith('v2.remoteEntry.js') || url.endsWith('mf-manifest.json') ? 'chayns-api' : 'default',
@@ -29,7 +55,7 @@ export const loadModule = (scope, module, url, preventSingleton = false) => {
29
55
  }], {
30
56
  force: scope in registeredScopes || preventSingleton
31
57
  });
32
- registeredScopes[scope] = url;
58
+ registeredScopes[scope] = remoteUrl;
33
59
  moduleMap[scope] = {};
34
60
  componentMap[scope] = {};
35
61
  }
@@ -37,8 +63,8 @@ export const loadModule = (scope, module, url, preventSingleton = false) => {
37
63
  const path = `${scope}/${module.replace(/^\.\//, '')}`;
38
64
  const promise = loadRemote(path);
39
65
  promise.catch(e => {
40
- console.error("[chayns-api] Failed to load module", scope, url, e);
41
- registeredScopes[scope] = '';
66
+ console.error("[chayns-api] Failed to load module", scope, remoteUrl, e);
67
+ resetAfterCacheTime(scope, module, remoteUrl);
42
68
  });
43
69
  return promise;
44
70
  }
@@ -104,7 +130,6 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
104
130
  });
105
131
  promise.catch(e => {
106
132
  console.error("[chayns-api] Failed to load component", scope, url, e);
107
- delete componentMap[scope][module];
108
133
  });
109
134
  componentMap[scope][module] = React.lazy(() => promise);
110
135
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "3.4.0",
3
+ "version": "3.4.1",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",