@module-federation/bridge-react 0.0.0-next-20250410121036 → 0.0.0-next-20250411200445

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +4 -8
  2. package/dist/index.cjs.js +136 -64
  3. package/dist/index.d.ts +1 -24
  4. package/dist/index.es.js +139 -67
  5. package/dist/router-v5.cjs.js +1 -1
  6. package/dist/router-v5.es.js +1 -1
  7. package/dist/router-v6.cjs.js +1 -1
  8. package/dist/router-v6.es.js +1 -1
  9. package/dist/router.cjs.js +1 -1
  10. package/dist/router.es.js +1 -1
  11. package/package.json +4 -19
  12. package/src/index.ts +0 -6
  13. package/src/provider/compat.ts +60 -0
  14. package/src/provider/create.tsx +20 -73
  15. package/src/remote/create.tsx +2 -4
  16. package/src/types.ts +0 -19
  17. package/src/utils/index.ts +20 -0
  18. package/vite.config.ts +0 -54
  19. package/dist/internal/bridge-base-CW88-1Be.es.js +0 -103
  20. package/dist/internal/bridge-base-DBiwuddQ.cjs.js +0 -119
  21. package/dist/internal/react-error-boundary.esm-CMdlkNPP.es.js +0 -99
  22. package/dist/internal/react-error-boundary.esm-D8nxmvmv.cjs.js +0 -98
  23. package/dist/legacy.cjs.js +0 -4
  24. package/dist/legacy.d.ts +0 -104
  25. package/dist/legacy.es.js +0 -4
  26. package/dist/v16.cjs.js +0 -22
  27. package/dist/v16.d.ts +0 -104
  28. package/dist/v16.es.js +0 -22
  29. package/dist/v18.cjs.js +0 -15
  30. package/dist/v18.d.ts +0 -105
  31. package/dist/v18.es.js +0 -15
  32. package/dist/v19.cjs.js +0 -15
  33. package/dist/v19.d.ts +0 -106
  34. package/dist/v19.es.js +0 -15
  35. package/src/legacy.ts +0 -13
  36. package/src/provider/versions/bridge-base.tsx +0 -122
  37. package/src/provider/versions/legacy.ts +0 -42
  38. package/src/provider/versions/v18.ts +0 -47
  39. package/src/provider/versions/v19.ts +0 -48
  40. package/src/v18.ts +0 -9
  41. package/src/v19.ts +0 -9
  42. /package/dist/{internal/context.cjs.js → context-C79iMWYD.cjs} +0 -0
  43. /package/dist/{internal/context.es.js → context-Dbqf0szX.js} +0 -0
