Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@module-federation/bridge-react

Package Overview
Dependencies
Maintainers
0
Versions
329
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@module-federation/bridge-react - npm Package Compare versions

Comparing version 0.0.0-next-20240726084328 to 0.0.0-next-20240731082143

16

CHANGELOG.md
# @module-federation/bridge-react
## 0.0.0-next-20240726084328
## 0.0.0-next-20240731082143
### Patch Changes
- @module-federation/bridge-shared@0.0.0-next-20240726084328
- @module-federation/bridge-shared@0.0.0-next-20240731082143
## 0.3.3
### Patch Changes
- @module-federation/bridge-shared@0.3.3
## 0.3.2
### Patch Changes
- @module-federation/bridge-shared@0.3.2
## 0.3.1

@@ -10,0 +22,0 @@

185

dist/index.cjs.js

@@ -120,66 +120,51 @@ "use strict";

}
const RemoteAppWrapper = React.forwardRef(function(props, ref) {
const RemoteApp2 = () => {
const {
name,
memoryRoute,
basename,
providerInfo,
dom,
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;
let domElement = null;
if (dom) {
domElement = document.getElementById(dom.replace("#", ""));
rootRef.current = domElement;
} else {
domElement = rootRef.current;
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
};
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
});
}
const renderProps = {
name,
// dom: rootRef.current,
dom: domElement,
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
});
}
});
};
}, []);
return dom ? null : /* @__PURE__ */ React.createElement("div", { className: props == null ? void 0 : props.className, style: props == null ? void 0 : props.style, ref: rootRef });
};
RemoteApp2["__APP_VERSION__"] = "0.3.1";
return /* @__PURE__ */ React.createElement(RemoteApp2, null);
});
};
}, []);
return /* @__PURE__ */ React.createElement("div", { ref: rootRef });
};
RemoteApp["__APP_VERSION__"] = "0.3.3";
function withRouterData(WrappedComponent) {
const Component = React.forwardRef(function(props, ref) {
return (props) => {
var _a;

@@ -242,9 +227,6 @@ let enableDispathPopstate = false;

}
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename, ref });
});
return React.forwardRef(function(props, ref) {
return /* @__PURE__ */ React.createElement(Component, { ...props, ref });
});
return /* @__PURE__ */ React.createElement(WrappedComponent, { ...props, basename });
};
}
const RemoteApp = withRouterData(RemoteAppWrapper);
const RemoteApp$1 = withRouterData(RemoteApp);
function createLazyRemoteComponent(info) {

@@ -266,5 +248,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,
RemoteApp$1,
{

@@ -274,3 +256,2 @@ name: moduleName,

exportName: info.export || "default",
ref,
...props

@@ -300,6 +281,6 @@ }

function createRemoteComponent(info) {
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, dom: info == null ? void 0 : info.dom, ref })));
});
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 })));
};
}

@@ -334,46 +315,28 @@ var client = {};

