@module-federation/bridge-react
Advanced tools
Comparing version 0.0.0-next-20240725030707 to 0.0.0-next-20240725035430
# @module-federation/bridge-react | ||
## 0.0.0-next-20240725030707 | ||
## 0.0.0-next-20240725035430 | ||
### Patch Changes | ||
- @module-federation/bridge-shared@0.0.0-next-20240725030707 | ||
- chore: bump next | ||
- @module-federation/bridge-shared@0.0.0-next-20240725035430 | ||
@@ -9,0 +10,0 @@ ## 0.3.1 |
@@ -120,51 +120,57 @@ "use strict"; | ||
} | ||
const RemoteApp = ({ | ||
name, | ||
memoryRoute, | ||
basename, | ||
providerInfo, | ||
...resProps | ||
}) => { | ||
const rootRef = React.useRef(null); | ||
const renderDom = React.useRef(null); | ||
const providerInfoRef = React.useRef(null); | ||
React.useEffect(() => { | ||
const renderTimeout = setTimeout(() => { | ||
const providerReturn = providerInfo(); | ||
providerInfoRef.current = providerReturn; | ||
const renderProps = { | ||
name, | ||
dom: rootRef.current, | ||
basename, | ||
memoryRoute, | ||
...resProps | ||
const RemoteAppWrapper = React.forwardRef(function(props, ref) { | ||
const RemoteApp2 = () => { | ||
const { | ||
name, | ||
memoryRoute, | ||
basename, | ||
providerInfo, | ||
className, | ||
style, | ||
...resProps | ||
} = props; | ||
const rootRef = ref && "current" in ref ? ref : React.useRef(null); | ||
const renderDom = React.useRef(null); | ||
const providerInfoRef = React.useRef(null); | ||
React.useEffect(() => { | ||
const renderTimeout = setTimeout(() => { | ||
const providerReturn = providerInfo(); | ||
providerInfoRef.current = providerReturn; | ||
const renderProps = { | ||
name, | ||
dom: rootRef.current, | ||
basename, | ||
memoryRoute, | ||
...resProps | ||
}; | ||
renderDom.current = rootRef.current; | ||
context.LoggerInstance.log( | ||
`createRemoteComponent LazyComponent render >>>`, | ||
renderProps | ||
); | ||
providerReturn.render(renderProps); | ||
}); | ||
return () => { | ||
clearTimeout(renderTimeout); | ||
setTimeout(() => { | ||
var _a, _b; | ||
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) { | ||
context.LoggerInstance.log( | ||
`createRemoteComponent LazyComponent destroy >>>`, | ||
{ name, basename, dom: renderDom.current } | ||
); | ||
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({ | ||
dom: renderDom.current | ||
}); | ||
} | ||
}); | ||
}; | ||
renderDom.current = rootRef.current; | ||
context.LoggerInstance.log( | ||
`createRemoteComponent LazyComponent render >>>`, | ||
renderProps | ||
); | ||
providerReturn.render(renderProps); | ||
}); | ||
return () => { | ||
clearTimeout(renderTimeout); | ||
setTimeout(() => { | ||
var _a, _b; | ||
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) { | ||
context.LoggerInstance.log( | ||
`createRemoteComponent LazyComponent destroy >>>`, | ||
{ name, basename, dom: renderDom.current } | ||
); | ||
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({ | ||
dom: renderDom.current | ||
}); | ||
} | ||
}); | ||
}; | ||
}, []); | ||
return /* @__PURE__ */ React.createElement("div", { ref: rootRef }); | ||
}; | ||
RemoteApp["__APP_VERSION__"] = "0.3.1"; | ||
}, []); | ||
return /* @__PURE__ */ React.createElement("div", { className, style, ref: rootRef }); | ||
}; | ||
RemoteApp2["__APP_VERSION__"] = "0.3.1"; | ||
return /* @__PURE__ */ React.createElement(RemoteApp2, null); | ||
}); | ||
function withRouterData(WrappedComponent) { | ||
return (props) => { | ||
const Component = React.forwardRef(function(props, ref) { | ||
var _a; | ||
@@ -227,6 +233,9 @@ let enableDispathPopstate = false; | ||
} | ||
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename }); | ||
}; | ||
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename, ref }); | ||
}); | ||
return React.forwardRef(function(props, ref) { | ||
return /* @__PURE__ */ React.createElement(Component, { ...props, ref }); | ||
}); | ||
} | ||
const RemoteApp$1 = withRouterData(RemoteApp); | ||
const RemoteApp = withRouterData(RemoteAppWrapper); | ||
function createLazyRemoteComponent(info) { | ||
@@ -248,5 +257,5 @@ const exportName = (info == null ? void 0 : info.export) || "default"; | ||
if (exportName in m2 && typeof exportFn === "function") { | ||
const RemoteAppComponent = React.forwardRef((props, _ref) => { | ||
const RemoteAppComponent = React.forwardRef((props, ref) => { | ||
return /* @__PURE__ */ React.createElement( | ||
RemoteApp$1, | ||
RemoteApp, | ||
{ | ||
@@ -256,2 +265,3 @@ name: moduleName, | ||
exportName: info.export || "default", | ||
ref, | ||
...props | ||
@@ -281,6 +291,6 @@ } | ||
function createRemoteComponent(info) { | ||
const LazyComponent = createLazyRemoteComponent(info); | ||
return (props) => { | ||
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props }))); | ||
}; | ||
return React.forwardRef(function(props, ref) { | ||
const LazyComponent = createLazyRemoteComponent(info); | ||
return /* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref }))); | ||
}); | ||
} | ||
@@ -315,28 +325,46 @@ var client = {}; | ||
const RawComponent = (info) => { | ||
const { appInfo, propsInfo } = info; | ||
const { appInfo, propsInfo, ...restProps } = info; | ||
const { name, memoryRoute, basename = "/" } = appInfo; | ||
return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename })); | ||
return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename, ...restProps })); | ||
}; | ||
return { | ||
render(info) { | ||
async render(info) { | ||
context.LoggerInstance.log(`createBridgeComponent render Info`, info); | ||
const { name, basename, memoryRoute, ...propsInfo } = info; | ||
if (context.atLeastReact18(React__namespace)) { | ||
const root = client.createRoot(info.dom); | ||
rootMap.set(info.dom, root); | ||
root.render( | ||
/* @__PURE__ */ React__namespace.createElement( | ||
RawComponent, | ||
{ | ||
propsInfo, | ||
appInfo: { | ||
name, | ||
basename, | ||
memoryRoute | ||
if (bridgeInfo == null ? void 0 : bridgeInfo.render) { | ||
Promise.resolve(bridgeInfo == null ? void 0 : bridgeInfo.render( | ||
/* @__PURE__ */ React__namespace.createElement( | ||
RawComponent, | ||
{ | ||
propsInfo, | ||
appInfo: { | ||
name, | ||
basename, | ||
memoryRoute | ||
} | ||
} | ||
} | ||
) | ||
); | ||
), | ||
info.dom | ||
)).then((root) => rootMap.set(info.dom, root)); | ||
} else { | ||
const root = client.createRoot(info.dom); | ||
root.render( | ||
/* @__PURE__ */ React__namespace.createElement( | ||
RawComponent, | ||
{ | ||
propsInfo, | ||
appInfo: { | ||
name, | ||
basename, | ||
memoryRoute | ||
} | ||
} | ||
) | ||
); | ||
rootMap.set(info.dom, root); | ||
} | ||
} else { | ||
ReactDOM.render( | ||
const renderFunc = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render; | ||
renderFunc( | ||
/* @__PURE__ */ React__namespace.createElement( | ||
@@ -357,3 +385,3 @@ RawComponent, | ||
}, | ||
destroy(info) { | ||
async destroy(info) { | ||
context.LoggerInstance.log(`createBridgeComponent destroy Info`, { | ||
@@ -360,0 +388,0 @@ dom: info.dom |
import { ComponentType } from 'react'; | ||
import { CSSProperties } from 'react'; | ||
import { default as default_2 } from 'react'; | ||
import { default as default_3 } from 'react-dom/client'; | ||
import { ErrorInfo } from 'react'; | ||
import { ForwardRefExoticComponent } from 'react'; | ||
import { PropsWithChildren } from 'react'; | ||
import { PropsWithoutRef } from 'react'; | ||
import * as React_2 from 'react'; | ||
import { RefAttributes } from 'react'; | ||
export declare function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>): () => { | ||
render(info: RenderFnParams & any): void; | ||
render(info: RenderFnParams & any): Promise<void>; | ||
destroy(info: { | ||
dom: HTMLElement; | ||
}): void; | ||
}): Promise<void>; | ||
rawComponent: React_2.ComponentType<T>; | ||
@@ -21,6 +26,3 @@ __BRIDGE_FN__: (_args: T) => void; | ||
export?: E; | ||
}): (props: { | ||
basename?: ProviderParams['basename']; | ||
memoryRoute?: ProviderParams['memoryRoute']; | ||
} & ("__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.JSX.Element; | ||
}): ForwardRefExoticComponent<PropsWithoutRef<RemoteProps> & RefAttributes<HTMLElement | HTMLDivElement>>; | ||
@@ -53,2 +55,3 @@ declare type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & { | ||
rootComponent: React_2.ComponentType<T>; | ||
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>; | ||
}; | ||
@@ -62,4 +65,12 @@ | ||
}; | ||
style?: CSSProperties; | ||
className?: string | string[]; | ||
} | ||
declare type RemoteProps = { | ||
basename?: ProviderParams['basename']; | ||
memoryRoute?: ProviderParams['memoryRoute']; | ||
[key: string]: any; | ||
}; | ||
export declare interface RenderFnParams extends ProviderParams { | ||
@@ -69,2 +80,4 @@ dom: HTMLElement; | ||
declare type RootType = HTMLElement | default_3.Root; | ||
export { } |
import * as React from "react"; | ||
import React__default, { createContext, Component, createElement, isValidElement, useContext, useState, useEffect, useRef, forwardRef } from "react"; | ||
import { p as pathJoin, L as LoggerInstance, f, a as atLeastReact18, R as RouterContext } from "./context-Bw2PEwa6.js"; | ||
import React__default, { createContext, Component, createElement, isValidElement, forwardRef, useRef, useEffect, useContext, useState } from "react"; | ||
import { L as LoggerInstance, p as pathJoin, f, a as atLeastReact18, R as RouterContext } from "./context-Bw2PEwa6.js"; | ||
import * as ReactRouterDOM from "react-router-dom"; | ||
@@ -101,51 +101,57 @@ import ReactDOM from "react-dom"; | ||
} | ||
const RemoteApp = ({ | ||
name, | ||
memoryRoute, | ||
basename, | ||
providerInfo, | ||
...resProps | ||
}) => { | ||
const rootRef = useRef(null); | ||
const renderDom = useRef(null); | ||
const providerInfoRef = useRef(null); | ||
useEffect(() => { | ||
const renderTimeout = setTimeout(() => { | ||
const providerReturn = providerInfo(); | ||
providerInfoRef.current = providerReturn; | ||
const renderProps = { | ||
name, | ||
dom: rootRef.current, | ||
basename, | ||
memoryRoute, | ||
...resProps | ||
const RemoteAppWrapper = forwardRef(function(props, ref) { | ||
const RemoteApp2 = () => { | ||
const { | ||
name, | ||
memoryRoute, | ||
basename, | ||
providerInfo, | ||
className, | ||
style, | ||
...resProps | ||
} = props; | ||
const rootRef = ref && "current" in ref ? ref : useRef(null); | ||
const renderDom = useRef(null); | ||
const providerInfoRef = useRef(null); | ||
useEffect(() => { | ||
const renderTimeout = setTimeout(() => { | ||
const providerReturn = providerInfo(); | ||
providerInfoRef.current = providerReturn; | ||
const renderProps = { | ||
name, | ||
dom: rootRef.current, | ||
basename, | ||
memoryRoute, | ||
...resProps | ||
}; | ||
renderDom.current = rootRef.current; | ||
LoggerInstance.log( | ||
`createRemoteComponent LazyComponent render >>>`, | ||
renderProps | ||
); | ||
providerReturn.render(renderProps); | ||
}); | ||
return () => { | ||
clearTimeout(renderTimeout); | ||
setTimeout(() => { | ||
var _a, _b; | ||
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) { | ||
LoggerInstance.log( | ||
`createRemoteComponent LazyComponent destroy >>>`, | ||
{ name, basename, dom: renderDom.current } | ||
); | ||
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({ | ||
dom: renderDom.current | ||
}); | ||
} | ||
}); | ||
}; | ||
renderDom.current = rootRef.current; | ||
LoggerInstance.log( | ||
`createRemoteComponent LazyComponent render >>>`, | ||
renderProps | ||
); | ||
providerReturn.render(renderProps); | ||
}); | ||
return () => { | ||
clearTimeout(renderTimeout); | ||
setTimeout(() => { | ||
var _a, _b; | ||
if ((_a = providerInfoRef.current) == null ? void 0 : _a.destroy) { | ||
LoggerInstance.log( | ||
`createRemoteComponent LazyComponent destroy >>>`, | ||
{ name, basename, dom: renderDom.current } | ||
); | ||
(_b = providerInfoRef.current) == null ? void 0 : _b.destroy({ | ||
dom: renderDom.current | ||
}); | ||
} | ||
}); | ||
}; | ||
}, []); | ||
return /* @__PURE__ */ React__default.createElement("div", { ref: rootRef }); | ||
}; | ||
RemoteApp["__APP_VERSION__"] = "0.3.1"; | ||
}, []); | ||
return /* @__PURE__ */ React__default.createElement("div", { className, style, ref: rootRef }); | ||
}; | ||
RemoteApp2["__APP_VERSION__"] = "0.3.1"; | ||
return /* @__PURE__ */ React__default.createElement(RemoteApp2, null); | ||
}); | ||
function withRouterData(WrappedComponent) { | ||
return (props) => { | ||
const Component2 = forwardRef(function(props, ref) { | ||
var _a; | ||
@@ -208,6 +214,9 @@ let enableDispathPopstate = false; | ||
} | ||
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename }); | ||
}; | ||
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename, ref }); | ||
}); | ||
return forwardRef(function(props, ref) { | ||
return /* @__PURE__ */ React__default.createElement(Component2, { ...props, ref }); | ||
}); | ||
} | ||
const RemoteApp$1 = withRouterData(RemoteApp); | ||
const RemoteApp = withRouterData(RemoteAppWrapper); | ||
function createLazyRemoteComponent(info) { | ||
@@ -229,5 +238,5 @@ const exportName = (info == null ? void 0 : info.export) || "default"; | ||
if (exportName in m2 && typeof exportFn === "function") { | ||
const RemoteAppComponent = forwardRef((props, _ref) => { | ||
const RemoteAppComponent = forwardRef((props, ref) => { | ||
return /* @__PURE__ */ React__default.createElement( | ||
RemoteApp$1, | ||
RemoteApp, | ||
{ | ||
@@ -237,2 +246,3 @@ name: moduleName, | ||
exportName: info.export || "default", | ||
ref, | ||
...props | ||
@@ -262,6 +272,6 @@ } | ||
function createRemoteComponent(info) { | ||
const LazyComponent = createLazyRemoteComponent(info); | ||
return (props) => { | ||
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 }))); | ||
}; | ||
return forwardRef(function(props, ref) { | ||
const LazyComponent = createLazyRemoteComponent(info); | ||
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 }))); | ||
}); | ||
} | ||
@@ -296,28 +306,46 @@ var client = {}; | ||
const RawComponent = (info) => { | ||
const { appInfo, propsInfo } = info; | ||
const { appInfo, propsInfo, ...restProps } = info; | ||
const { name, memoryRoute, basename = "/" } = appInfo; | ||
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename })); | ||
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename, ...restProps })); | ||
}; | ||
return { | ||
render(info) { | ||
async render(info) { | ||
LoggerInstance.log(`createBridgeComponent render Info`, info); | ||
const { name, basename, memoryRoute, ...propsInfo } = info; | ||
if (atLeastReact18(React)) { | ||
const root = client.createRoot(info.dom); | ||
rootMap.set(info.dom, root); | ||
root.render( | ||
/* @__PURE__ */ React.createElement( | ||
RawComponent, | ||
{ | ||
propsInfo, | ||
appInfo: { | ||
name, | ||
basename, | ||
memoryRoute | ||
if (bridgeInfo == null ? void 0 : bridgeInfo.render) { | ||
Promise.resolve(bridgeInfo == null ? void 0 : bridgeInfo.render( | ||
/* @__PURE__ */ React.createElement( | ||
RawComponent, | ||
{ | ||
propsInfo, | ||
appInfo: { | ||
name, | ||
basename, | ||
memoryRoute | ||
} | ||
} | ||
} | ||
) | ||
); | ||
), | ||
info.dom | ||
)).then((root) => rootMap.set(info.dom, root)); | ||
} else { | ||
const root = client.createRoot(info.dom); | ||
root.render( | ||
/* @__PURE__ */ React.createElement( | ||
RawComponent, | ||
{ | ||
propsInfo, | ||
appInfo: { | ||
name, | ||
basename, | ||
memoryRoute | ||
} | ||
} | ||
) | ||
); | ||
rootMap.set(info.dom, root); | ||
} | ||
} else { | ||
ReactDOM.render( | ||
const renderFunc = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render; | ||
renderFunc( | ||
/* @__PURE__ */ React.createElement( | ||
@@ -338,3 +366,3 @@ RawComponent, | ||
}, | ||
destroy(info) { | ||
async destroy(info) { | ||
LoggerInstance.log(`createBridgeComponent destroy Info`, { | ||
@@ -341,0 +369,0 @@ dom: info.dom |
{ | ||
"name": "@module-federation/bridge-react", | ||
"version": "0.0.0-next-20240725030707", | ||
"version": "0.0.0-next-20240725035430", | ||
"publishConfig": { | ||
@@ -23,2 +23,12 @@ "access": "public" | ||
}, | ||
"./router-v5": { | ||
"types": "./dist/router-v5.d.ts", | ||
"import": "./dist/router-v5.es.js", | ||
"require": "./dist/router-v5.cjs.js" | ||
}, | ||
"./router-v6": { | ||
"types": "./dist/router-v6.d.ts", | ||
"import": "./dist/router-v6.es.js", | ||
"require": "./dist/router-v6.cjs.js" | ||
}, | ||
"./*": "./*" | ||
@@ -29,3 +39,3 @@ }, | ||
"react-error-boundary": "^4.0.13", | ||
"@module-federation/bridge-shared": "0.0.0-next-20240725030707" | ||
"@module-federation/bridge-shared": "0.0.0-next-20240725035430" | ||
}, | ||
@@ -32,0 +42,0 @@ "peerDependencies": { |
@@ -25,2 +25,4 @@ import { defineConfig } from 'vite'; | ||
router: path.resolve(__dirname, 'src/router.tsx'), | ||
'router-v5': path.resolve(__dirname, 'src/router-v5.tsx'), | ||
'router-v6': path.resolve(__dirname, 'src/router-v6.tsx'), | ||
}, | ||
@@ -36,2 +38,4 @@ formats: ['cjs', 'es'], | ||
'react-router-dom/', | ||
'react-router-dom/index.js', | ||
'react-router-dom/dist/index.js', | ||
], | ||
@@ -38,0 +42,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89026
37
2396
+ Added@module-federation/bridge-shared@0.0.0-next-20240725035430(transitive)
- Removed@module-federation/bridge-shared@0.0.0-next-20240725030707(transitive)
Updated@module-federation/bridge-shared@0.0.0-next-20240725035430