@module-federation/bridge-react
Advanced tools
Comparing version 0.0.0-next-20240822101913 to 0.0.0-next-20240823062237
# @module-federation/bridge-react | ||
## 0.0.0-next-20240822101913 | ||
## 0.0.0-next-20240823062237 | ||
### Patch Changes | ||
- 3082116: feat: support module isolated reported | ||
- @module-federation/bridge-shared@0.0.0-next-20240822101913 | ||
- @module-federation/bridge-shared@0.0.0-next-20240823062237 | ||
@@ -10,0 +9,0 @@ ## 0.5.1 |
@@ -330,3 +330,2 @@ "use strict"; | ||
function createBridgeComponent(bridgeInfo) { | ||
let provider; | ||
return () => { | ||
@@ -346,61 +345,58 @@ const rootMap = /* @__PURE__ */ new Map(); | ||
}; | ||
if (!provider) { | ||
provider = { | ||
async render(info) { | ||
context.LoggerInstance.log(`createBridgeComponent render Info`, info); | ||
const { | ||
moduleName, | ||
dom, | ||
basename, | ||
memoryRoute, | ||
fallback, | ||
...propsInfo | ||
} = info; | ||
const rootComponentWithErrorBoundary = ( | ||
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error | ||
/* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement( | ||
RawComponent, | ||
{ | ||
appInfo: { | ||
moduleName, | ||
basename, | ||
memoryRoute | ||
}, | ||
propsInfo | ||
} | ||
)) | ||
); | ||
if (context.atLeastReact18(React__namespace)) { | ||
if (bridgeInfo == null ? void 0 : bridgeInfo.render) { | ||
Promise.resolve( | ||
bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom) | ||
).then((root) => rootMap.set(info.dom, root)); | ||
} else { | ||
const root = client.createRoot(info.dom); | ||
root.render(rootComponentWithErrorBoundary); | ||
rootMap.set(info.dom, root); | ||
return { | ||
async render(info) { | ||
context.LoggerInstance.log(`createBridgeComponent render Info`, info); | ||
const { | ||
moduleName, | ||
dom, | ||
basename, | ||
memoryRoute, | ||
fallback, | ||
...propsInfo | ||
} = info; | ||
const rootComponentWithErrorBoundary = ( | ||
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error | ||
/* @__PURE__ */ React__namespace.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React__namespace.createElement( | ||
RawComponent, | ||
{ | ||
appInfo: { | ||
moduleName, | ||
basename, | ||
memoryRoute | ||
}, | ||
propsInfo | ||
} | ||
)) | ||
); | ||
if (context.atLeastReact18(React__namespace)) { | ||
if (bridgeInfo == null ? void 0 : bridgeInfo.render) { | ||
Promise.resolve( | ||
bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom) | ||
).then((root) => rootMap.set(info.dom, root)); | ||
} else { | ||
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render; | ||
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom); | ||
const root = client.createRoot(info.dom); | ||
root.render(rootComponentWithErrorBoundary); | ||
rootMap.set(info.dom, root); | ||
} | ||
}, | ||
async destroy(info) { | ||
context.LoggerInstance.log(`createBridgeComponent destroy Info`, { | ||
dom: info.dom | ||
}); | ||
if (context.atLeastReact18(React__namespace)) { | ||
const root = rootMap.get(info.dom); | ||
root == null ? void 0 : root.unmount(); | ||
rootMap.delete(info.dom); | ||
} else { | ||
ReactDOM.unmountComponentAtNode(info.dom); | ||
} | ||
}, | ||
rawComponent: bridgeInfo.rootComponent, | ||
__BRIDGE_FN__: (_args) => { | ||
} else { | ||
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render; | ||
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom); | ||
} | ||
}; | ||
} | ||
return provider; | ||
}, | ||
async destroy(info) { | ||
context.LoggerInstance.log(`createBridgeComponent destroy Info`, { | ||
dom: info.dom | ||
}); | ||
if (context.atLeastReact18(React__namespace)) { | ||
const root = rootMap.get(info.dom); | ||
root == null ? void 0 : root.unmount(); | ||
rootMap.delete(info.dom); | ||
} else { | ||
ReactDOM.unmountComponentAtNode(info.dom); | ||
} | ||
}, | ||
rawComponent: bridgeInfo.rootComponent, | ||
__BRIDGE_FN__: (_args) => { | ||
} | ||
}; | ||
}; | ||
@@ -407,0 +403,0 @@ } |
@@ -8,3 +8,10 @@ import { ComponentType } from 'react'; | ||
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => Provider<T>; | ||
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => { | ||
render(info: RenderFnParams & any): Promise<void>; | ||
destroy(info: { | ||
dom: HTMLElement; | ||
}): Promise<void>; | ||
rawComponent: React_2.ComponentType<T>; | ||
__BRIDGE_FN__: (_args: T) => void; | ||
}; | ||
@@ -42,11 +49,2 @@ export declare function createRemoteComponent<T, E extends keyof T>(info: { | ||
declare type Provider<T> = { | ||
render(info: any): Promise<void>; | ||
destroy(info: { | ||
dom: HTMLElement; | ||
}): Promise<void>; | ||
rawComponent: React_2.ComponentType<T>; | ||
__BRIDGE_FN__: (_args: T) => void; | ||
}; | ||
declare type ProviderFnParams<T> = { | ||
@@ -53,0 +51,0 @@ rootComponent: React_2.ComponentType<T>; |
@@ -311,3 +311,2 @@ import * as React from "react"; | ||
function createBridgeComponent(bridgeInfo) { | ||
let provider; | ||
return () => { | ||
@@ -327,61 +326,58 @@ const rootMap = /* @__PURE__ */ new Map(); | ||
}; | ||
if (!provider) { | ||
provider = { | ||
async render(info) { | ||
LoggerInstance.log(`createBridgeComponent render Info`, info); | ||
const { | ||
moduleName, | ||
dom, | ||
basename, | ||
memoryRoute, | ||
fallback, | ||
...propsInfo | ||
} = info; | ||
const rootComponentWithErrorBoundary = ( | ||
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error | ||
/* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement( | ||
RawComponent, | ||
{ | ||
appInfo: { | ||
moduleName, | ||
basename, | ||
memoryRoute | ||
}, | ||
propsInfo | ||
} | ||
)) | ||
); | ||
if (atLeastReact18(React)) { | ||
if (bridgeInfo == null ? void 0 : bridgeInfo.render) { | ||
Promise.resolve( | ||
bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom) | ||
).then((root) => rootMap.set(info.dom, root)); | ||
} else { | ||
const root = client.createRoot(info.dom); | ||
root.render(rootComponentWithErrorBoundary); | ||
rootMap.set(info.dom, root); | ||
return { | ||
async render(info) { | ||
LoggerInstance.log(`createBridgeComponent render Info`, info); | ||
const { | ||
moduleName, | ||
dom, | ||
basename, | ||
memoryRoute, | ||
fallback, | ||
...propsInfo | ||
} = info; | ||
const rootComponentWithErrorBoundary = ( | ||
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error | ||
/* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: fallback }, /* @__PURE__ */ React.createElement( | ||
RawComponent, | ||
{ | ||
appInfo: { | ||
moduleName, | ||
basename, | ||
memoryRoute | ||
}, | ||
propsInfo | ||
} | ||
)) | ||
); | ||
if (atLeastReact18(React)) { | ||
if (bridgeInfo == null ? void 0 : bridgeInfo.render) { | ||
Promise.resolve( | ||
bridgeInfo == null ? void 0 : bridgeInfo.render(rootComponentWithErrorBoundary, dom) | ||
).then((root) => rootMap.set(info.dom, root)); | ||
} else { | ||
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render; | ||
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom); | ||
const root = client.createRoot(info.dom); | ||
root.render(rootComponentWithErrorBoundary); | ||
rootMap.set(info.dom, root); | ||
} | ||
}, | ||
async destroy(info) { | ||
LoggerInstance.log(`createBridgeComponent destroy Info`, { | ||
dom: info.dom | ||
}); | ||
if (atLeastReact18(React)) { | ||
const root = rootMap.get(info.dom); | ||
root == null ? void 0 : root.unmount(); | ||
rootMap.delete(info.dom); | ||
} else { | ||
ReactDOM.unmountComponentAtNode(info.dom); | ||
} | ||
}, | ||
rawComponent: bridgeInfo.rootComponent, | ||
__BRIDGE_FN__: (_args) => { | ||
} else { | ||
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render; | ||
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom); | ||
} | ||
}; | ||
} | ||
return provider; | ||
}, | ||
async destroy(info) { | ||
LoggerInstance.log(`createBridgeComponent destroy Info`, { | ||
dom: info.dom | ||
}); | ||
if (atLeastReact18(React)) { | ||
const root = rootMap.get(info.dom); | ||
root == null ? void 0 : root.unmount(); | ||
rootMap.delete(info.dom); | ||
} else { | ||
ReactDOM.unmountComponentAtNode(info.dom); | ||
} | ||
}, | ||
rawComponent: bridgeInfo.rootComponent, | ||
__BRIDGE_FN__: (_args) => { | ||
} | ||
}; | ||
}; | ||
@@ -388,0 +384,0 @@ } |
{ | ||
"name": "@module-federation/bridge-react", | ||
"version": "0.0.0-next-20240822101913", | ||
"version": "0.0.0-next-20240823062237", | ||
"publishConfig": { | ||
@@ -38,3 +38,3 @@ "access": "public" | ||
"react-error-boundary": "^4.0.13", | ||
"@module-federation/bridge-shared": "0.0.0-next-20240822101913" | ||
"@module-federation/bridge-shared": "0.0.0-next-20240823062237" | ||
}, | ||
@@ -41,0 +41,0 @@ "peerDependencies": { |
Sorry, the diff of this file is not supported yet
87552
2369
+ Added@module-federation/bridge-shared@0.0.0-next-20240823062237(transitive)
- Removed@module-federation/bridge-shared@0.0.0-next-20240822101913(transitive)
Updated@module-federation/bridge-shared@0.0.0-next-20240823062237