package/dist/v18.es.js DELETED
@@ -1,15 +0,0 @@
1
- import { createRoot } from "react-dom/client";
2
- import { c as createBaseBridgeComponent } from "./internal/bridge-base-CW88-1Be.es.js";
3
- function createReact18Root(container, options) {
4
- return createRoot(container, options);
5
- }
6
- function createBridgeComponent(bridgeInfo) {
7
- const fullBridgeInfo = {
8
- ...bridgeInfo,
9
- createRoot: createReact18Root
10
- };
11
- return createBaseBridgeComponent(fullBridgeInfo);
12
- }
13
- export {
14
- createBridgeComponent
15
- };
package/dist/v19.cjs.js DELETED
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const client = require("react-dom/client");
4
- const bridgeBase = require("./internal/bridge-base-DBiwuddQ.cjs.js");
5
- function createReact19Root(container, options) {
6
- return client.createRoot(container, options);
7
- }
8
- function createBridgeComponent(bridgeInfo) {
9
- const fullBridgeInfo = {
10
- ...bridgeInfo,
11
- createRoot: createReact19Root
12
- };
13
- return bridgeBase.createBaseBridgeComponent(fullBridgeInfo);
14
- }
15
- exports.createBridgeComponent = createBridgeComponent;
package/dist/v19.d.ts DELETED
@@ -1,106 +0,0 @@
1
- import { default as default_2 } from 'react';
2
- import * as React_2 from 'react';
3
-
4
- export declare function createBridgeComponent<T = any>(bridgeInfo: Omit<ProviderFnParams<T>, 'createRoot'>): () => {
5
- render(info: RenderParams): Promise<void>;
6
- destroy(info: DestroyParams): void;
7
- };
8
-
9
- export declare interface CreateRootOptions {
10
- identifierPrefix?: string;
11
- onRecoverableError?: (error: unknown, errorInfo: unknown) => void;
12
- transitionCallbacks?: unknown;
13
- }
14
-
15
- /**
16
- * Options for creating a React root
17
- */
18
- declare interface CreateRootOptions_2 {
19
- identifierPrefix?: string;
20
- onRecoverableError?: (error: unknown) => void;
21
- transitionCallbacks?: unknown;
22
- }
23
-
24
- /**
25
- * Parameters for the destroy function
26
- */
27
- export declare interface DestroyParams {
28
- moduleName: string;
29
- dom: HTMLElement;
30
- }
31
-
32
- /**
33
- * Parameters for the provider function
34
- */
35
- export declare interface ProviderFnParams<T> {
36
- rootComponent: React_2.ComponentType<T>;
37
- render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
38
- createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions_2) => Root_2;
39
- /**
40
- * Default options to pass to createRoot for React 18 and 19
41
- * These options will be used when creating a root unless overridden by rootOptions in render params
42
- * @example
43
- * {
44
- * identifierPrefix: 'app-',
45
- * onRecoverableError: (err) => console.error(err)
46
- * }
47
- */
48
- defaultRootOptions?: CreateRootOptions_2;
49
- }
50
-
51
- /**
52
- * Parameters for the provider function
53
- */
54
- export declare interface ProviderParams {
55
- moduleName?: string;
56
- basename?: string;
57
- memoryRoute?: {
58
- entryPath: string;
59
- initialState?: Record<string, unknown>;
60
- };
61
- style?: React_2.CSSProperties;
62
- className?: string;
63
- }
64
-
65
- /**
66
- * Parameters for the render function
67
- */
68
- export declare interface RenderParams {
69
- moduleName?: string;
70
- basename?: string;
71
- memoryRoute?: {
72
- entryPath: string;
73
- initialState?: Record<string, unknown>;
74
- };
75
- dom: HTMLElement;
76
- /**
77
- * Options to pass to createRoot for React 18 and 19
78
- * @example
79
- * {
80
- * identifierPrefix: 'app-',
81
- * onRecoverableError: (err) => console.error(err)
82
- * }
83
- */
84
- rootOptions?: CreateRootOptions_2;
85
- [key: string]: unknown;
86
- }
87
-
88
- export declare interface Root {
89
- render(children: default_2.ReactNode): void;
90
- unmount(): void;
91
- }
92
-
93
- /**
94
- * Interface for a React root object
95
- */
96
- declare interface Root_2 {
97
- render(children: React_2.ReactNode): void;
98
- unmount(): void;
99
- }
100
-
101
- /**
102
- * Type for a root element, which can be either an HTMLElement or a React root
103
- */
104
- export declare type RootType = HTMLElement | Root_2;
105
-
106
- export { }
package/dist/v19.es.js DELETED
@@ -1,15 +0,0 @@
1
- import { createRoot } from "react-dom/client";
2
- import { c as createBaseBridgeComponent } from "./internal/bridge-base-CW88-1Be.es.js";
3
- function createReact19Root(container, options) {
4
- return createRoot(container, options);
5
- }
6
- function createBridgeComponent(bridgeInfo) {
7
- const fullBridgeInfo = {
8
- ...bridgeInfo,
9
- createRoot: createReact19Root
10
- };
11
- return createBaseBridgeComponent(fullBridgeInfo);
12
- }
13
- export {
14
- createBridgeComponent
15
- };
package/src/legacy.ts DELETED
@@ -1,13 +0,0 @@
1
- /**
2
- * Entry point for React 16/17 (legacy) specific bridge components
3
- * This file provides support for React 16 and 17 versions, using the traditional ReactDOM.render API
4
- */
5
- export { createBridgeComponent } from './provider/versions/legacy';
6
- export type { CreateRootOptions, Root } from './provider/versions/legacy';
7
- export type {
8
- ProviderParams,
9
- ProviderFnParams,
10
- RootType,
11
- DestroyParams,
12
- RenderParams,
13
- } from './types';
@@ -1,122 +0,0 @@
1
- /**
2
- * Base bridge component implementation
3
- * This file contains bridge component logic shared across all React versions
4
- */
5
- import * as React from 'react';
6
- import type {
7
- ProviderParams,
8
- ProviderFnParams,
9
- RootType,
10
- DestroyParams,
11
- RenderParams,
12
- CreateRootOptions,
13
- } from '../../types';
14
- import { ErrorBoundary, FallbackProps } from 'react-error-boundary';
15
- import { RouterContext } from '../context';
16
- import { LoggerInstance } from '../../utils';
17
- import { federationRuntime } from '../plugin';
18
-
19
- export function createBaseBridgeComponent<T>({
20
- createRoot,
21
- defaultRootOptions,
22
- ...bridgeInfo
23
- }: ProviderFnParams<T>) {
24
- return () => {
25
- const rootMap = new Map<any, RootType>();
26
- const instance = federationRuntime.instance;
27
- LoggerInstance.debug(
28
- `createBridgeComponent instance from props >>>`,
29
- instance,
30
- );
31
-
32
- const RawComponent = (info: { propsInfo: T; appInfo: ProviderParams }) => {
33
- const { appInfo, propsInfo, ...restProps } = info;
34
- const { moduleName, memoryRoute, basename = '/' } = appInfo;
35
- return (
36
- <RouterContext.Provider value={{ moduleName, basename, memoryRoute }}>
37
- <bridgeInfo.rootComponent
38
- {...propsInfo}
39
- basename={basename}
40
- {...restProps}
41
- />
42
- </RouterContext.Provider>
43
- );
44
- };
45
-
46
- return {
47
- async render(info: RenderParams) {
48
- LoggerInstance.debug(`createBridgeComponent render Info`, info);
49
- const {
50
- moduleName,
51
- dom,
52
- basename,
53
- memoryRoute,
54
- fallback,
55
- rootOptions,
56
- ...propsInfo
57
- } = info;
58
-
59
- const mergedRootOptions: CreateRootOptions | undefined = {
60
- ...defaultRootOptions,
61
- ...(rootOptions as CreateRootOptions),
62
- };
63
-
64
- const beforeBridgeRenderRes =
65
- instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(info) || {};
66
-
67
- const rootComponentWithErrorBoundary = (
68
- <ErrorBoundary
69
- FallbackComponent={fallback as React.ComponentType<FallbackProps>}
70
- >
71
- <RawComponent
72
- appInfo={{
73
- moduleName,
74
- basename,
75
- memoryRoute,
76
- }}
77
- propsInfo={
78
- {
79
- ...propsInfo,
80
- ...(beforeBridgeRenderRes as any)?.extraProps,
81
- } as T
82
- }
83
- />
84
- </ErrorBoundary>
85
- );
86
-
87
- if (bridgeInfo.render) {
88
- await Promise.resolve(
89
- bridgeInfo.render(rootComponentWithErrorBoundary, dom),
90
- ).then((root: RootType) => rootMap.set(dom, root));
91
- } else {
92
- let root = rootMap.get(dom);
93
- // Do not call createRoot multiple times
94
- if (!root && createRoot) {
95
- root = createRoot(dom, mergedRootOptions);
96
- rootMap.set(dom, root as any);
97
- }
98
-
99
- if (root && 'render' in root) {
100
- root.render(rootComponentWithErrorBoundary);
101
- }
102
- }
103
- instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
104
- },
105
-
106
- destroy(info: DestroyParams) {
107
- const { dom } = info;
108
- LoggerInstance.debug(`createBridgeComponent destroy Info`, info);
109
- const root = rootMap.get(dom);
110
- if (root) {
111
- if ('unmount' in root) {
112
- root.unmount();
113
- } else {
114
- console.warn('Root does not have unmount method');
115
- }
116
- rootMap.delete(dom);
117
- }
118
- instance?.bridgeHook?.lifecycle?.afterBridgeDestroy?.emit(info);
119
- },
120
- };
121
- };
122
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * Entry point for React 16/17 (legacy) specific bridge components
3
- * This file provides support for React 16 and 17 versions, using the traditional ReactDOM.render API
4
- */
5
- import type { ProviderFnParams } from '../../types';
6
- import { createBaseBridgeComponent } from './bridge-base';
7
- import ReactDOM from 'react-dom';
8
-
9
- export interface CreateRootOptions {
10
- identifierPrefix?: string;
11
- onRecoverableError?: (error: unknown, errorInfo: unknown) => void;
12
- }
13
-
14
- export interface Root {
15
- render(children: React.ReactNode): void;
16
- unmount(): void;
17
- }
18
-
19
- export function createReact16Or17Root(
20
- container: Element | DocumentFragment,
21
- ): Root {
22
- return {
23
- render(children: React.ReactNode) {
24
- // @ts-ignore - React 17's render method is deprecated but still functional
25
- ReactDOM.render(children, container);
26
- },
27
- unmount() {
28
- ReactDOM.unmountComponentAtNode(container as Element);
29
- },
30
- };
31
- }
32
-
33
- export function createBridgeComponent<T = any>(
34
- bridgeInfo: Omit<ProviderFnParams<T>, 'createRoot'>,
35
- ) {
36
- const fullBridgeInfo = {
37
- ...bridgeInfo,
38
- createRoot: createReact16Or17Root,
39
- } as unknown as ProviderFnParams<T>;
40
-
41
- return createBaseBridgeComponent(fullBridgeInfo);
42
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * Entry point for React 18 specific bridge components
3
- */
4
- import React from 'react';
5
- import { createRoot as createReactRoot, hydrateRoot } from 'react-dom/client';
6
- import { createBaseBridgeComponent } from './bridge-base';
7
- import type { ProviderFnParams } from '../../types';
8
-
9
- export interface CreateRootOptions {
10
- identifierPrefix?: string;
11
- onRecoverableError?: (error: unknown, errorInfo: unknown) => void;
12
- }
13
-
14
- export interface Root {
15
- render(children: React.ReactNode): void;
16
- unmount(): void;
17
- }
18
-
19
- export function createReact18Root(
20
- container: Element | DocumentFragment,
21
- options?: CreateRootOptions,
22
- ): Root {
23
- return createReactRoot(container, options);
24
- }
25
-
26
- export function hydrateReact18Root(
27
- container: Element | DocumentFragment,
28
- initialChildren: React.ReactNode,
29
- options?: CreateRootOptions,
30
- ) {
31
- return hydrateRoot(
32
- container as Element,
33
- initialChildren as React.ReactElement,
34
- options,
35
- );
36
- }
37
-
38
- export function createBridgeComponent<T = any>(
39
- bridgeInfo: Omit<ProviderFnParams<T>, 'createRoot'>,
40
- ) {
41
- const fullBridgeInfo = {
42
- ...bridgeInfo,
43
- createRoot: createReact18Root,
44
- } as unknown as ProviderFnParams<T>;
45
-
46
- return createBaseBridgeComponent(fullBridgeInfo);
47
- }
@@ -1,48 +0,0 @@
1
- /**
2
- * Entry point for React 19 specific bridge components
3
- * This file provides support for React 19 version, using the new ReactDOM.createRoot API
4
- */
5
- import React from 'react';
6
- import { createRoot, hydrateRoot } from 'react-dom/client';
7
- import { createBaseBridgeComponent } from './bridge-base';
8
- import type { ProviderFnParams } from '../../types';
9
- export interface CreateRootOptions {
10
- identifierPrefix?: string;
11
- onRecoverableError?: (error: unknown, errorInfo: unknown) => void;
12
- transitionCallbacks?: unknown;
13
- }
14
-
15
- export interface Root {
16
- render(children: React.ReactNode): void;
17
- unmount(): void;
18
- }
19
-
20
- export function createReact19Root(
21
- container: Element | DocumentFragment,
22
- options?: CreateRootOptions,
23
- ): Root {
24
- return createRoot(container as Element, options);
25
- }
26
-
27
- export function hydrateReact19Root(
28
- container: Element | DocumentFragment,
29
- initialChildren: React.ReactNode,
30
- options?: CreateRootOptions,
31
- ): Root {
32
- return hydrateRoot(
33
- container as Element,
34
- initialChildren as React.ReactElement,
35
- options,
36
- );
37
- }
38
-
39
- export function createBridgeComponent<T = any>(
40
- bridgeInfo: Omit<ProviderFnParams<T>, 'createRoot'>,
41
- ) {
42
- const fullBridgeInfo = {
43
- ...bridgeInfo,
44
- createRoot: createReact19Root,
45
- } as unknown as ProviderFnParams<T>;
46
-
47
- return createBaseBridgeComponent(fullBridgeInfo);
48
- }
package/src/v18.ts DELETED
@@ -1,9 +0,0 @@
1
- export { createBridgeComponent } from './provider/versions/v18';
2
- export type { CreateRootOptions, Root } from './provider/versions/v18';
3
- export type {
4
- ProviderParams,
5
- ProviderFnParams,
6
- RootType,
7
- DestroyParams,
8
- RenderParams,
9
- } from './types';
package/src/v19.ts DELETED
@@ -1,9 +0,0 @@
1
- export { createBridgeComponent } from './provider/versions/v19';
2
- export type { CreateRootOptions, Root } from './provider/versions/v19';
3
- export type {
4
- ProviderParams,
5
- ProviderFnParams,
6
- RootType,
7
- DestroyParams,
8
- RenderParams,
9
- } from './types';