chayns-api 3.4.0 → 3.4.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.
|
@@ -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 normalizeUrl = url => {
|
|
11
|
+
try {
|
|
12
|
+
return new URL(url).toString();
|
|
13
|
+
} catch {
|
|
14
|
+
return url;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const resetAfterCacheTime = (scope, module, url) => {
|
|
18
|
+
const key = `${scope}\n${module}\n${url}`;
|
|
19
|
+
if (!globalThis.moduleFederationScopes.errorResetTimeouts) {
|
|
20
|
+
globalThis.moduleFederationScopes.errorResetTimeouts = new Set();
|
|
21
|
+
}
|
|
22
|
+
const errorResetTimeouts = globalThis.moduleFederationScopes.errorResetTimeouts;
|
|
23
|
+
if (errorResetTimeouts.has(key)) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
errorResetTimeouts.add(key);
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
const {
|
|
29
|
+
registeredScopes
|
|
30
|
+
} = globalThis.moduleFederationScopes;
|
|
31
|
+
if (registeredScopes[scope] === url) {
|
|
32
|
+
registeredScopes[scope] = '';
|
|
33
|
+
}
|
|
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
|
-
|
|
23
|
-
|
|
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: ${
|
|
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] =
|
|
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,
|
|
45
|
-
|
|
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
|
}
|
|
@@ -65,7 +65,8 @@ const initModuleFederationSharing = ({
|
|
|
65
65
|
globalThis.moduleFederationScopes = {
|
|
66
66
|
registeredScopes: {},
|
|
67
67
|
moduleMap: {},
|
|
68
|
-
componentMap: {}
|
|
68
|
+
componentMap: {},
|
|
69
|
+
errorResetTimeouts: new Set()
|
|
69
70
|
};
|
|
70
71
|
};
|
|
71
72
|
exports.initModuleFederationSharing = initModuleFederationSharing;
|
|
@@ -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 normalizeUrl = url => {
|
|
7
|
+
try {
|
|
8
|
+
return new URL(url).toString();
|
|
9
|
+
} catch {
|
|
10
|
+
return url;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
const resetAfterCacheTime = (scope, module, url) => {
|
|
14
|
+
const key = `${scope}\n${module}\n${url}`;
|
|
15
|
+
if (!globalThis.moduleFederationScopes.errorResetTimeouts) {
|
|
16
|
+
globalThis.moduleFederationScopes.errorResetTimeouts = new Set();
|
|
17
|
+
}
|
|
18
|
+
const errorResetTimeouts = globalThis.moduleFederationScopes.errorResetTimeouts;
|
|
19
|
+
if (errorResetTimeouts.has(key)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
errorResetTimeouts.add(key);
|
|
23
|
+
setTimeout(() => {
|
|
24
|
+
const {
|
|
25
|
+
registeredScopes
|
|
26
|
+
} = globalThis.moduleFederationScopes;
|
|
27
|
+
if (registeredScopes[scope] === url) {
|
|
28
|
+
registeredScopes[scope] = '';
|
|
29
|
+
}
|
|
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
|
-
|
|
19
|
-
|
|
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: ${
|
|
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] =
|
|
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,
|
|
41
|
-
|
|
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
|
}
|