@module-federation/bridge-react 0.0.0-next-20241115035905 → 0.0.0-next-20241115100504

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 CHANGED
@@ -1,12 +1,13 @@
1
1
  # @module-federation/bridge-react
2
2
 
3
- ## 0.0.0-next-20241115035905
3
+ ## 0.0.0-next-20241115100504
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - @module-federation/runtime@0.0.0-next-20241115035905
8
- - @module-federation/sdk@0.0.0-next-20241115035905
9
- - @module-federation/bridge-shared@0.0.0-next-20241115035905
7
+ - c7dbc4b: feat: mount bridge api to module instance
8
+ - 0309fb5: fix: wrap try catch with react-router-dom path resolve
9
+ - @module-federation/sdk@0.0.0-next-20241115100504
10
+ - @module-federation/bridge-shared@0.0.0-next-20241115100504
10
11
 
11
12
  ## 0.7.4
12
13
 
package/dist/index..js ADDED
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const plugin = require("./plugin-CfJaHqe4.cjs");
4
+ exports.BridgeReactPlugin = plugin.BridgeReactPlugin;
5
+ exports.createBridgeComponent = plugin.createBridgeComponent;
6
+ exports.createRemoteComponent = plugin.createRemoteComponent;
package/dist/index.d.ts CHANGED
@@ -2,9 +2,13 @@ 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/enhanced/runtime';
6
+ import { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
5
7
  import { PropsWithChildren } from 'react';
6
8
  import * as React_2 from 'react';
7
9
 
10
+ export declare function BridgeReactPlugin(): FederationRuntimePlugin;
11
+
8
12
  export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => {
9
13
  render(info: RenderParams): Promise<void>;
10
14
  destroy(info: DestroyParams): Promise<void>;
@@ -12,12 +16,7 @@ export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>
12
16
  __BRIDGE_FN__: (_args: T) => void;
13
17
  };
14
18
 
15
- export declare function createRemoteComponent<T, E extends keyof T>(info: {
16
- loader: () => Promise<T>;
17
- loading: default_2.ReactNode;
18
- fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
19
- export?: E;
20
- }): 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>>;
19
+ 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>>;
21
20
 
22
21
  declare type DestroyParams = {
23
22
  moduleName: string;
@@ -48,9 +47,18 @@ declare type FallbackProps = {
48
47
  resetErrorBoundary: (...args: any[]) => void;
49
48
  };
50
49
 
50
+ declare type LazyRemoteComponentInfo<T, E extends keyof T> = {
51
+ loader: () => Promise<T>;
52
+ loading: default_2.ReactNode;
53
+ fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
54
+ export?: E;
55
+ instance?: FederationHost;
56
+ };
57
+
51
58
  declare type ProviderFnParams<T> = {
52
59
  rootComponent: React_2.ComponentType<T>;
53
60
  render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
61
+ instance?: FederationHost;
54
62
  };
55
63
 
56
64
  export declare interface ProviderParams {
package/dist/index.es.js CHANGED
@@ -1,431 +1,6 @@
1
- import * as React from "react";
2
- import React__default, { createContext, Component, createElement, isValidElement, forwardRef, useRef, useEffect, useContext, useState } from "react";
3
- import { L as LoggerInstance, g as getRootDomDefaultClassName, p as pathJoin, a as atLeastReact18, R as RouterContext } from "./context-CUbFnlO5.js";
4
- import * as ReactRouterDOM from "react-router-dom";
5
- import { getInstance } from "@module-federation/runtime";
6
- import ReactDOM from "react-dom";
7
- const ErrorBoundaryContext = createContext(null);
8
- const initialState = {
9
- didCatch: false,
10
- error: null
11
- };
12
- class ErrorBoundary extends Component {
13
- constructor(props) {
14
- super(props);
15
- this.resetErrorBoundary = this.resetErrorBoundary.bind(this);
16
- this.state = initialState;
17
- }
18
- static getDerivedStateFromError(error) {
19
- return {
20
- didCatch: true,
21
- error
22
- };
23
- }
24
- resetErrorBoundary() {
25
- const {
26
- error
27
- } = this.state;
28
- if (error !== null) {
29
- var _this$props$onReset, _this$props;
30
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
31
- args[_key] = arguments[_key];
32
- }
33
- (_this$props$onReset = (_this$props = this.props).onReset) === null || _this$props$onReset === void 0 ? void 0 : _this$props$onReset.call(_this$props, {
34
- args,
35
- reason: "imperative-api"
36
- });
37
- this.setState(initialState);
38
- }
39
- }
40
- componentDidCatch(error, info) {
41
- var _this$props$onError, _this$props2;
42
- (_this$props$onError = (_this$props2 = this.props).onError) === null || _this$props$onError === void 0 ? void 0 : _this$props$onError.call(_this$props2, error, info);
43
- }
44
- componentDidUpdate(prevProps, prevState) {
45
- const {
46
- didCatch
47
- } = this.state;
48
- const {
49
- resetKeys
50
- } = this.props;
51
- if (didCatch && prevState.error !== null && hasArrayChanged(prevProps.resetKeys, resetKeys)) {
52
- var _this$props$onReset2, _this$props3;
53
- (_this$props$onReset2 = (_this$props3 = this.props).onReset) === null || _this$props$onReset2 === void 0 ? void 0 : _this$props$onReset2.call(_this$props3, {
54
- next: resetKeys,
55
- prev: prevProps.resetKeys,
56
- reason: "keys"
57
- });
58
- this.setState(initialState);
59
- }
60
- }
61
- render() {
62
- const {
63
- children,
64
- fallbackRender,
65
- FallbackComponent,
66
- fallback
67
- } = this.props;
68
- const {
69
- didCatch,
70
- error
71
- } = this.state;
72
- let childToRender = children;
73
- if (didCatch) {
74
- const props = {
75
- error,
76
- resetErrorBoundary: this.resetErrorBoundary
77
- };
78
- if (typeof fallbackRender === "function") {
79
- childToRender = fallbackRender(props);
80
- } else if (FallbackComponent) {
81
- childToRender = createElement(FallbackComponent, props);
82
- } else if (fallback === null || isValidElement(fallback)) {
83
- childToRender = fallback;
84
- } else {
85
- throw error;
86
- }
87
- }
88
- return createElement(ErrorBoundaryContext.Provider, {
89
- value: {
90
- didCatch,
91
- error,
92
- resetErrorBoundary: this.resetErrorBoundary
93
- }
94
- }, childToRender);
95
- }
96
- }
97
- function hasArrayChanged() {
98
- let a = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
99
- let b = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
100
- return a.length !== b.length || a.some((item, index) => !Object.is(item, b[index]));
101
- }
102
- function e() {
103
- const t = new PopStateEvent("popstate", { state: window.history.state });
104
- window.dispatchEvent(t);
105
- }
106
- const RemoteAppWrapper = forwardRef(function(props, ref) {
107
- const RemoteApp2 = () => {
108
- LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props });
109
- const {
110
- moduleName,
111
- memoryRoute,
112
- basename,
113
- providerInfo,
114
- className,
115
- style,
116
- fallback,
117
- ...resProps
118
- } = props;
119
- const rootRef = ref && "current" in ref ? ref : useRef(null);
120
- const renderDom = useRef(null);
121
- const providerInfoRef = useRef(null);
122
- const hostInstance = getInstance();
123
- LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
124
- useEffect(() => {
125
- const renderTimeout = setTimeout(() => {
126
- var _a, _b, _c, _d, _e, _f;
127
- const providerReturn = providerInfo();
128
- providerInfoRef.current = providerReturn;
129
- let renderProps = {
130
- moduleName,
131
- dom: rootRef.current,
132
- basename,
133
- memoryRoute,
134
- fallback,
135
- ...resProps
136
- };
137
- renderDom.current = rootRef.current;
138
- LoggerInstance.log(
139
- `createRemoteComponent LazyComponent render >>>`,
140
- renderProps
141
- );
142
- LoggerInstance.log(
143
- `createRemoteComponent LazyComponent hostInstance >>>`,
144
- hostInstance
145
- );
146
- const beforeBridgeRenderRes = ((_c = (_b = (_a = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(
147
- renderProps
148
- )) || {};
149
- renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
150
- providerReturn.render(renderProps);
151
- (_f = (_e = (_d = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(
152
- renderProps
153
- );
154
- });
155
- return () => {
156
- clearTimeout(renderTimeout);
157
- setTimeout(() => {
158
- var _a, _b, _c, _d, _e, _f, _g, _h;
159
- if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) {
160
- LoggerInstance.log(
161
- `createRemoteComponent LazyComponent destroy >>>`,
162
- { moduleName, basename, dom: renderDom.current }
163
- );
164
- (_d = (_c = (_b = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
165
- moduleName,
166
- dom: renderDom.current,
167
- basename,
168
- memoryRoute,
169
- fallback,
170
- ...resProps
171
- });
172
- (_e = providerInfoRef.current) == null ? void 0 : _e.destroy({
173
- moduleName,
174
- dom: renderDom.current
175
- });
176
- (_h = (_g = (_f = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
177
- moduleName,
178
- dom: renderDom.current,
179
- basename,
180
- memoryRoute,
181
- fallback,
182
- ...resProps
183
- });
184
- }
185
- });
186
- };
187
- }, []);
188
- const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props == null ? void 0 : props.className}`;
189
- return /* @__PURE__ */ React__default.createElement(
190
- "div",
191
- {
192
- className: rootComponentClassName,
193
- style: props == null ? void 0 : props.style,
194
- ref: rootRef
195
- }
196
- );
197
- };
198
- RemoteApp2["__APP_VERSION__"] = "0.7.4";
199
- return /* @__PURE__ */ React__default.createElement(RemoteApp2, null);
200
- });
201
- function withRouterData(WrappedComponent) {
202
- const Component2 = forwardRef(function(props, ref) {
203
- var _a;
204
- let enableDispathPopstate = false;
205
- let routerContextVal;
206
- try {
207
- ReactRouterDOM.useLocation();
208
- enableDispathPopstate = true;
209
- } catch {
210
- enableDispathPopstate = false;
211
- }
212
- let basename = "/";
213
- if (!props.basename && enableDispathPopstate) {
214
- const ReactRouterDOMAny = ReactRouterDOM;
215
- const useRouteMatch = ReactRouterDOMAny["useRouteMatch"];
216
- const useHistory = ReactRouterDOMAny["useHistory"];
217
- const useHref = ReactRouterDOMAny["useHref"];
218
- const UNSAFE_RouteContext = ReactRouterDOMAny["UNSAFE_RouteContext"];
219
- if (UNSAFE_RouteContext) {
220
- if (useHref) {
221
- basename = useHref == null ? void 0 : useHref("/");
222
- }
223
- routerContextVal = useContext(UNSAFE_RouteContext);
224
- if (routerContextVal && routerContextVal.matches && routerContextVal.matches.length > 0) {
225
- const matchIndex = routerContextVal.matches.length - 1;
226
- const pathnameBase = routerContextVal.matches[matchIndex].pathnameBase;
227
- basename = pathJoin(basename, pathnameBase || "/");
228
- }
229
- } else {
230
- const match = useRouteMatch == null ? void 0 : useRouteMatch();
231
- if (useHistory) {
232
- const history = useHistory == null ? void 0 : useHistory();
233
- basename = (_a = history == null ? void 0 : history.createHref) == null ? void 0 : _a.call(history, { pathname: "/" });
234
- }
235
- if (match) {
236
- basename = pathJoin(basename, (match == null ? void 0 : match.path) || "/");
237
- }
238
- }
239
- }
240
- LoggerInstance.log(`createRemoteComponent withRouterData >>>`, {
241
- ...props,
242
- basename,
243
- routerContextVal,
244
- enableDispathPopstate
245
- });
246
- if (enableDispathPopstate) {
247
- const location = ReactRouterDOM.useLocation();
248
- const [pathname, setPathname] = useState(location.pathname);
249
- useEffect(() => {
250
- if (pathname !== "" && pathname !== location.pathname) {
251
- LoggerInstance.log(`createRemoteComponent dispatchPopstateEnv >>>`, {
252
- name: props.name,
253
- pathname: location.pathname
254
- });
255
- e();
256
- }
257
- setPathname(location.pathname);
258
- }, [location]);
259
- }
260
- return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename, ref });
261
- });
262
- return forwardRef(function(props, ref) {
263
- return /* @__PURE__ */ React__default.createElement(Component2, { ...props, ref });
264
- });
265
- }
266
- const RemoteApp = withRouterData(RemoteAppWrapper);
267
- function createLazyRemoteComponent(info) {
268
- const exportName = (info == null ? void 0 : info.export) || "default";
269
- return React__default.lazy(async () => {
270
- LoggerInstance.log(`createRemoteComponent LazyComponent create >>>`, {
271
- lazyComponent: info.loader,
272
- exportName
273
- });
274
- try {
275
- const m2 = await info.loader();
276
- const moduleName = m2 && m2[Symbol.for("mf_module_id")];
277
- LoggerInstance.log(
278
- `createRemoteComponent LazyComponent loadRemote info >>>`,
279
- { name: moduleName, module: m2, exportName }
280
- );
281
- const exportFn = m2[exportName];
282
- if (exportName in m2 && typeof exportFn === "function") {
283
- const RemoteAppComponent = forwardRef((props, ref) => {
284
- return /* @__PURE__ */ React__default.createElement(
285
- RemoteApp,
286
- {
287
- moduleName,
288
- providerInfo: exportFn,
289
- exportName: info.export || "default",
290
- fallback: info.fallback,
291
- ref,
292
- ...props
293
- }
294
- );
295
- });
296
- return {
297
- default: RemoteAppComponent
298
- };
299
- } else {
300
- LoggerInstance.log(
301
- `createRemoteComponent LazyComponent module not found >>>`,
302
- { name: moduleName, module: m2, exportName }
303
- );
304
- throw Error(
305
- `Make sure that ${moduleName} has the correct export when export is ${String(
306
- exportName
307
- )}`
308
- );
309
- }
310
- } catch (error) {
311
- throw error;
312
- }
313
- });
314
- }
315
- function createRemoteComponent(info) {
316
- return forwardRef(
317
- (props, ref) => {
318
- const LazyComponent = createLazyRemoteComponent(info);
319
- 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 })));
320
- }
321
- );
322
- }
323
- var client = {};
324
- var m = ReactDOM;
325
- if (process.env.NODE_ENV === "production") {
326
- client.createRoot = m.createRoot;
327
- client.hydrateRoot = m.hydrateRoot;
328
- } else {
329
- var i = m.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
330
- client.createRoot = function(c, o) {
331
- i.usingClientEntryPoint = true;
332
- try {
333
- return m.createRoot(c, o);
334
- } finally {
335
- i.usingClientEntryPoint = false;
336
- }
337
- };
338
- client.hydrateRoot = function(c, h, o) {
339
- i.usingClientEntryPoint = true;
340
- try {
341
- return m.hydrateRoot(c, h, o);
342
- } finally {
343
- i.usingClientEntryPoint = false;
344
- }
345
- };
346
- }
347
- function createBridgeComponent(bridgeInfo) {
348
- return () => {
349
- const rootMap = /* @__PURE__ */ new Map();
350
- const instance = getInstance();
351
- LoggerInstance.log(`createBridgeComponent remote instance`, instance);
352
- const RawComponent = (info) => {
353
- const { appInfo, propsInfo, ...restProps } = info;
354
- const { moduleName, memoryRoute, basename = "/" } = appInfo;
355
- return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { moduleName, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(
356
- bridgeInfo.rootComponent,
357
- {
358
- ...propsInfo,
359
- basename,
360
- ...restProps
361
- }
362
- ));
363
- };
364
- return {
365
- async render(info) {
366
- var _a, _b, _c, _d, _e, _f;
367
- LoggerInstance.log(`createBridgeComponent render Info`, info);
368
- const {
369
- moduleName,
370
- dom,
371
- basename,
372
- memoryRoute,
373
- fallback,
374
- ...propsInfo
375
- } = info;
376
- const beforeBridgeRenderRes = ((_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(info)) || {};
377
- const rootComponentWithErrorBoundary = (
378
- // set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
379
- /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement(
380
- RawComponent,
381
- {
382
- appInfo: {
383
- moduleName,
384
- basename,
385
- memoryRoute
386
- },
387
- propsInfo: { ...propsInfo, ...beforeBridgeRenderRes == null ? void 0 : beforeBridgeRenderRes.extraProps }
388
- }
389
- ))
390
- );
391
- if (atLeastReact18(React)) {
392
- if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
393
- Promise.resolve(
394
- bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom)
395
- ).then((root) => rootMap.set(info.dom, root));
396
- } else {
397
- const root = client.createRoot(info.dom);
398
- root.render(rootComponentWithErrorBoundary);
399
- rootMap.set(info.dom, root);
400
- }
401
- } else {
402
- const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
403
- renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom);
404
- }
405
- ((_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(info)) || {};
406
- },
407
- async destroy(info) {
408
- var _a, _b, _c, _d, _e, _f;
409
- LoggerInstance.log(`createBridgeComponent destroy Info`, {
410
- dom: info.dom
411
- });
412
- (_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeDestroy) == null ? void 0 : _c.emit(info);
413
- if (atLeastReact18(React)) {
414
- const root = rootMap.get(info.dom);
415
- root == null ? void 0 : root.unmount();
416
- rootMap.delete(info.dom);
417
- } else {
418
- ReactDOM.unmountComponentAtNode(info.dom);
419
- }
420
- (_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeDestroy) == null ? void 0 : _f.emit(info);
421
- },
422
- rawComponent: bridgeInfo.rootComponent,
423
- __BRIDGE_FN__: (_args) => {
424
- }
425
- };
426
- };
427
- }
1
+ import { B, a, c } from "./plugin-qjDRExZS.js";
428
2
  export {
429
- createBridgeComponent,
430
- createRemoteComponent
3
+ B as BridgeReactPlugin,
4
+ a as createBridgeComponent,
5
+ c as createRemoteComponent
431
6
  };
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
2
  const React = require("react");
4
3
  const context = require("./context-BcJ-YlNr.cjs");
5
4
  const ReactRouterDOM = require("react-router-dom");
6
- const runtime = require("@module-federation/runtime");
7
5
  const ReactDOM = require("react-dom");
8
6
  function _interopNamespaceDefault(e2) {
9
7
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
@@ -133,13 +131,13 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
133
131
  className,
134
132
  style,
135
133
  fallback,
134
+ instance,
136
135
  ...resProps
137
136
  } = props;
138
137
  const rootRef = ref && "current" in ref ? ref : React.useRef(null);
139
138
  const renderDom = React.useRef(null);
140
139
  const providerInfoRef = React.useRef(null);
141
- const hostInstance = runtime.getInstance();
142
- context.LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);
140
+ context.LoggerInstance.log(`RemoteAppWrapper instance from props >>>`, instance);
143
141
  React.useEffect(() => {
144
142
  const renderTimeout = setTimeout(() => {
145
143
  var _a, _b, _c, _d, _e, _f;
@@ -160,16 +158,14 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
160
158
  );
161
159
  context.LoggerInstance.log(
162
160
  `createRemoteComponent LazyComponent hostInstance >>>`,
163
- hostInstance
161
+ instance
164
162
  );
165
- const beforeBridgeRenderRes = ((_c = (_b = (_a = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(
163
+ const beforeBridgeRenderRes = ((_c = (_b = (_a = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _a.lifecycle) == null ? void 0 : _b.beforeBridgeRender) == null ? void 0 : _c.emit(
166
164
  renderProps
167
165
  )) || {};
168
166
  renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
169
167
  providerReturn.render(renderProps);
170
- (_f = (_e = (_d = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(
171
- renderProps
172
- );
168
+ (_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeRender) == null ? void 0 : _f.emit(renderProps);
173
169
  });
174
170
  return () => {
175
171
  clearTimeout(renderTimeout);
@@ -180,7 +176,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
180
176
  `createRemoteComponent LazyComponent destroy >>>`,
181
177
  { moduleName, basename, dom: renderDom.current }
182
178
  );
183
- (_d = (_c = (_b = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
179
+ (_d = (_c = (_b = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _b.lifecycle) == null ? void 0 : _c.beforeBridgeDestroy) == null ? void 0 : _d.emit({
184
180
  moduleName,
185
181
  dom: renderDom.current,
186
182
  basename,
@@ -192,7 +188,7 @@ const RemoteAppWrapper = React.forwardRef(function(props, ref) {
192
188
  moduleName,
193
189
  dom: renderDom.current
194
190
  });
195
- (_h = (_g = (_f = hostInstance == null ? void 0 : hostInstance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
191
+ (_h = (_g = (_f = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _f.lifecycle) == null ? void 0 : _g.afterBridgeDestroy) == null ? void 0 : _h.emit({
196
192
  moduleName,
197
193
  dom: renderDom.current,
198
194
  basename,
@@ -308,6 +304,7 @@ function createLazyRemoteComponent(info) {
308
304
  exportName: info.export || "default",
309
305
  fallback: info.fallback,
310
306
  ref,
307
+ instance: info.instance,
311
308
  ...props
312
309
  }
313
310
  );
@@ -366,8 +363,11 @@ if (process.env.NODE_ENV === "production") {
366
363
  function createBridgeComponent(bridgeInfo) {
367
364
  return () => {
368
365
  const rootMap = /* @__PURE__ */ new Map();
369
- const instance = runtime.getInstance();
370
- context.LoggerInstance.log(`createBridgeComponent remote instance`, instance);
366
+ const { instance } = bridgeInfo;
367
+ context.LoggerInstance.log(
368
+ `createBridgeComponent instance from props >>>`,
369
+ instance
370
+ );
371
371
  const RawComponent = (info) => {
372
372
  const { appInfo, propsInfo, ...restProps } = info;
373
373
  const { moduleName, memoryRoute, basename = "/" } = appInfo;
@@ -436,7 +436,9 @@ function createBridgeComponent(bridgeInfo) {
436
436
  } else {
437
437
  ReactDOM.unmountComponentAtNode(info.dom);
438
438
  }
439
- (_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeDestroy) == null ? void 0 : _f.emit(info);
439
+ (_f = (_e = (_d = instance == null ? void 0 : instance.bridgeHook) == null ? void 0 : _d.lifecycle) == null ? void 0 : _e.afterBridgeDestroy) == null ? void 0 : _f.emit(
440
+ info
441
+ );
440
442
  },
441
443
  rawComponent: bridgeInfo.rootComponent,
442
444
  __BRIDGE_FN__: (_args) => {
@@ -444,5 +446,28 @@ function createBridgeComponent(bridgeInfo) {
444
446
  };
445
447
  };
446
448
  }
449
+ function BridgeReactPlugin() {
450
+ return {
451
+ name: "bridge-react-plugin",
452
+ beforeInit(args) {
453
+ const originalCreateRemoteComponent = createRemoteComponent;
454
+ args.origin.createRemoteComponent = function(info) {
455
+ return originalCreateRemoteComponent({
456
+ ...info,
457
+ instance: args.origin
458
+ });
459
+ };
460
+ const originalCreateBridgeComponentt = createBridgeComponent;
461
+ args.origin.createBridgeComponent = function(info) {
462
+ return originalCreateBridgeComponentt({
463
+ ...info,
464
+ instance: args.origin
465
+ });
466
+ };
467
+ return args;
468
+ }
469
+ };
470
+ }
471
+ exports.BridgeReactPlugin = BridgeReactPlugin;
447
472
  exports.createBridgeComponent = createBridgeComponent;
448
473
  exports.createRemoteComponent = createRemoteComponent;