@module-federation/bridge-react 0.0.0-next-20241119071808 → 0.0.0-next-20241120032055
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/CHANGELOG.md +3 -3
- package/dist/index.cjs.js +12 -25
- package/dist/index.d.ts +2 -16
- package/dist/index.es.js +11 -26
- package/dist/plugin.cjs.js +13 -2
- package/dist/plugin.d.ts +7 -0
- package/dist/plugin.es.js +12 -2
- package/package.json +4 -4
- package/src/create.tsx +0 -13
- package/src/index.ts +2 -21
- package/src/plugin.ts +19 -1
- package/src/provider.tsx +3 -12
- package/src/remote/index.tsx +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# @module-federation/bridge-react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-next-
|
|
3
|
+
## 0.0.0-next-20241120032055
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
7
|
- c7dbc4b: feat: mount bridge api to module instance
|
|
8
8
|
- 0309fb5: fix: wrap try catch with react-router-dom path resolve
|
|
9
|
-
- @module-federation/sdk@0.0.0-next-
|
|
10
|
-
- @module-federation/bridge-shared@0.0.0-next-
|
|
9
|
+
- @module-federation/sdk@0.0.0-next-20241120032055
|
|
10
|
+
- @module-federation/bridge-shared@0.0.0-next-20241120032055
|
|
11
11
|
|
|
12
12
|
## 0.7.4
|
|
13
13
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
3
3
|
const React = require("react");
|
|
4
4
|
const context = require("./context-BcJ-YlNr.cjs");
|
|
5
5
|
const ReactRouterDOM = require("react-router-dom");
|
|
6
|
+
const plugin = require("./plugin.cjs.js");
|
|
6
7
|
const ReactDOM = require("react-dom");
|
|
7
8
|
function _interopNamespaceDefault(e2) {
|
|
8
9
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
@@ -132,9 +133,9 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
|
|
|
132
133
|
className,
|
|
133
134
|
style,
|
|
134
135
|
fallback,
|
|
135
|
-
instance,
|
|
136
136
|
...resProps
|
|
137
137
|
} = props;
|
|
138
|
+
const instance = plugin.federationRuntime.instance;
|
|
138
139
|
const rootRef = ref && "current" in ref ? ref : React.useRef(null);
|
|
139
140
|
const renderDom = React.useRef(null);
|
|
140
141
|
const providerInfoRef = React.useRef(null);
|
|
@@ -305,7 +306,6 @@ function createLazyRemoteComponent(info) {
|
|
|
305
306
|
exportName: info.export || "default",
|
|
306
307
|
fallback: info.fallback,
|
|
307
308
|
ref,
|
|
308
|
-
instance: info.instance,
|
|
309
309
|
...props
|
|
310
310
|
}
|
|
311
311
|
);
|
|
@@ -329,10 +329,13 @@ function createLazyRemoteComponent(info) {
|
|
|
329
329
|
}
|
|
330
330
|
});
|
|
331
331
|
}
|
|
332
|
-
function
|
|
333
|
-
return (
|
|
334
|
-
|
|
335
|
-
|
|
332
|
+
function createRemoteComponent(info) {
|
|
333
|
+
return React.forwardRef(
|
|
334
|
+
(props, ref) => {
|
|
335
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
336
|
+
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref })));
|
|
337
|
+
}
|
|
338
|
+
);
|
|
336
339
|
}
|
|
337
340
|
var client = {};
|
|
338
341
|
var m = ReactDOM;
|
|
@@ -361,7 +364,7 @@ if (process.env.NODE_ENV === "production") {
|
|
|
361
364
|
function createBridgeComponent(bridgeInfo) {
|
|
362
365
|
return () => {
|
|
363
366
|
const rootMap = /* @__PURE__ */ new Map();
|
|
364
|
-
const
|
|
367
|
+
const instance = plugin.federationRuntime.instance;
|
|
365
368
|
context.LoggerInstance.log(
|
|
366
369
|
`createBridgeComponent instance from props >>>`,
|
|
367
370
|
instance
|
|
@@ -444,21 +447,5 @@ function createBridgeComponent(bridgeInfo) {
|
|
|
444
447
|
};
|
|
445
448
|
};
|
|
446
449
|
}
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
return createBridgeComponent({ ...bridgeInfo, instance });
|
|
450
|
-
};
|
|
451
|
-
}
|
|
452
|
-
exports.createRemoteComponent = void 0;
|
|
453
|
-
exports.createBridgeComponent = void 0;
|
|
454
|
-
function BridgeReactPlugin() {
|
|
455
|
-
return {
|
|
456
|
-
name: "bridge-react-plugin",
|
|
457
|
-
beforeInit(args) {
|
|
458
|
-
exports.createRemoteComponent = createRemoteComponentWithInstance(args.origin);
|
|
459
|
-
exports.createBridgeComponent = createBridgeComponentWithInstance(args.origin);
|
|
460
|
-
return args;
|
|
461
|
-
}
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
exports.BridgeReactPlugin = BridgeReactPlugin;
|
|
450
|
+
exports.createBridgeComponent = createBridgeComponent;
|
|
451
|
+
exports.createRemoteComponent = createRemoteComponent;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,29 +2,17 @@ import { ComponentType } from 'react';
|
|
|
2
2
|
import { default as default_2 } from 'react';
|
|
3
3
|
import { default as default_3 } from 'react-dom/client';
|
|
4
4
|
import { ErrorInfo } from 'react';
|
|
5
|
-
import { FederationHost } from '@module-federation/runtime';
|
|
6
|
-
import { FederationRuntimePlugin } from '@module-federation/runtime';
|
|
7
5
|
import { PropsWithChildren } from 'react';
|
|
8
6
|
import * as React_2 from 'react';
|
|
9
7
|
|
|
10
|
-
export declare function
|
|
11
|
-
|
|
12
|
-
declare type CreateBridgeComponent = typeof createBridgeComponent_2;
|
|
13
|
-
|
|
14
|
-
export declare let createBridgeComponent: CreateBridgeComponent;
|
|
15
|
-
|
|
16
|
-
declare function createBridgeComponent_2<T>(bridgeInfo: ProviderFnParams<T>): () => {
|
|
8
|
+
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
|
|
17
9
|
render(info: RenderParams): Promise<void>;
|
|
18
10
|
destroy(info: DestroyParams): Promise<void>;
|
|
19
11
|
rawComponent: React_2.ComponentType<T>;
|
|
20
12
|
__BRIDGE_FN__: (_args: T) => void;
|
|
21
13
|
};
|
|
22
14
|
|
|
23
|
-
declare
|
|
24
|
-
|
|
25
|
-
export declare let createRemoteComponent: CreateRemoteComponent;
|
|
26
|
-
|
|
27
|
-
declare function createRemoteComponent_2<T, E extends keyof T>(info: LazyRemoteComponentInfo<T, E>): default_2.ForwardRefExoticComponent<default_2.PropsWithoutRef<ProviderParams & ("__BRIDGE_FN__" extends keyof (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never) ? (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"] extends (...args: any) => any ? Parameters<(T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"]>[0] : {} : {})> & default_2.RefAttributes<HTMLDivElement>>;
|
|
15
|
+
export declare function createRemoteComponent<T, E extends keyof T>(info: LazyRemoteComponentInfo<T, E>): default_2.ForwardRefExoticComponent<default_2.PropsWithoutRef<ProviderParams & ("__BRIDGE_FN__" extends keyof (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never) ? (T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"] extends (...args: any) => any ? Parameters<(T[E] extends (...args: any) => any ? ReturnType<T[E]> : never)["__BRIDGE_FN__"]>[0] : {} : {})> & default_2.RefAttributes<HTMLDivElement>>;
|
|
28
16
|
|
|
29
17
|
declare type DestroyParams = {
|
|
30
18
|
moduleName: string;
|
|
@@ -60,13 +48,11 @@ declare type LazyRemoteComponentInfo<T, E extends keyof T> = {
|
|
|
60
48
|
loading: default_2.ReactNode;
|
|
61
49
|
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
62
50
|
export?: E;
|
|
63
|
-
instance?: FederationHost;
|
|
64
51
|
};
|
|
65
52
|
|
|
66
53
|
declare type ProviderFnParams<T> = {
|
|
67
54
|
rootComponent: React_2.ComponentType<T>;
|
|
68
55
|
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
69
|
-
instance?: FederationHost;
|
|
70
56
|
};
|
|
71
57
|
|
|
72
58
|
export declare interface ProviderParams {
|
package/dist/index.es.js
CHANGED
|
@@ -2,6 +2,7 @@ import * as React from "react";
|
|
|
2
2
|
import React__default, { createContext, Component, createElement, isValidElement, forwardRef, useRef, useEffect, useContext, useState } from "react";
|
|
3
3
|
import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin, a as atLeastReact18, R as RouterContext } from "./context-CUbFnlO5.js";
|
|
4
4
|
import * as ReactRouterDOM from "react-router-dom";
|
|
5
|
+
import { federationRuntime } from "./plugin.es.js";
|
|
5
6
|
import ReactDOM from "react-dom";
|
|
6
7
|
const ErrorBoundaryContext = createContext(null);
|
|
7
8
|
const initialState = {
|
|
@@ -113,9 +114,9 @@ const RemoteAppWrapper = forwardRef(function(props, ref) {
|
|
|
113
114
|
className,
|
|
114
115
|
style,
|
|
115
116
|
fallback,
|
|
116
|
-
instance,
|
|
117
117
|
...resProps
|
|
118
118
|
} = props;
|
|
119
|
+
const instance = federationRuntime.instance;
|
|
119
120
|
const rootRef = ref && "current" in ref ? ref : useRef(null);
|
|
120
121
|
const renderDom = useRef(null);
|
|
121
122
|
const providerInfoRef = useRef(null);
|
|
@@ -286,7 +287,6 @@ function createLazyRemoteComponent(info) {
|
|
|
286
287
|
exportName: info.export || "default",
|
|
287
288
|
fallback: info.fallback,
|
|
288
289
|
ref,
|
|
289
|
-
instance: info.instance,
|
|
290
290
|
...props
|
|
291
291
|
}
|
|
292
292
|
);
|
|
@@ -310,10 +310,13 @@ function createLazyRemoteComponent(info) {
|
|
|
310
310
|
}
|
|
311
311
|
});
|
|
312
312
|
}
|
|
313
|
-
function
|
|
314
|
-
return (
|
|
315
|
-
|
|
316
|
-
|
|
313
|
+
function createRemoteComponent(info) {
|
|
314
|
+
return forwardRef(
|
|
315
|
+
(props, ref) => {
|
|
316
|
+
const LazyComponent = createLazyRemoteComponent(info);
|
|
317
|
+
return /* @__PURE__ */ React__default.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React__default.createElement(React__default.Suspense, { fallback: info.loading }, /* @__PURE__ */ React__default.createElement(LazyComponent, { ...props, ref })));
|
|
318
|
+
}
|
|
319
|
+
);
|
|
317
320
|
}
|
|
318
321
|
var client = {};
|
|
319
322
|
var m = ReactDOM;
|
|
@@ -339,10 +342,10 @@ if (process.env.NODE_ENV === "production") {
|
|
|
339
342
|
}
|
|
340
343
|
};
|
|
341
344
|
}
|
|
342
|
-
function createBridgeComponent
|
|
345
|
+
function createBridgeComponent(bridgeInfo) {
|
|
343
346
|
return () => {
|
|
344
347
|
const rootMap = /* @__PURE__ */ new Map();
|
|
345
|
-
const
|
|
348
|
+
const instance = federationRuntime.instance;
|
|
346
349
|
LoggerInstance.log(
|
|
347
350
|
`createBridgeComponent instance from props >>>`,
|
|
348
351
|
instance
|
|
@@ -425,25 +428,7 @@ function createBridgeComponent$1(bridgeInfo) {
|
|
|
425
428
|
};
|
|
426
429
|
};
|
|
427
430
|
}
|
|
428
|
-
function createBridgeComponentWithInstance(instance) {
|
|
429
|
-
return (bridgeInfo) => {
|
|
430
|
-
return createBridgeComponent$1({ ...bridgeInfo, instance });
|
|
431
|
-
};
|
|
432
|
-
}
|
|
433
|
-
let createRemoteComponent;
|
|
434
|
-
let createBridgeComponent;
|
|
435
|
-
function BridgeReactPlugin() {
|
|
436
|
-
return {
|
|
437
|
-
name: "bridge-react-plugin",
|
|
438
|
-
beforeInit(args) {
|
|
439
|
-
createRemoteComponent = createRemoteComponentWithInstance(args.origin);
|
|
440
|
-
createBridgeComponent = createBridgeComponentWithInstance(args.origin);
|
|
441
|
-
return args;
|
|
442
|
-
}
|
|
443
|
-
};
|
|
444
|
-
}
|
|
445
431
|
export {
|
|
446
|
-
BridgeReactPlugin,
|
|
447
432
|
createBridgeComponent,
|
|
448
433
|
createRemoteComponent
|
|
449
434
|
};
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const federationRuntime = { instance: null };
|
|
4
|
+
function BridgeReactPlugin() {
|
|
5
|
+
return {
|
|
6
|
+
name: "bridge-react-plugin",
|
|
7
|
+
beforeInit(args) {
|
|
8
|
+
federationRuntime.instance = args.origin;
|
|
9
|
+
return args;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
exports.default = BridgeReactPlugin;
|
|
14
|
+
exports.federationRuntime = federationRuntime;
|
package/dist/plugin.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { FederationHost } from '@module-federation/runtime';
|
|
1
2
|
import { FederationRuntimePlugin } from '@module-federation/runtime';
|
|
2
3
|
|
|
3
4
|
declare function BridgeReactPlugin(): FederationRuntimePlugin;
|
|
4
5
|
export default BridgeReactPlugin;
|
|
5
6
|
|
|
7
|
+
export declare const federationRuntime: FederationRuntimeType;
|
|
8
|
+
|
|
9
|
+
export declare type FederationRuntimeType = {
|
|
10
|
+
instance: FederationHost | null;
|
|
11
|
+
};
|
|
12
|
+
|
|
6
13
|
export { }
|
package/dist/plugin.es.js
CHANGED
|
@@ -1,4 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
const federationRuntime = { instance: null };
|
|
2
|
+
function BridgeReactPlugin() {
|
|
3
|
+
return {
|
|
4
|
+
name: "bridge-react-plugin",
|
|
5
|
+
beforeInit(args) {
|
|
6
|
+
federationRuntime.instance = args.origin;
|
|
7
|
+
return args;
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
}
|
|
2
11
|
export {
|
|
3
|
-
BridgeReactPlugin as default
|
|
12
|
+
BridgeReactPlugin as default,
|
|
13
|
+
federationRuntime
|
|
4
14
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/bridge-react",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20241120032055",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@loadable/component": "^5.16.4",
|
|
48
48
|
"react-error-boundary": "^4.0.13",
|
|
49
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
50
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
49
|
+
"@module-federation/bridge-shared": "0.0.0-next-20241120032055",
|
|
50
|
+
"@module-federation/sdk": "0.0.0-next-20241120032055"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
53
|
"react": ">=16.9.0",
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"typescript": "^5.2.2",
|
|
69
69
|
"vite": "^5.2.14",
|
|
70
70
|
"vite-plugin-dts": "^3.9.1",
|
|
71
|
-
"@module-federation/runtime": "0.0.0-next-
|
|
71
|
+
"@module-federation/runtime": "0.0.0-next-20241120032055"
|
|
72
72
|
},
|
|
73
73
|
"scripts": {
|
|
74
74
|
"dev": "vite",
|
package/src/create.tsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React, { forwardRef } from 'react';
|
|
2
|
-
import type { FederationHost } from '@module-federation/runtime';
|
|
3
2
|
import {
|
|
4
3
|
ErrorBoundary,
|
|
5
4
|
ErrorBoundaryPropsWithComponent,
|
|
@@ -24,7 +23,6 @@ type LazyRemoteComponentInfo<T, E extends keyof T> = {
|
|
|
24
23
|
loading: React.ReactNode;
|
|
25
24
|
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
26
25
|
export?: E;
|
|
27
|
-
instance?: FederationHost;
|
|
28
26
|
};
|
|
29
27
|
|
|
30
28
|
function createLazyRemoteComponent<T, E extends keyof T>(
|
|
@@ -64,7 +62,6 @@ function createLazyRemoteComponent<T, E extends keyof T>(
|
|
|
64
62
|
exportName={info.export || 'default'}
|
|
65
63
|
fallback={info.fallback}
|
|
66
64
|
ref={ref}
|
|
67
|
-
instance={info.instance}
|
|
68
65
|
{...props}
|
|
69
66
|
/>
|
|
70
67
|
);
|
|
@@ -116,13 +113,3 @@ export function createRemoteComponent<T, E extends keyof T>(
|
|
|
116
113
|
},
|
|
117
114
|
);
|
|
118
115
|
}
|
|
119
|
-
|
|
120
|
-
export function createRemoteComponentWithInstance<T, E extends keyof T>(
|
|
121
|
-
instance: FederationHost,
|
|
122
|
-
) {
|
|
123
|
-
return (info: LazyRemoteComponentInfo<T, E>) => {
|
|
124
|
-
return createLazyRemoteComponent({ ...info, instance });
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
export type CreateRemoteComponent = typeof createRemoteComponent;
|
package/src/index.ts
CHANGED
|
@@ -1,24 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { createBridgeComponentWithInstance } from './provider';
|
|
4
|
-
import type { CreateRemoteComponent } from './create';
|
|
5
|
-
import type { CreateBridgeComponent } from './provider';
|
|
6
|
-
|
|
7
|
-
let createRemoteComponent: CreateRemoteComponent;
|
|
8
|
-
let createBridgeComponent: CreateBridgeComponent;
|
|
9
|
-
function BridgeReactPlugin(): FederationRuntimePlugin {
|
|
10
|
-
return {
|
|
11
|
-
name: 'bridge-react-plugin',
|
|
12
|
-
beforeInit(args) {
|
|
13
|
-
// @ts-ignore
|
|
14
|
-
createRemoteComponent = createRemoteComponentWithInstance(args.origin);
|
|
15
|
-
createBridgeComponent = createBridgeComponentWithInstance(args.origin);
|
|
16
|
-
return args;
|
|
17
|
-
},
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export { BridgeReactPlugin, createRemoteComponent, createBridgeComponent };
|
|
1
|
+
export { createRemoteComponent } from './create';
|
|
2
|
+
export { createBridgeComponent } from './provider';
|
|
22
3
|
export type {
|
|
23
4
|
ProviderParams,
|
|
24
5
|
RenderFnParams,
|
package/src/plugin.ts
CHANGED
|
@@ -1,2 +1,20 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { FederationRuntimePlugin } from '@module-federation/runtime';
|
|
2
|
+
import type { FederationHost } from '@module-federation/runtime';
|
|
3
|
+
|
|
4
|
+
export type FederationRuntimeType = {
|
|
5
|
+
instance: FederationHost | null;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const federationRuntime: FederationRuntimeType = { instance: null };
|
|
9
|
+
|
|
10
|
+
function BridgeReactPlugin(): FederationRuntimePlugin {
|
|
11
|
+
return {
|
|
12
|
+
name: 'bridge-react-plugin',
|
|
13
|
+
beforeInit(args) {
|
|
14
|
+
federationRuntime.instance = args.origin;
|
|
15
|
+
return args;
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
|
|
2
20
|
export default BridgeReactPlugin;
|
package/src/provider.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import type {
|
|
|
9
9
|
import { ErrorBoundary } from 'react-error-boundary';
|
|
10
10
|
import { RouterContext } from './context';
|
|
11
11
|
import { LoggerInstance, atLeastReact18 } from './utils';
|
|
12
|
-
import
|
|
12
|
+
import { federationRuntime } from './plugin';
|
|
13
13
|
|
|
14
14
|
type RenderParams = RenderFnParams & {
|
|
15
15
|
[key: string]: unknown;
|
|
@@ -20,19 +20,18 @@ type DestroyParams = {
|
|
|
20
20
|
};
|
|
21
21
|
type RootType = HTMLElement | ReactDOMClient.Root;
|
|
22
22
|
|
|
23
|
-
type ProviderFnParams<T> = {
|
|
23
|
+
export type ProviderFnParams<T> = {
|
|
24
24
|
rootComponent: React.ComponentType<T>;
|
|
25
25
|
render?: (
|
|
26
26
|
App: React.ReactElement,
|
|
27
27
|
id?: HTMLElement | string,
|
|
28
28
|
) => RootType | Promise<RootType>;
|
|
29
|
-
instance?: FederationHost;
|
|
30
29
|
};
|
|
31
30
|
|
|
32
31
|
export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
|
|
33
32
|
return () => {
|
|
34
33
|
const rootMap = new Map<any, RootType>();
|
|
35
|
-
const
|
|
34
|
+
const instance = federationRuntime.instance;
|
|
36
35
|
LoggerInstance.log(
|
|
37
36
|
`createBridgeComponent instance from props >>>`,
|
|
38
37
|
instance,
|
|
@@ -134,11 +133,3 @@ export function ShadowRoot(info: { children: () => JSX.Element }) {
|
|
|
134
133
|
|
|
135
134
|
return <div ref={domRef}>{root && <info.children />}</div>;
|
|
136
135
|
}
|
|
137
|
-
|
|
138
|
-
export function createBridgeComponentWithInstance<T>(instance: FederationHost) {
|
|
139
|
-
return (bridgeInfo: ProviderFnParams<T>) => {
|
|
140
|
-
return createBridgeComponent({ ...bridgeInfo, instance });
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
export type CreateBridgeComponent = typeof createBridgeComponent;
|
package/src/remote/index.tsx
CHANGED
|
@@ -10,7 +10,7 @@ import type { ProviderParams } from '@module-federation/bridge-shared';
|
|
|
10
10
|
import { dispatchPopstateEnv } from '@module-federation/bridge-shared';
|
|
11
11
|
import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
|
|
12
12
|
import { LoggerInstance, pathJoin, getRootDomDefaultClassName } from '../utils';
|
|
13
|
-
import
|
|
13
|
+
import { federationRuntime } from '../plugin';
|
|
14
14
|
|
|
15
15
|
declare const __APP_VERSION__: string;
|
|
16
16
|
export interface RenderFnParams extends ProviderParams {
|
|
@@ -34,7 +34,6 @@ interface RemoteAppParams {
|
|
|
34
34
|
providerInfo: NonNullable<RemoteModule['provider']>;
|
|
35
35
|
exportName: string | number | symbol;
|
|
36
36
|
fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
|
|
37
|
-
instance: FederationHost;
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
const RemoteAppWrapper = forwardRef(function (
|
|
@@ -51,10 +50,10 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
51
50
|
className,
|
|
52
51
|
style,
|
|
53
52
|
fallback,
|
|
54
|
-
instance,
|
|
55
53
|
...resProps
|
|
56
54
|
} = props;
|
|
57
55
|
|
|
56
|
+
const instance = federationRuntime.instance;
|
|
58
57
|
const rootRef: React.MutableRefObject<HTMLDivElement | null> =
|
|
59
58
|
ref && 'current' in ref
|
|
60
59
|
? (ref as React.MutableRefObject<HTMLDivElement | null>)
|
|
@@ -62,6 +61,7 @@ const RemoteAppWrapper = forwardRef(function (
|
|
|
62
61
|
|
|
63
62
|
const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
|
|
64
63
|
const providerInfoRef = useRef<any>(null);
|
|
64
|
+
|
|
65
65
|
LoggerInstance.log(`RemoteAppWrapper instance from props >>>`, instance);
|
|
66
66
|
|
|
67
67
|
useEffect(() => {
|