chayns-api 2.6.0-beta.6 → 2.6.0-beta.8

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,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  var _htmlescape = _interopRequireDefault(require("htmlescape"));
8
8
  var _react = _interopRequireWildcard(require("react"));
9
+ var _useIsomorphicLayoutEffect = require("../hooks/useIsomorphicLayoutEffect");
9
10
  var _IChaynsReact = require("../types/IChaynsReact");
10
11
  var _deviceHelper = _interopRequireDefault(require("../util/deviceHelper"));
11
12
  var _AppWrapper = require("../wrapper/AppWrapper");
@@ -93,7 +94,7 @@ const ChaynsProvider = ({
93
94
  customWrapper.current.emitChange();
94
95
  }
95
96
  }, [customFunctions, isModule]);
96
- (0, _react.useLayoutEffect)(() => {
97
+ (0, _useIsomorphicLayoutEffect.useIsomorphicLayoutEffect)(() => {
97
98
  (0, _moduleWrapper.addModuleWrapper)(customWrapper.current);
98
99
  return () => {
99
100
  (0, _moduleWrapper.removeModuleWrapper)(customWrapper.current);
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useIsomorphicLayoutEffect = void 0;
7
+ var _react = require("react");
8
+ const useIsomorphicLayoutEffect = exports.useIsomorphicLayoutEffect = typeof window !== 'undefined' ? _react.useLayoutEffect : _react.useEffect;
@@ -4,32 +4,13 @@ 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
- };
27
7
  const collectCssChunks = async modules => {
28
- const p = Object.values(modules).map(async module => {
29
- const info = await loadRemoteInfo(module.url);
8
+ const instance = globalThis.moduleFederationRuntime.getInstance();
9
+ const p = Object.values(modules).map(module => {
10
+ const info = instance.snapshotHandler.manifestCache.get(module.url);
30
11
  const chunks = [];
31
12
  info === null || info === void 0 || info.exposes.forEach(exposes => {
32
- if (module.modules.has(exposes.path)) {
13
+ if (exposes.path && module.modules.has(exposes.path)) {
33
14
  var _exposes$assets$css, _exposes$assets;
34
15
  const {
35
16
  sync = [],
@@ -43,7 +24,6 @@ const collectCssChunks = async modules => {
43
24
  });
44
25
  return chunks;
45
26
  });
46
- const r = await Promise.allSettled(p);
47
- return r.flatMap(v => v.status === 'fulfilled' ? v.value : []).join('');
27
+ return p.flat().join('');
48
28
  };
49
29
  exports.collectCssChunks = collectCssChunks;
@@ -1,5 +1,6 @@
1
1
  import htmlEscape from 'htmlescape';
2
- import React, { useEffect, useLayoutEffect, useRef, useState } from 'react';
2
+ import React, { useEffect, useRef, useState } from 'react';
3
+ import { useIsomorphicLayoutEffect } from '../hooks/useIsomorphicLayoutEffect';
3
4
  import { AppName } from '../types/IChaynsReact';
4
5
  import getDeviceInfo from '../util/deviceHelper';
5
6
  import { AppWrapper } from '../wrapper/AppWrapper';
@@ -85,7 +86,7 @@ const ChaynsProvider = ({
85
86
  customWrapper.current.emitChange();
86
87
  }
87
88
  }, [customFunctions, isModule]);
88
- useLayoutEffect(() => {
89
+ useIsomorphicLayoutEffect(() => {
89
90
  addModuleWrapper(customWrapper.current);
90
91
  return () => {
91
92
  removeModuleWrapper(customWrapper.current);
@@ -0,0 +1,2 @@
1
+ import { useEffect, useLayoutEffect } from 'react';
2
+ export const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
@@ -1,29 +1,10 @@
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
- };
21
1
  export const collectCssChunks = async modules => {
22
- const p = Object.values(modules).map(async module => {
23
- const info = await loadRemoteInfo(module.url);
2
+ const instance = globalThis.moduleFederationRuntime.getInstance();
3
+ const p = Object.values(modules).map(module => {
4
+ const info = instance.snapshotHandler.manifestCache.get(module.url);
24
5
  const chunks = [];
25
6
  info === null || info === void 0 || info.exposes.forEach(exposes => {
26
- if (module.modules.has(exposes.path)) {
7
+ if (exposes.path && module.modules.has(exposes.path)) {
27
8
  var _exposes$assets$css, _exposes$assets;
28
9
  const {
29
10
  sync = [],
@@ -37,6 +18,5 @@ export const collectCssChunks = async modules => {
37
18
  });
38
19
  return chunks;
39
20
  });
40
- const r = await Promise.allSettled(p);
41
- return r.flatMap(v => v.status === 'fulfilled' ? v.value : []).join('');
21
+ return p.flat().join('');
42
22
  };
@@ -0,0 +1,2 @@
1
+ import { useLayoutEffect } from 'react';
2
+ export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "chayns-api",
3
- "version": "2.6.0-beta.6",
3
+ "version": "2.6.0-beta.8",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",