chayns-api 2.6.0-beta.5 → 2.6.0-beta.7

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;
@@ -58,7 +58,7 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
58
58
  throw new Error('[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.');
59
59
  }
60
60
  const {
61
- shareScopeMap: shareScopes
61
+ getInstance
62
62
  } = globalThis.moduleFederationRuntime;
63
63
  const {
64
64
  componentMap,
@@ -73,6 +73,7 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
73
73
  if (typeof Module.default === 'function') {
74
74
  return Module;
75
75
  }
76
+ const shareScopes = getInstance().shareScopeMap;
76
77
  const sharedReact = (_shareScopes$chaynsA = shareScopes['chayns-api'].react) === null || _shareScopes$chaynsA === void 0 ? void 0 : _shareScopes$chaynsA[_react.default.version];
77
78
  const matchReactVersion = sharedReact && sharedReact.useIn.includes(scope) && ((_sharedReact$lib = sharedReact.lib) === null || _sharedReact$lib === void 0 ? void 0 : _sharedReact$lib.call(sharedReact)) === _react.default;
78
79
  if (!matchReactVersion || Module.default.environment !== 'production' || (Module.default.version || 1) < 2) {
@@ -41,12 +41,17 @@ const initModuleFederationSharing = ({
41
41
  lib: () => ReactDOMClient
42
42
  };
43
43
  }
44
- globalThis.moduleFederationRuntime = createInstance({
44
+ const instance = createInstance({
45
45
  name: name !== null && name !== void 0 ? name : '',
46
46
  remotes: [],
47
47
  shared,
48
48
  plugins: [(0, _SequentialLoadPlugin.SequentialLoadPlugin)(), ...plugins]
49
49
  });
50
+ globalThis.moduleFederationRuntime = {
51
+ loadRemote: instance.loadRemote.bind(instance),
52
+ registerRemotes: instance.registerRemotes.bind(instance),
53
+ getInstance: () => instance
54
+ };
50
55
  globalThis.moduleFederationScopes = {
51
56
  registeredScopes: {},
52
57
  moduleMap: {},
@@ -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;
@@ -50,7 +50,7 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
50
50
  throw new Error('[chayns-api] moduleFederationSharing has not been initialized. Make sure to call initModuleFederationSharing.');
51
51
  }
52
52
  const {
53
- shareScopeMap: shareScopes
53
+ getInstance
54
54
  } = globalThis.moduleFederationRuntime;
55
55
  const {
56
56
  componentMap,
@@ -65,6 +65,7 @@ const loadComponent = (scope, module, url, skipCompatMode = false, preventSingle
65
65
  if (typeof Module.default === 'function') {
66
66
  return Module;
67
67
  }
68
+ const shareScopes = getInstance().shareScopeMap;
68
69
  const sharedReact = (_shareScopes$chaynsA = shareScopes['chayns-api'].react) === null || _shareScopes$chaynsA === void 0 ? void 0 : _shareScopes$chaynsA[React.version];
69
70
  const matchReactVersion = sharedReact && sharedReact.useIn.includes(scope) && ((_sharedReact$lib = sharedReact.lib) === null || _sharedReact$lib === void 0 ? void 0 : _sharedReact$lib.call(sharedReact)) === React;
70
71
  if (!matchReactVersion || Module.default.environment !== 'production' || (Module.default.version || 1) < 2) {
@@ -34,12 +34,17 @@ export const initModuleFederationSharing = ({
34
34
  lib: () => ReactDOMClient
35
35
  };
36
36
  }
37
- globalThis.moduleFederationRuntime = createInstance({
37
+ const instance = createInstance({
38
38
  name: name !== null && name !== void 0 ? name : '',
39
39
  remotes: [],
40
40
  shared,
41
41
  plugins: [SequentialLoadPlugin(), ...plugins]
42
42
  });
43
+ globalThis.moduleFederationRuntime = {
44
+ loadRemote: instance.loadRemote.bind(instance),
45
+ registerRemotes: instance.registerRemotes.bind(instance),
46
+ getInstance: () => instance
47
+ };
43
48
  globalThis.moduleFederationScopes = {
44
49
  registeredScopes: {},
45
50
  moduleMap: {},
@@ -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.5",
3
+ "version": "2.6.0-beta.7",
4
4
  "description": "new chayns api",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",