@module-federation/bridge-react
Advanced tools
Comparing version 0.0.0-next-20240819022441 to 0.0.0-next-20240819031127
# @module-federation/bridge-react | ||
## 0.0.0-next-20240819022441 | ||
## 0.0.0-next-20240819031127 | ||
### Patch Changes | ||
- @module-federation/bridge-shared@0.0.0-next-20240819022441 | ||
- 49d6135: feat(@module-federation/bridge): enhance Bridge capabilities and fix some issues | ||
- Updated dependencies [49d6135] | ||
- @module-federation/bridge-shared@0.0.0-next-20240819031127 | ||
## 0.4.0 | ||
### Patch Changes | ||
- @module-federation/bridge-shared@0.4.0 | ||
## 0.3.5 | ||
@@ -10,0 +18,0 @@ |
@@ -120,51 +120,67 @@ "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 = () => { | ||
context.LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props }); | ||
const { | ||
moduleName, | ||
memoryRoute, | ||
basename, | ||
providerInfo, | ||
className, | ||
style, | ||
fallback, | ||
...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 = { | ||
moduleName, | ||
dom: rootRef.current, | ||
basename, | ||
memoryRoute, | ||
fallback, | ||
...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 >>>`, | ||
{ moduleName, 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.5"; | ||
}, []); | ||
return /* @__PURE__ */ React.createElement( | ||
"div", | ||
{ | ||
className: props == null ? void 0 : props.className, | ||
style: props == null ? void 0 : props.style, | ||
ref: rootRef | ||
} | ||
); | ||
}; | ||
RemoteApp2["__APP_VERSION__"] = "0.4.0"; | ||
return /* @__PURE__ */ React.createElement(RemoteApp2, null); | ||
}); | ||
function withRouterData(WrappedComponent) { | ||
return (props) => { | ||
const Component = React.forwardRef(function(props, ref) { | ||
var _a; | ||
@@ -227,6 +243,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,9 +267,11 @@ 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, | ||
{ | ||
name: moduleName, | ||
moduleName, | ||
providerInfo: exportFn, | ||
exportName: info.export || "default", | ||
fallback: info.fallback, | ||
ref, | ||
...props | ||
@@ -280,6 +301,9 @@ } | ||
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((props, ref) => { | ||
const LazyComponent = createLazyRemoteComponent(info); | ||
return ( | ||
// set ErrorBoundary for LazyComponent rendering error, usually caused by inner bridge logic render process | ||
/* @__PURE__ */ React.createElement(ErrorBoundary, { FallbackComponent: info.fallback }, /* @__PURE__ */ React.createElement(React.Suspense, { fallback: info.loading }, /* @__PURE__ */ React.createElement(LazyComponent, { ...props, ref }))) | ||
); | ||
}); | ||
} | ||
@@ -314,44 +338,54 @@ var client = {}; | ||
const RawComponent = (info) => { | ||
const { appInfo, propsInfo } = 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 })); | ||
const { appInfo, propsInfo, ...restProps } = info; | ||
const { moduleName, memoryRoute, basename = "/" } = appInfo; | ||
return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { moduleName, 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; | ||
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)) { | ||
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(rootComponentWithErrorBoundary, dom) | ||
).then((root) => rootMap.set(info.dom, root)); | ||
} else { | ||
const root = client.createRoot(info.dom); | ||
root.render(rootComponentWithErrorBoundary); | ||
rootMap.set(info.dom, root); | ||
} | ||
} else { | ||
ReactDOM.render( | ||
/* @__PURE__ */ React__namespace.createElement( | ||
RawComponent, | ||
{ | ||
propsInfo, | ||
appInfo: { | ||
name, | ||
basename, | ||
memoryRoute | ||
} | ||
} | ||
), | ||
info.dom | ||
); | ||
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render; | ||
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom); | ||
} | ||
}, | ||
destroy(info) { | ||
async destroy(info) { | ||
context.LoggerInstance.log(`createBridgeComponent destroy Info`, { | ||
@@ -363,2 +397,3 @@ dom: info.dom | ||
root == null ? void 0 : root.unmount(); | ||
rootMap.delete(info.dom); | ||
} else { | ||
@@ -365,0 +400,0 @@ ReactDOM.unmountComponentAtNode(info.dom); |
import { ComponentType } from 'react'; | ||
import { default as default_2 } from 'react'; | ||
import { default as default_3 } from 'react-dom/client'; | ||
import { ErrorInfo } from 'react'; | ||
@@ -8,6 +9,6 @@ import { PropsWithChildren } 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>; | ||
@@ -22,6 +23,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; | ||
}): 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<unknown>>; | ||
@@ -54,6 +52,7 @@ declare type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & { | ||
rootComponent: React_2.ComponentType<T>; | ||
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>; | ||
}; | ||
export declare interface ProviderParams { | ||
name?: string; | ||
moduleName?: string; | ||
basename?: string; | ||
@@ -63,2 +62,4 @@ memoryRoute?: { | ||
}; | ||
style?: React.CSSProperties; | ||
className?: string; | ||
} | ||
@@ -70,2 +71,4 @@ | ||
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,67 @@ 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 = () => { | ||
LoggerInstance.log(`RemoteAppWrapper RemoteApp props >>>`, { props }); | ||
const { | ||
moduleName, | ||
memoryRoute, | ||
basename, | ||
providerInfo, | ||
className, | ||
style, | ||
fallback, | ||
...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 = { | ||
moduleName, | ||
dom: rootRef.current, | ||
basename, | ||
memoryRoute, | ||
fallback, | ||
...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 >>>`, | ||
{ moduleName, 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.5"; | ||
}, []); | ||
return /* @__PURE__ */ React__default.createElement( | ||
"div", | ||
{ | ||
className: props == null ? void 0 : props.className, | ||
style: props == null ? void 0 : props.style, | ||
ref: rootRef | ||
} | ||
); | ||
}; | ||
RemoteApp2["__APP_VERSION__"] = "0.4.0"; | ||
return /* @__PURE__ */ React__default.createElement(RemoteApp2, null); | ||
}); | ||
function withRouterData(WrappedComponent) { | ||
return (props) => { | ||
const Component2 = forwardRef(function(props, ref) { | ||
var _a; | ||
@@ -208,6 +224,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,9 +248,11 @@ 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, | ||
{ | ||
name: moduleName, | ||
moduleName, | ||
providerInfo: exportFn, | ||
exportName: info.export || "default", | ||
fallback: info.fallback, | ||
ref, | ||
...props | ||
@@ -261,6 +282,9 @@ } | ||
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((props, ref) => { | ||
const LazyComponent = createLazyRemoteComponent(info); | ||
return ( | ||
// set ErrorBoundary for LazyComponent rendering error, usually caused by inner bridge logic render process | ||
/* @__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 }))) | ||
); | ||
}); | ||
} | ||
@@ -295,44 +319,54 @@ var client = {}; | ||
const RawComponent = (info) => { | ||
const { appInfo, propsInfo } = info; | ||
const { name, memoryRoute, basename = "/" } = appInfo; | ||
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename })); | ||
const { appInfo, propsInfo, ...restProps } = info; | ||
const { moduleName, memoryRoute, basename = "/" } = appInfo; | ||
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { moduleName, 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; | ||
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)) { | ||
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(rootComponentWithErrorBoundary, dom) | ||
).then((root) => rootMap.set(info.dom, root)); | ||
} else { | ||
const root = client.createRoot(info.dom); | ||
root.render(rootComponentWithErrorBoundary); | ||
rootMap.set(info.dom, root); | ||
} | ||
} else { | ||
ReactDOM.render( | ||
/* @__PURE__ */ React.createElement( | ||
RawComponent, | ||
{ | ||
propsInfo, | ||
appInfo: { | ||
name, | ||
basename, | ||
memoryRoute | ||
} | ||
} | ||
), | ||
info.dom | ||
); | ||
const renderFn = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render; | ||
renderFn == null ? void 0 : renderFn(rootComponentWithErrorBoundary, info.dom); | ||
} | ||
}, | ||
destroy(info) { | ||
async destroy(info) { | ||
LoggerInstance.log(`createBridgeComponent destroy Info`, { | ||
@@ -344,2 +378,3 @@ dom: info.dom | ||
root == null ? void 0 : root.unmount(); | ||
rootMap.delete(info.dom); | ||
} else { | ||
@@ -346,0 +381,0 @@ ReactDOM.unmountComponentAtNode(info.dom); |
@@ -23,12 +23,10 @@ "use strict"; | ||
const ReactRouterDom__namespace = /* @__PURE__ */ _interopNamespaceDefault(ReactRouterDom); | ||
function WraperRouter(props) { | ||
function WrapperRouter(props) { | ||
const { basename, ...propsRes } = props; | ||
const routerContextProps = React.useContext(context.RouterContext) || {}; | ||
context.LoggerInstance.log(`WraperRouter info >>>`, { | ||
context.LoggerInstance.log(`WrapperRouter info >>>`, { | ||
...routerContextProps, | ||
routerContextProps, | ||
WraperRouterProps: props | ||
WrapperRouterProps: props | ||
}); | ||
if (!routerContextProps) | ||
return /* @__PURE__ */ React.createElement(ReactRouterDom__namespace.BrowserRouter, { ...props }); | ||
if (routerContextProps == null ? void 0 : routerContextProps.memoryRoute) { | ||
@@ -51,10 +49,10 @@ return /* @__PURE__ */ React.createElement( | ||
} | ||
function WraperRouterProvider(props) { | ||
function WrapperRouterProvider(props) { | ||
const { router, ...propsRes } = props; | ||
const routerContextProps = React.useContext(context.RouterContext) || {}; | ||
const routers = router.routes; | ||
context.LoggerInstance.log(`WraperRouterProvider info >>>`, { | ||
context.LoggerInstance.log(`WrapperRouterProvider info >>>`, { | ||
...routerContextProps, | ||
routerContextProps, | ||
WraperRouterProviderProps: props, | ||
WrapperRouterProviderProps: props, | ||
router | ||
@@ -65,4 +63,2 @@ }); | ||
const createBrowserRouter = ReactRouterDom__namespace["createBrowserRouter"]; | ||
if (!routerContextProps) | ||
return /* @__PURE__ */ React.createElement(RouterProvider, { ...props }); | ||
if (routerContextProps.memoryRoute) { | ||
@@ -82,4 +78,4 @@ const MemeoryRouterInstance = createMemoryRouter(routers, { | ||
} | ||
exports.BrowserRouter = WraperRouter; | ||
exports.RouterProvider = WraperRouterProvider; | ||
exports.BrowserRouter = WrapperRouter; | ||
exports.RouterProvider = WrapperRouterProvider; | ||
Object.keys(ReactRouterDom).forEach((k) => { | ||
@@ -86,0 +82,0 @@ if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) |
@@ -5,12 +5,10 @@ import React__default, { useContext } from "react"; | ||
import { R as RouterContext, L as LoggerInstance } from "./context-Bw2PEwa6.js"; | ||
function WraperRouter(props) { | ||
function WrapperRouter(props) { | ||
const { basename, ...propsRes } = props; | ||
const routerContextProps = useContext(RouterContext) || {}; | ||
LoggerInstance.log(`WraperRouter info >>>`, { | ||
LoggerInstance.log(`WrapperRouter info >>>`, { | ||
...routerContextProps, | ||
routerContextProps, | ||
WraperRouterProps: props | ||
WrapperRouterProps: props | ||
}); | ||
if (!routerContextProps) | ||
return /* @__PURE__ */ React__default.createElement(ReactRouterDom.BrowserRouter, { ...props }); | ||
if (routerContextProps == null ? void 0 : routerContextProps.memoryRoute) { | ||
@@ -33,10 +31,10 @@ return /* @__PURE__ */ React__default.createElement( | ||
} | ||
function WraperRouterProvider(props) { | ||
function WrapperRouterProvider(props) { | ||
const { router, ...propsRes } = props; | ||
const routerContextProps = useContext(RouterContext) || {}; | ||
const routers = router.routes; | ||
LoggerInstance.log(`WraperRouterProvider info >>>`, { | ||
LoggerInstance.log(`WrapperRouterProvider info >>>`, { | ||
...routerContextProps, | ||
routerContextProps, | ||
WraperRouterProviderProps: props, | ||
WrapperRouterProviderProps: props, | ||
router | ||
@@ -47,4 +45,2 @@ }); | ||
const createBrowserRouter = ReactRouterDom["createBrowserRouter"]; | ||
if (!routerContextProps) | ||
return /* @__PURE__ */ React__default.createElement(RouterProvider, { ...props }); | ||
if (routerContextProps.memoryRoute) { | ||
@@ -65,4 +61,4 @@ const MemeoryRouterInstance = createMemoryRouter(routers, { | ||
export { | ||
WraperRouter as BrowserRouter, | ||
WraperRouterProvider as RouterProvider | ||
WrapperRouter as BrowserRouter, | ||
WrapperRouterProvider as RouterProvider | ||
}; |
{ | ||
"name": "@module-federation/bridge-react", | ||
"version": "0.0.0-next-20240819022441", | ||
"version": "0.0.0-next-20240819031127", | ||
"publishConfig": { | ||
@@ -23,2 +23,12 @@ "access": "public" | ||
}, | ||
"./router-v5": { | ||
"types": "./dist/router.d.ts", | ||
"import": "./dist/router.es.js", | ||
"require": "./dist/router.cjs.js" | ||
}, | ||
"./router-v6": { | ||
"types": "./dist/router.d.ts", | ||
"import": "./dist/router.es.js", | ||
"require": "./dist/router.cjs.js" | ||
}, | ||
"./*": "./*" | ||
@@ -29,3 +39,3 @@ }, | ||
"react-error-boundary": "^4.0.13", | ||
"@module-federation/bridge-shared": "0.0.0-next-20240819022441" | ||
"@module-federation/bridge-shared": "0.0.0-next-20240819031127" | ||
}, | ||
@@ -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.tsx'), | ||
'router-v6': path.resolve(__dirname, 'src/router.tsx'), | ||
}, | ||
@@ -36,3 +38,30 @@ formats: ['cjs', 'es'], | ||
'react-router-dom/', | ||
'react-router-dom/index.js', | ||
'react-router-dom/dist/index.js', | ||
], | ||
plugins: [ | ||
{ | ||
name: 'modify-output-plugin', | ||
generateBundle(options, bundle) { | ||
for (const fileName in bundle) { | ||
const chunk = bundle[fileName]; | ||
if (fileName.includes('router-v6') && chunk.type === 'chunk') { | ||
chunk.code = chunk.code.replace( | ||
// Match 'react-router-dom/' followed by single quotes, double quotes, or backticks, replacing only 'react-router-dom/' to react-router-v6 dist file structure | ||
/react-router-dom\/(?=[\'\"\`])/g, | ||
'react-router-dom/dist/index.js', | ||
); | ||
} | ||
if (fileName.includes('router-v5') && chunk.type === 'chunk') { | ||
chunk.code = chunk.code.replace( | ||
// Match 'react-router-dom/' followed by single quotes, double quotes, or backticks, replacing only 'react-router-dom/' to react-router-v5 dist file structure | ||
/react-router-dom\/(?=[\'\"\`])/g, | ||
'react-router-dom/index.js', | ||
); | ||
} | ||
} | ||
}, | ||
}, | ||
], | ||
}, | ||
@@ -39,0 +68,0 @@ minify: false, |
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
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
77325
35
2081
+ Added@module-federation/bridge-shared@0.0.0-next-20240819031127(transitive)
- Removed@module-federation/bridge-shared@0.0.0-next-20240819022441(transitive)
Updated@module-federation/bridge-shared@0.0.0-next-20240819031127