chayns-api 2.6.0-beta.8 → 2.6.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/dist/cjs/constants/hydrationContext.js +12 -1
- package/dist/cjs/constants/moduleContext.js +12 -1
- package/dist/cjs/host/module/ModuleHost.js +4 -3
- package/dist/cjs/util/collectCssChunks.js +30 -6
- package/dist/esm/constants/hydrationContext.js +12 -1
- package/dist/esm/constants/moduleContext.js +12 -1
- package/dist/esm/host/module/ModuleHost.js +4 -3
- package/dist/esm/util/collectCssChunks.js +30 -6
- package/dist/types/util/collectCssChunks.d.ts +6 -0
- package/package.json +1 -1
|
@@ -9,6 +9,17 @@ let HydrationContext = exports.HydrationContext = void 0;
|
|
|
9
9
|
if (!globalThis.window && globalThis._hydrationContext) {
|
|
10
10
|
exports.HydrationContext = HydrationContext = globalThis._hydrationContext;
|
|
11
11
|
} else {
|
|
12
|
-
|
|
12
|
+
const emptyReadonly = new Proxy({}, {
|
|
13
|
+
set() {
|
|
14
|
+
return true;
|
|
15
|
+
},
|
|
16
|
+
defineProperty() {
|
|
17
|
+
return true;
|
|
18
|
+
},
|
|
19
|
+
deleteProperty() {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
exports.HydrationContext = HydrationContext = (0, _react.createContext)(emptyReadonly);
|
|
13
24
|
globalThis._hydrationContext = HydrationContext;
|
|
14
25
|
}
|
|
@@ -9,6 +9,17 @@ let ModuleContext = exports.ModuleContext = void 0;
|
|
|
9
9
|
if (!globalThis.window && globalThis._moduleContext) {
|
|
10
10
|
exports.ModuleContext = ModuleContext = globalThis._moduleContext;
|
|
11
11
|
} else {
|
|
12
|
-
|
|
12
|
+
const emptyReadonly = new Proxy({}, {
|
|
13
|
+
set() {
|
|
14
|
+
return true;
|
|
15
|
+
},
|
|
16
|
+
defineProperty() {
|
|
17
|
+
return true;
|
|
18
|
+
},
|
|
19
|
+
deleteProperty() {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
exports.ModuleContext = ModuleContext = (0, _react.createContext)(emptyReadonly);
|
|
13
24
|
globalThis._moduleContext = ModuleContext;
|
|
14
25
|
}
|
|
@@ -17,13 +17,14 @@ const System = ({
|
|
|
17
17
|
}) => {
|
|
18
18
|
const Component = (0, _react.useMemo)(() => (0, _loadComponent.default)(system.scope, system.module, globalThis.window ? system.url : system.serverUrl, undefined, system.preventSingleton), [system.scope, system.module, system.url, system.serverUrl, system.preventSingleton]);
|
|
19
19
|
if (!globalThis.window) {
|
|
20
|
-
var
|
|
20
|
+
var _moduleContext$system;
|
|
21
21
|
const moduleContext = (0, _react.useContext)(_moduleContext.ModuleContext);
|
|
22
|
-
(_moduleContext$
|
|
22
|
+
const info = (_moduleContext$system = moduleContext[system.scope]) !== null && _moduleContext$system !== void 0 ? _moduleContext$system : {
|
|
23
23
|
url: system.url,
|
|
24
24
|
modules: new Set()
|
|
25
25
|
};
|
|
26
|
-
|
|
26
|
+
info.modules.add(system.module);
|
|
27
|
+
moduleContext[system.scope] = info;
|
|
27
28
|
}
|
|
28
29
|
return _react.default.createElement(_react.default.Suspense, {
|
|
29
30
|
fallback: fallback || ''
|
|
@@ -4,26 +4,50 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.collectCssChunks = void 0;
|
|
7
|
+
const remoteInfoCache = {};
|
|
8
|
+
const loadRemoteInfo = async url => {
|
|
9
|
+
if (!url.endsWith('/mf-manifest.json')) {
|
|
10
|
+
return null;
|
|
11
|
+
}
|
|
12
|
+
if (remoteInfoCache[url]) {
|
|
13
|
+
return remoteInfoCache[url];
|
|
14
|
+
}
|
|
15
|
+
const res = await fetch(url);
|
|
16
|
+
if (res.status === 200) {
|
|
17
|
+
const info = await res.json();
|
|
18
|
+
remoteInfoCache[url] = info;
|
|
19
|
+
return info;
|
|
20
|
+
}
|
|
21
|
+
if (res.status === 404) {
|
|
22
|
+
remoteInfoCache[url] = null;
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`Could not load remote info from ${url}`);
|
|
26
|
+
};
|
|
7
27
|
const collectCssChunks = async modules => {
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
const info = instance.snapshotHandler.manifestCache.get(module.url);
|
|
28
|
+
const p = Object.values(modules).map(async module => {
|
|
29
|
+
const info = await loadRemoteInfo(module.url);
|
|
11
30
|
const chunks = [];
|
|
12
31
|
info === null || info === void 0 || info.exposes.forEach(exposes => {
|
|
13
|
-
if (
|
|
32
|
+
if (module.modules.has(exposes.path)) {
|
|
14
33
|
var _exposes$assets$css, _exposes$assets;
|
|
15
34
|
const {
|
|
16
35
|
sync = [],
|
|
17
36
|
async = []
|
|
18
37
|
} = (_exposes$assets$css = (_exposes$assets = exposes.assets) === null || _exposes$assets === void 0 ? void 0 : _exposes$assets.css) !== null && _exposes$assets$css !== void 0 ? _exposes$assets$css : {};
|
|
19
|
-
|
|
38
|
+
sync.forEach(chunk => {
|
|
20
39
|
const url = new URL(chunk, module.url);
|
|
21
40
|
chunks.push(`<link rel="stylesheet" href="${url}">`);
|
|
22
41
|
});
|
|
42
|
+
async.forEach(chunk => {
|
|
43
|
+
const url = new URL(chunk, module.url);
|
|
44
|
+
chunks.push(`<link rel="preload" href="${url}" as="style" onload="this.rel='stylesheet'">`);
|
|
45
|
+
});
|
|
23
46
|
}
|
|
24
47
|
});
|
|
25
48
|
return chunks;
|
|
26
49
|
});
|
|
27
|
-
|
|
50
|
+
const r = await Promise.allSettled(p);
|
|
51
|
+
return r.flatMap(v => v.status === 'fulfilled' ? v.value : []).join('');
|
|
28
52
|
};
|
|
29
53
|
exports.collectCssChunks = collectCssChunks;
|
|
@@ -3,6 +3,17 @@ export let HydrationContext;
|
|
|
3
3
|
if (!globalThis.window && globalThis._hydrationContext) {
|
|
4
4
|
HydrationContext = globalThis._hydrationContext;
|
|
5
5
|
} else {
|
|
6
|
-
|
|
6
|
+
const emptyReadonly = new Proxy({}, {
|
|
7
|
+
set() {
|
|
8
|
+
return true;
|
|
9
|
+
},
|
|
10
|
+
defineProperty() {
|
|
11
|
+
return true;
|
|
12
|
+
},
|
|
13
|
+
deleteProperty() {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
HydrationContext = createContext(emptyReadonly);
|
|
7
18
|
globalThis._hydrationContext = HydrationContext;
|
|
8
19
|
}
|
|
@@ -3,6 +3,17 @@ export let ModuleContext;
|
|
|
3
3
|
if (!globalThis.window && globalThis._moduleContext) {
|
|
4
4
|
ModuleContext = globalThis._moduleContext;
|
|
5
5
|
} else {
|
|
6
|
-
|
|
6
|
+
const emptyReadonly = new Proxy({}, {
|
|
7
|
+
set() {
|
|
8
|
+
return true;
|
|
9
|
+
},
|
|
10
|
+
defineProperty() {
|
|
11
|
+
return true;
|
|
12
|
+
},
|
|
13
|
+
deleteProperty() {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
ModuleContext = createContext(emptyReadonly);
|
|
7
18
|
globalThis._moduleContext = ModuleContext;
|
|
8
19
|
}
|
|
@@ -9,13 +9,14 @@ const System = ({
|
|
|
9
9
|
}) => {
|
|
10
10
|
const Component = useMemo(() => loadComponent(system.scope, system.module, globalThis.window ? system.url : system.serverUrl, undefined, system.preventSingleton), [system.scope, system.module, system.url, system.serverUrl, system.preventSingleton]);
|
|
11
11
|
if (!globalThis.window) {
|
|
12
|
-
var
|
|
12
|
+
var _moduleContext$system;
|
|
13
13
|
const moduleContext = useContext(ModuleContext);
|
|
14
|
-
(_moduleContext$
|
|
14
|
+
const info = (_moduleContext$system = moduleContext[system.scope]) !== null && _moduleContext$system !== void 0 ? _moduleContext$system : {
|
|
15
15
|
url: system.url,
|
|
16
16
|
modules: new Set()
|
|
17
17
|
};
|
|
18
|
-
|
|
18
|
+
info.modules.add(system.module);
|
|
19
|
+
moduleContext[system.scope] = info;
|
|
19
20
|
}
|
|
20
21
|
return React.createElement(React.Suspense, {
|
|
21
22
|
fallback: fallback || ''
|
|
@@ -1,22 +1,46 @@
|
|
|
1
|
+
const remoteInfoCache = {};
|
|
2
|
+
const loadRemoteInfo = async url => {
|
|
3
|
+
if (!url.endsWith('/mf-manifest.json')) {
|
|
4
|
+
return null;
|
|
5
|
+
}
|
|
6
|
+
if (remoteInfoCache[url]) {
|
|
7
|
+
return remoteInfoCache[url];
|
|
8
|
+
}
|
|
9
|
+
const res = await fetch(url);
|
|
10
|
+
if (res.status === 200) {
|
|
11
|
+
const info = await res.json();
|
|
12
|
+
remoteInfoCache[url] = info;
|
|
13
|
+
return info;
|
|
14
|
+
}
|
|
15
|
+
if (res.status === 404) {
|
|
16
|
+
remoteInfoCache[url] = null;
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
throw new Error(`Could not load remote info from ${url}`);
|
|
20
|
+
};
|
|
1
21
|
export const collectCssChunks = async modules => {
|
|
2
|
-
const
|
|
3
|
-
|
|
4
|
-
const info = instance.snapshotHandler.manifestCache.get(module.url);
|
|
22
|
+
const p = Object.values(modules).map(async module => {
|
|
23
|
+
const info = await loadRemoteInfo(module.url);
|
|
5
24
|
const chunks = [];
|
|
6
25
|
info === null || info === void 0 || info.exposes.forEach(exposes => {
|
|
7
|
-
if (
|
|
26
|
+
if (module.modules.has(exposes.path)) {
|
|
8
27
|
var _exposes$assets$css, _exposes$assets;
|
|
9
28
|
const {
|
|
10
29
|
sync = [],
|
|
11
30
|
async = []
|
|
12
31
|
} = (_exposes$assets$css = (_exposes$assets = exposes.assets) === null || _exposes$assets === void 0 ? void 0 : _exposes$assets.css) !== null && _exposes$assets$css !== void 0 ? _exposes$assets$css : {};
|
|
13
|
-
|
|
32
|
+
sync.forEach(chunk => {
|
|
14
33
|
const url = new URL(chunk, module.url);
|
|
15
34
|
chunks.push(`<link rel="stylesheet" href="${url}">`);
|
|
16
35
|
});
|
|
36
|
+
async.forEach(chunk => {
|
|
37
|
+
const url = new URL(chunk, module.url);
|
|
38
|
+
chunks.push(`<link rel="preload" href="${url}" as="style" onload="this.rel='stylesheet'">`);
|
|
39
|
+
});
|
|
17
40
|
}
|
|
18
41
|
});
|
|
19
42
|
return chunks;
|
|
20
43
|
});
|
|
21
|
-
|
|
44
|
+
const r = await Promise.allSettled(p);
|
|
45
|
+
return r.flatMap(v => v.status === 'fulfilled' ? v.value : []).join('');
|
|
22
46
|
};
|
|
@@ -1,2 +1,8 @@
|
|
|
1
1
|
import { ModuleContextValueType } from '../constants';
|
|
2
|
+
/**
|
|
3
|
+
* Collects the css chunks from all modules rendered during SSR
|
|
4
|
+
* @experimental Handling for async chunks is not final and subject to change.
|
|
5
|
+
* Eventually a parameter for the rendered html might be added to analyze the async chunks
|
|
6
|
+
* @param modules
|
|
7
|
+
*/
|
|
2
8
|
export declare const collectCssChunks: (modules: ModuleContextValueType) => Promise<string>;
|