@tramvai/module-child-app 4.26.9 → 4.29.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.
@@ -9,10 +9,11 @@ class BrowserLoader extends Loader {
9
9
  constructor({ logger }) {
10
10
  super();
11
11
  this.initializedMap = new WeakMap();
12
+ this.map = new Map();
12
13
  this.log = logger('child-app:loader');
13
14
  }
15
+ // eslint-disable-next-line max-statements
14
16
  async load(config) {
15
- var _a;
16
17
  const moduleName = config.name;
17
18
  const childApp = await this.get(config);
18
19
  if (childApp) {
@@ -23,25 +24,39 @@ class BrowserLoader extends Loader {
23
24
  return childApp;
24
25
  }
25
26
  let container = getModuleFromGlobal(config.client.entry);
27
+ // case when Child App is loaded, but not initialized.
28
+ // can be caused when initalization is failed, or still in process.
29
+ // for second case, we can try to wait initialization.
30
+ if (container && !childApp && this.map.has(config.key)) {
31
+ return this.map.get(config.key);
32
+ }
26
33
  if (!container) {
27
34
  this.log.debug({
28
35
  event: 'load-fetch',
29
36
  moduleName,
30
37
  });
31
- // `resolveOnCssFailed: true` - allow to load module without server preloading on the client-side
32
- await loadModule(config.client.entry, {
33
- cssUrl: (_a = config.css) === null || _a === void 0 ? void 0 : _a.entry,
34
- resolveOnCssFailed: true,
35
- });
36
- container = getModuleFromGlobal(config.client.entry);
37
- if (container) {
38
- this.log.debug({
39
- event: 'load-success',
40
- moduleName,
38
+ const promise = (async () => {
39
+ var _a;
40
+ // `resolveOnCssFailed: true` - allow to load module without server preloading on the client-side
41
+ await loadModule(config.client.entry, {
42
+ cssUrl: (_a = config.css) === null || _a === void 0 ? void 0 : _a.entry,
43
+ resolveOnCssFailed: true,
41
44
  });
42
- await this.init(config);
43
- return this.get(config);
44
- }
45
+ container = getModuleFromGlobal(config.client.entry);
46
+ if (container) {
47
+ this.log.debug({
48
+ event: 'load-success',
49
+ moduleName,
50
+ });
51
+ await this.init(config);
52
+ // eslint-disable-next-line @typescript-eslint/no-shadow
53
+ const childApp = this.get(config);
54
+ this.map.delete(config.key);
55
+ return childApp;
56
+ }
57
+ })();
58
+ this.map.set(config.key, promise);
59
+ return promise;
45
60
  }
46
61
  this.log.error({
47
62
  event: 'load-failed',
@@ -3,16 +3,17 @@ import type { ChildAppFinalConfig } from '@tramvai/tokens-child-app';
3
3
  import type { LOGGER_TOKEN } from '@tramvai/tokens-common';
4
4
  import { Loader } from '../shared/loader';
5
5
  import type { ModuleFederationContainer } from '../shared/webpack/moduleFederation';
6
- export declare const getModuleFromGlobal: (entry: string) => ModuleFederationContainer | void;
6
+ export declare const getModuleFromGlobal: (entry: string) => ModuleFederationContainer | undefined;
7
7
  export declare class BrowserLoader extends Loader {
8
8
  private readonly log;
9
9
  private readonly initializedMap;
10
+ private map;
10
11
  constructor({ logger }: {
11
12
  logger: typeof LOGGER_TOKEN;
12
13
  });
13
- load(config: ChildAppFinalConfig): Promise<ChildApp | void>;
14
+ load(config: ChildAppFinalConfig): Promise<ChildApp | undefined>;
14
15
  init(config: ChildAppFinalConfig): Promise<void>;
15
- get(config: ChildAppFinalConfig): ChildApp | void;
16
+ get(config: ChildAppFinalConfig): ChildApp | undefined;
16
17
  waitFor(config: ChildAppFinalConfig): Promise<void>;
17
18
  }
18
19
  //# sourceMappingURL=loader.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tramvai/module-child-app",
3
- "version": "4.26.9",
3
+ "version": "4.29.1",
4
4
  "description": "Module for child apps",
5
5
  "browser": {
6
6
  "./lib/server.js": "./lib/browser.js",
@@ -33,23 +33,23 @@
33
33
  "@tinkoff/env-validators": "0.3.1",
34
34
  "@tinkoff/module-loader-client": "0.6.3",
35
35
  "@tinkoff/module-loader-server": "0.7.2",
36
- "@tramvai/module-common": "4.26.9",
36
+ "@tramvai/module-common": "4.29.1",
37
37
  "@tinkoff/url": "0.10.1",
38
- "@tramvai/child-app-core": "4.26.9",
38
+ "@tramvai/child-app-core": "4.29.1",
39
39
  "@tramvai/safe-strings": "0.7.2",
40
- "@tramvai/tokens-child-app": "4.26.9"
40
+ "@tramvai/tokens-child-app": "4.29.1"
41
41
  },
42
42
  "devDependencies": {},
43
43
  "peerDependencies": {
44
44
  "@tinkoff/dippy": "0.10.8",
45
- "@tinkoff/router": "0.4.89",
45
+ "@tinkoff/router": "0.4.94",
46
46
  "@tinkoff/utils": "^2.1.2",
47
- "@tramvai/core": "4.26.9",
48
- "@tramvai/state": "4.26.9",
49
- "@tramvai/react": "4.26.9",
50
- "@tramvai/tokens-common": "4.26.9",
51
- "@tramvai/tokens-render": "4.26.9",
52
- "@tramvai/tokens-router": "4.26.9",
47
+ "@tramvai/core": "4.29.1",
48
+ "@tramvai/state": "4.29.1",
49
+ "@tramvai/react": "4.29.1",
50
+ "@tramvai/tokens-common": "4.29.1",
51
+ "@tramvai/tokens-render": "4.29.1",
52
+ "@tramvai/tokens-router": "4.29.1",
53
53
  "react": ">=16.14.0",
54
54
  "react-dom": ">=16.14.0",
55
55
  "object-assign": "^4.1.1",