Skip to content

Commit

Permalink
chore: patch update nx
Browse files Browse the repository at this point in the history
  • Loading branch information
ScriptedAlchemy committed Nov 15, 2024
2 parents df24cb6 + b00aff2 commit 917d285
Show file tree
Hide file tree
Showing 74 changed files with 1,826 additions and 1,552 deletions.
5 changes: 0 additions & 5 deletions .changeset/clean-boats-swim.md

This file was deleted.

6 changes: 6 additions & 0 deletions apps/modernjs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @module-federation/modernjsapp

## 0.1.67

### Patch Changes

- @module-federation/enhanced@0.7.4

## 0.1.66

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/modernjs/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@module-federation/modernjsapp",
"private": true,
"version": "0.1.66",
"version": "0.1.67",
"scripts": {
"reset": "npx rimraf ./**/node_modules",
"dev": "modern dev",
Expand Down
6 changes: 6 additions & 0 deletions apps/website-new/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# website-new

## 1.0.9

### Patch Changes

- @module-federation/error-codes@0.7.4

## 1.0.8

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion apps/website-new/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "website-new",
"version": "1.0.8",
"version": "1.0.9",
"private": true,
"scripts": {
"dev": "rspress dev",
Expand Down
6 changes: 6 additions & 0 deletions packages/bridge/bridge-react-webpack-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @module-federation/bridge-react-webpack-plugin

## 0.7.4

### Patch Changes

- @module-federation/sdk@0.7.4

## 0.7.3

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/bridge-react-webpack-plugin/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@module-federation/bridge-react-webpack-plugin",
"version": "0.7.3",
"version": "0.7.4",
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/bridge/bridge-react/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @module-federation/bridge-react

## 0.7.4

### Patch Changes

- ff8ce29: feat: feat: support lifecycyle hooks in module-deferation bridge
- Updated dependencies [ff8ce29]
- @module-federation/runtime@0.7.4
- @module-federation/sdk@0.7.4
- @module-federation/bridge-shared@0.7.4

## 0.7.3

### Patch Changes
Expand Down
5 changes: 3 additions & 2 deletions packages/bridge/bridge-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@module-federation/bridge-react",
"version": "0.7.3",
"version": "0.7.4",
"publishConfig": {
"access": "public"
},
Expand Down Expand Up @@ -48,7 +48,8 @@
"@loadable/component": "^5.16.4",
"@module-federation/bridge-shared": "workspace:*",
"@module-federation/sdk": "workspace:*",
"react-error-boundary": "^4.0.13"
"react-error-boundary": "^4.0.13",
"@module-federation/runtime": "workspace:*"
},
"peerDependencies": {
"react": ">=16.9.0",
Expand Down
4 changes: 2 additions & 2 deletions packages/bridge/bridge-react/src/create.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { forwardRef } from 'react';
import type { ProviderParams } from '@module-federation/bridge-shared';
import { LoggerInstance } from './utils';
import {
ErrorBoundary,
ErrorBoundaryPropsWithComponent,
} from 'react-error-boundary';
import { LoggerInstance } from './utils';
import RemoteApp from './remote';
import type { ProviderParams } from '@module-federation/bridge-shared';

export interface RenderFnParams extends ProviderParams {
dom?: any;
Expand Down
39 changes: 33 additions & 6 deletions packages/bridge/bridge-react/src/provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,24 @@ import { useLayoutEffect, useRef, useState } from 'react';
import * as React from 'react';
import ReactDOM from 'react-dom';
import ReactDOMClient from 'react-dom/client';
import { RouterContext } from './context';
import type {
ProviderParams,
RenderFnParams,
} from '@module-federation/bridge-shared';
import { LoggerInstance, atLeastReact18 } from './utils';
import { ErrorBoundary } from 'react-error-boundary';
import { RouterContext } from './context';
import { LoggerInstance, atLeastReact18 } from './utils';
import { getInstance } from '@module-federation/runtime';

type RenderParams = RenderFnParams & {
[key: string]: unknown;
};
type DestroyParams = {
moduleName: string;
dom: HTMLElement;
};
type RootType = HTMLElement | ReactDOMClient.Root;

type ProviderFnParams<T> = {
rootComponent: React.ComponentType<T>;
render?: (
Expand All @@ -22,6 +31,9 @@ type ProviderFnParams<T> = {
export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
return () => {
const rootMap = new Map<any, RootType>();
const instance = getInstance();
LoggerInstance.log(`createBridgeComponent remote instance`, instance);

const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => {
const { appInfo, propsInfo, ...restProps } = info;
const { moduleName, memoryRoute, basename = '/' } = appInfo;
Expand All @@ -37,7 +49,7 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
};

return {
async render(info: RenderFnParams & any) {
async render(info: RenderParams) {
LoggerInstance.log(`createBridgeComponent render Info`, info);
const {
moduleName,
Expand All @@ -47,6 +59,10 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
fallback,
...propsInfo
} = info;

const beforeBridgeRenderRes =
instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(info) || {};

const rootComponentWithErrorBoundary = (
// set ErrorBoundary for RawComponent rendering error, usually caused by user app rendering error
<ErrorBoundary FallbackComponent={fallback}>
Expand All @@ -56,11 +72,13 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
basename,
memoryRoute,
}}
propsInfo={propsInfo}
propsInfo={
{ ...propsInfo, ...beforeBridgeRenderRes?.extraProps } as T
}
/>
</ErrorBoundary>
);

// call render function
if (atLeastReact18(React)) {
if (bridgeInfo?.render) {
// in case bridgeInfo?.render is an async function, resolve this to promise
Expand All @@ -77,18 +95,27 @@ export function createBridgeComponent<T>(bridgeInfo: ProviderFnParams<T>) {
const renderFn = bridgeInfo?.render || ReactDOM.render;
renderFn?.(rootComponentWithErrorBoundary, info.dom);
}

instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
},
async destroy(info: { dom: HTMLElement }) {

async destroy(info: DestroyParams) {
LoggerInstance.log(`createBridgeComponent destroy Info`, {
dom: info.dom,
});

instance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit(info);

// call destroy function
if (atLeastReact18(React)) {
const root = rootMap.get(info.dom);
(root as ReactDOMClient.Root)?.unmount();
rootMap.delete(info.dom);
} else {
ReactDOM.unmountComponentAtNode(info.dom);
}

instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit(info);
},
rawComponent: bridgeInfo.rootComponent,
__BRIDGE_FN__: (_args: T) => {},
Expand Down
45 changes: 42 additions & 3 deletions packages/bridge/bridge-react/src/remote/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import React, {
} from 'react';
import * as ReactRouterDOM from 'react-router-dom';
import type { ProviderParams } from '@module-federation/bridge-shared';
import { LoggerInstance, pathJoin } from '../utils';
import { dispatchPopstateEnv } from '@module-federation/bridge-shared';
import { ErrorBoundaryPropsWithComponent } from 'react-error-boundary';
import { LoggerInstance, pathJoin, getRootDomDefaultClassName } from '../utils';
import { getInstance } from '@module-federation/runtime';

declare const __APP_VERSION__: string;
export interface RenderFnParams extends ProviderParams {
Expand Down Expand Up @@ -59,13 +60,15 @@ const RemoteAppWrapper = forwardRef(function (

const renderDom: React.MutableRefObject<HTMLElement | null> = useRef(null);
const providerInfoRef = useRef<any>(null);
const hostInstance = getInstance();
LoggerInstance.log(`RemoteAppWrapper hostInstance >>>`, hostInstance);

useEffect(() => {
const renderTimeout = setTimeout(() => {
const providerReturn = providerInfo();
providerInfoRef.current = providerReturn;

const renderProps = {
let renderProps = {
moduleName,
dom: rootRef.current,
basename,
Expand All @@ -78,7 +81,21 @@ const RemoteAppWrapper = forwardRef(function (
`createRemoteComponent LazyComponent render >>>`,
renderProps,
);

LoggerInstance.log(
`createRemoteComponent LazyComponent hostInstance >>>`,
hostInstance,
);
const beforeBridgeRenderRes =
hostInstance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(
renderProps,
) || {};
// @ts-ignore
renderProps = { ...renderProps, ...beforeBridgeRenderRes.extraProps };
providerReturn.render(renderProps);
hostInstance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(
renderProps,
);
});

return () => {
Expand All @@ -89,17 +106,39 @@ const RemoteAppWrapper = forwardRef(function (
`createRemoteComponent LazyComponent destroy >>>`,
{ moduleName, basename, dom: renderDom.current },
);

hostInstance?.bridgeHook?.lifecycle?.beforeBridgeDestroy?.emit({
moduleName,
dom: renderDom.current,
basename,
memoryRoute,
fallback,
...resProps,
});

providerInfoRef.current?.destroy({
moduleName,
dom: renderDom.current,
});

hostInstance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit({
moduleName,
dom: renderDom.current,
basename,
memoryRoute,
fallback,
...resProps,
});
}
});
};
}, []);

// bridge-remote-root
const rootComponentClassName = `${getRootDomDefaultClassName(moduleName)} ${props?.className}`;
return (
<div
className={props?.className}
className={rootComponentClassName}
style={props?.style}
ref={rootRef}
></div>
Expand Down
1 change: 0 additions & 1 deletion packages/bridge/bridge-react/src/router-v5.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { useContext } from 'react';
// The upper alias react-router-dom$ into this file avoids the loop
// @ts-ignore
import * as ReactRouterDom from 'react-router-dom/index.js';

import { RouterContext } from './context';
import { LoggerInstance } from './utils';

Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/bridge-react/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function WrapperRouterProvider(
return <RouterProvider router={MemeoryRouterInstance} />;
} else {
const BrowserRouterInstance = createBrowserRouter(routers, {
basename: routerContextProps.basename,
basename: routerContextProps.basename || router?.basename,
future: router.future,
window: router.window,
});
Expand Down
22 changes: 22 additions & 0 deletions packages/bridge/bridge-react/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { FederationHost } from '@module-federation/runtime';
import { createLogger } from '@module-federation/sdk';

export const LoggerInstance = createLogger(
Expand Down Expand Up @@ -41,3 +42,24 @@ export function pathJoin(...args: string[]) {
}, '');
return res || '/';
}

export const getModuleName = (id: string) => {
if (!id) {
return id;
}
// separate module name without detailed module path
// @vmok-e2e/edenx-demo-app2/button -> @vmok-e2e/edenx-demo-app2
const idArray = id.split('/');
if (idArray.length < 2) {
return id;
}
return idArray[0] + '/' + idArray[1];
};

export const getRootDomDefaultClassName = (moduleName: string) => {
if (!moduleName) {
return '';
}
const name = getModuleName(moduleName).replace(/\@/, '').replace(/\//, '-');
return `bridge-root-component-${name}`;
};
1 change: 1 addition & 0 deletions packages/bridge/bridge-react/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default defineConfig({
'react-router-dom/',
'react-router-dom/index.js',
'react-router-dom/dist/index.js',
'@module-federation/runtime',
],
plugins: [
{
Expand Down
2 changes: 2 additions & 0 deletions packages/bridge/bridge-shared/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @module-federation/bridge-shared

## 0.7.4

## 0.7.3

## 0.7.2
Expand Down
2 changes: 1 addition & 1 deletion packages/bridge/bridge-shared/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@module-federation/bridge-shared",
"version": "0.7.3",
"version": "0.7.4",
"publishConfig": {
"access": "public"
},
Expand Down
10 changes: 10 additions & 0 deletions packages/bridge/vue3-bridge/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @module-federation/bridge-vue3

## 0.7.4

### Patch Changes

- ff8ce29: feat: feat: support lifecycyle hooks in module-deferation bridge
- Updated dependencies [ff8ce29]
- @module-federation/runtime@0.7.4
- @module-federation/sdk@0.7.4
- @module-federation/bridge-shared@0.7.4

## 0.7.3

### Patch Changes
Expand Down
Loading

0 comments on commit 917d285

Please sign in to comment.