const RawComponent = (info) => {
const { appInfo, propsInfo, ...restProps } = 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, ...restProps }));
return /* @__PURE__ */ React__namespace.createElement(context.RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React__namespace.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename }));
};
return {
async render(info) {
render(info) {
context.LoggerInstance.log(`createBridgeComponent render Info`, info);
const { name, basename, memoryRoute, ...propsInfo } = info;
if (context.atLeastReact18(React__namespace)) {
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
}
const root = client.createRoot(info.dom);
rootMap.set(info.dom, root);
root.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 {
const renderFunc = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
renderFunc(
ReactDOM.render(
/* @__PURE__ */ React__namespace.createElement(

@@ -394,3 +357,3 @@ RawComponent,

},
async destroy(info) {
destroy(info) {
context.LoggerInstance.log(`createBridgeComponent destroy Info`, {

@@ -397,0 +360,0 @@ dom: 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';
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): Promise<void>;
render(info: RenderFnParams & any): void;
destroy(info: {
dom: HTMLElement;
}): Promise<void>;
}): void;
rawComponent: React_2.ComponentType<T>;

@@ -25,4 +21,6 @@ __BRIDGE_FN__: (_args: T) => void;

export?: E;
dom?: string;
}): ForwardRefExoticComponent<PropsWithoutRef<ProviderParams> & RefAttributes<HTMLElement | HTMLDivElement>>;
}): (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;

@@ -55,6 +53,5 @@ declare type ErrorBoundaryPropsWithComponent = ErrorBoundarySharedProps & {

rootComponent: React_2.ComponentType<T>;
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
};
export declare interface ProviderParams extends default_2.HTMLAttributes<HTMLDivElement> {
export declare interface ProviderParams {
name?: string;

@@ -65,5 +62,2 @@ basename?: string;

};
props?: {
[key: string]: any;
};
}

@@ -75,4 +69,2 @@

declare type RootType = HTMLElement | default_3.Root;
export { }
import * as React from "react";
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 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 * as ReactRouterDOM from "react-router-dom";

@@ -101,66 +101,51 @@ import ReactDOM from "react-dom";

}
const RemoteAppWrapper = forwardRef(function(props, ref) {
const RemoteApp2 = () => {
const {
name,
memoryRoute,
basename,
providerInfo,
dom,
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;
let domElement = null;
if (dom) {
domElement = document.getElementById(dom.replace("#", ""));
rootRef.current = domElement;
} else {
domElement = rootRef.current;
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
};
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
});
}
const renderProps = {
name,
// dom: rootRef.current,
dom: domElement,
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
});
}
});
};
}, []);
return dom ? null : /* @__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.3.1";
return /* @__PURE__ */ React__default.createElement(RemoteApp2, null);
});
};
}, []);
return /* @__PURE__ */ React__default.createElement("div", { ref: rootRef });
};
RemoteApp["__APP_VERSION__"] = "0.3.3";
function withRouterData(WrappedComponent) {
const Component2 = forwardRef(function(props, ref) {
return (props) => {
var _a;

@@ -223,9 +208,6 @@ let enableDispathPopstate = false;

}
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename, ref });
});
return forwardRef(function(props, ref) {
return /* @__PURE__ */ React__default.createElement(Component2, { ...props, ref });
});
return /* @__PURE__ */ React__default.createElement(WrappedComponent, { ...props, basename });
};
}
const RemoteApp = withRouterData(RemoteAppWrapper);
const RemoteApp$1 = withRouterData(RemoteApp);
function createLazyRemoteComponent(info) {

@@ -247,5 +229,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,
RemoteApp$1,
{

@@ -255,3 +237,2 @@ name: moduleName,

exportName: info.export || "default",
ref,
...props

@@ -281,6 +262,6 @@ }

function createRemoteComponent(info) {
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, dom: info == null ? void 0 : info.dom, ref })));
});
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 })));
};
}

@@ -315,46 +296,28 @@ var client = {};

const RawComponent = (info) => {
const { appInfo, propsInfo, ...restProps } = 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, ...restProps }));
return /* @__PURE__ */ React.createElement(RouterContext.Provider, { value: { name, basename, memoryRoute } }, /* @__PURE__ */ React.createElement(bridgeInfo.rootComponent, { ...propsInfo, basename }));
};
return {
async render(info) {
render(info) {
LoggerInstance.log(`createBridgeComponent render Info`, info);
const { name, basename, memoryRoute, ...propsInfo } = info;
if (atLeastReact18(React)) {
if (bridgeInfo == null ? void 0 : bridgeInfo.render) {
Promise.resolve(bridgeInfo == null ? void 0 : bridgeInfo.render(
/* @__PURE__ */ React.createElement(
RawComponent,
{
propsInfo,
appInfo: {
name,
basename,
memoryRoute
}
const root = client.createRoot(info.dom);
rootMap.set(info.dom, root);
root.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 {
const renderFunc = (bridgeInfo == null ? void 0 : bridgeInfo.render) || ReactDOM.render;
renderFunc(
ReactDOM.render(
/* @__PURE__ */ React.createElement(

@@ -375,3 +338,3 @@ RawComponent,

},
async destroy(info) {
destroy(info) {
LoggerInstance.log(`createBridgeComponent destroy Info`, {

@@ -378,0 +341,0 @@ dom: info.dom

{
"name": "@module-federation/bridge-react",
"version": "0.0.0-next-20240726084328",
"version": "0.0.0-next-20240731082143",
"publishConfig": {

@@ -23,12 +23,2 @@ "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"
},
"./*": "./*"

@@ -39,3 +29,3 @@ },

"react-error-boundary": "^4.0.13",
"@module-federation/bridge-shared": "0.0.0-next-20240726084328"
"@module-federation/bridge-shared": "0.0.0-next-20240731082143"
},

@@ -42,0 +32,0 @@ "peerDependencies": {

@@ -25,4 +25,2 @@ 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'),
},

@@ -38,4 +36,2 @@ formats: ['cjs', 'es'],

'react-router-dom/',
'react-router-dom/index.js',
'react-router-dom/dist/index.js',
],

@@ -42,0 +38,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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc