@module-federation/bridge-react 0.0.0-next-20250408084324 → 0.0.0-next-20250410121036
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.
- package/CHANGELOG.md +9 -3
- package/dist/index.cjs.js +64 -136
- package/dist/index.d.ts +24 -1
- package/dist/index.es.js +67 -139
- package/dist/internal/bridge-base-CW88-1Be.es.js +103 -0
- package/dist/internal/bridge-base-DBiwuddQ.cjs.js +119 -0
- package/dist/internal/react-error-boundary.esm-CMdlkNPP.es.js +99 -0
- package/dist/internal/react-error-boundary.esm-D8nxmvmv.cjs.js +98 -0
- package/dist/legacy.cjs.js +4 -0
- package/dist/legacy.d.ts +104 -0
- package/dist/legacy.es.js +4 -0
- package/dist/router-v5.cjs.js +1 -1
- package/dist/router-v5.es.js +1 -1
- package/dist/router-v6.cjs.js +1 -1
- package/dist/router-v6.es.js +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.es.js +1 -1
- package/dist/v16.cjs.js +22 -0
- package/dist/v16.d.ts +104 -0
- package/dist/v16.es.js +22 -0
- package/dist/v18.cjs.js +15 -0
- package/dist/v18.d.ts +105 -0
- package/dist/v18.es.js +15 -0
- package/dist/v19.cjs.js +15 -0
- package/dist/v19.d.ts +106 -0
- package/dist/v19.es.js +15 -0
- package/package.json +19 -4
- package/src/index.ts +6 -0
- package/src/legacy.ts +13 -0
- package/src/provider/create.tsx +73 -20
- package/src/provider/versions/bridge-base.tsx +122 -0
- package/src/provider/versions/legacy.ts +42 -0
- package/src/provider/versions/v18.ts +47 -0
- package/src/provider/versions/v19.ts +48 -0
- package/src/remote/create.tsx +4 -2
- package/src/types.ts +19 -0
- package/src/utils/index.ts +0 -20
- package/src/v18.ts +9 -0
- package/src/v19.ts +9 -0
- package/vite.config.ts +54 -0
- package/src/provider/compat.ts +0 -60
- /package/dist/{context-C79iMWYD.cjs → internal/context.cjs.js} +0 -0
- /package/dist/{context-Dbqf0szX.js → internal/context.es.js} +0 -0
package/dist/v16.d.ts
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import * as React_2 from 'react';
|
|
2
|
+
|
|
3
|
+
export declare function createBridgeComponent<T = any>(bridgeInfo: Omit<ProviderFnParams<T>, 'createRoot'>): () => {
|
|
4
|
+
render(info: RenderParams): Promise<void>;
|
|
5
|
+
destroy(info: DestroyParams): void;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export declare interface CreateRootOptions {
|
|
9
|
+
identifierPrefix?: string;
|
|
10
|
+
onRecoverableError?: (error: unknown, errorInfo: unknown) => void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Options for creating a React root
|
|
15
|
+
*/
|
|
16
|
+
declare interface CreateRootOptions_2 {
|
|
17
|
+
identifierPrefix?: string;
|
|
18
|
+
onRecoverableError?: (error: unknown) => void;
|
|
19
|
+
transitionCallbacks?: unknown;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Parameters for the destroy function
|
|
24
|
+
*/
|
|
25
|
+
export declare interface DestroyParams {
|
|
26
|
+
moduleName: string;
|
|
27
|
+
dom: HTMLElement;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Parameters for the provider function
|
|
32
|
+
*/
|
|
33
|
+
export declare interface ProviderFnParams<T> {
|
|
34
|
+
rootComponent: React_2.ComponentType<T>;
|
|
35
|
+
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
36
|
+
createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions_2) => Root_2;
|
|
37
|
+
/**
|
|
38
|
+
* Default options to pass to createRoot for React 18 and 19
|
|
39
|
+
* These options will be used when creating a root unless overridden by rootOptions in render params
|
|
40
|
+
* @example
|
|
41
|
+
* {
|
|
42
|
+
* identifierPrefix: 'app-',
|
|
43
|
+
* onRecoverableError: (err) => console.error(err)
|
|
44
|
+
* }
|
|
45
|
+
*/
|
|
46
|
+
defaultRootOptions?: CreateRootOptions_2;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Parameters for the provider function
|
|
51
|
+
*/
|
|
52
|
+
export declare interface ProviderParams {
|
|
53
|
+
moduleName?: string;
|
|
54
|
+
basename?: string;
|
|
55
|
+
memoryRoute?: {
|
|
56
|
+
entryPath: string;
|
|
57
|
+
initialState?: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
style?: React_2.CSSProperties;
|
|
60
|
+
className?: string;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Parameters for the render function
|
|
65
|
+
*/
|
|
66
|
+
export declare interface RenderParams {
|
|
67
|
+
moduleName?: string;
|
|
68
|
+
basename?: string;
|
|
69
|
+
memoryRoute?: {
|
|
70
|
+
entryPath: string;
|
|
71
|
+
initialState?: Record<string, unknown>;
|
|
72
|
+
};
|
|
73
|
+
dom: HTMLElement;
|
|
74
|
+
/**
|
|
75
|
+
* Options to pass to createRoot for React 18 and 19
|
|
76
|
+
* @example
|
|
77
|
+
* {
|
|
78
|
+
* identifierPrefix: 'app-',
|
|
79
|
+
* onRecoverableError: (err) => console.error(err)
|
|
80
|
+
* }
|
|
81
|
+
*/
|
|
82
|
+
rootOptions?: CreateRootOptions_2;
|
|
83
|
+
[key: string]: unknown;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export declare interface Root {
|
|
87
|
+
render(children: React.ReactNode): void;
|
|
88
|
+
unmount(): void;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Interface for a React root object
|
|
93
|
+
*/
|
|
94
|
+
declare interface Root_2 {
|
|
95
|
+
render(children: React_2.ReactNode): void;
|
|
96
|
+
unmount(): void;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Type for a root element, which can be either an HTMLElement or a React root
|
|
101
|
+
*/
|
|
102
|
+
export declare type RootType = HTMLElement | Root_2;
|
|
103
|
+
|
|
104
|
+
export { }
|
package/dist/v16.es.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { c as createBaseBridgeComponent } from "./internal/bridge-base-CW88-1Be.es.js";
|
|
2
|
+
import ReactDOM from "react-dom";
|
|
3
|
+
function createReact16Or17Root(container) {
|
|
4
|
+
return {
|
|
5
|
+
render(children) {
|
|
6
|
+
ReactDOM.render(children, container);
|
|
7
|
+
},
|
|
8
|
+
unmount() {
|
|
9
|
+
ReactDOM.unmountComponentAtNode(container);
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
function createBridgeComponent(bridgeInfo) {
|
|
14
|
+
const fullBridgeInfo = {
|
|
15
|
+
...bridgeInfo,
|
|
16
|
+
createRoot: createReact16Or17Root
|
|
17
|
+
};
|
|
18
|
+
return createBaseBridgeComponent(fullBridgeInfo);
|
|
19
|
+
}
|
|
20
|
+
export {
|
|
21
|
+
createBridgeComponent
|
|
22
|
+
};
|
package/dist/v18.cjs.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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 createReact18Root(container, options) {
|
|
6
|
+
return client.createRoot(container, options);
|
|
7
|
+
}
|
|
8
|
+
function createBridgeComponent(bridgeInfo) {
|
|
9
|
+
const fullBridgeInfo = {
|
|
10
|
+
...bridgeInfo,
|
|
11
|
+
createRoot: createReact18Root
|
|
12
|
+
};
|
|
13
|
+
return bridgeBase.createBaseBridgeComponent(fullBridgeInfo);
|
|
14
|
+
}
|
|
15
|
+
exports.createBridgeComponent = createBridgeComponent;
|
package/dist/v18.d.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
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
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Options for creating a React root
|
|
16
|
+
*/
|
|
17
|
+
declare interface CreateRootOptions_2 {
|
|
18
|
+
identifierPrefix?: string;
|
|
19
|
+
onRecoverableError?: (error: unknown) => void;
|
|
20
|
+
transitionCallbacks?: unknown;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Parameters for the destroy function
|
|
25
|
+
*/
|
|
26
|
+
export declare interface DestroyParams {
|
|
27
|
+
moduleName: string;
|
|
28
|
+
dom: HTMLElement;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Parameters for the provider function
|
|
33
|
+
*/
|
|
34
|
+
export declare interface ProviderFnParams<T> {
|
|
35
|
+
rootComponent: React_2.ComponentType<T>;
|
|
36
|
+
render?: (App: React_2.ReactElement, id?: HTMLElement | string) => RootType | Promise<RootType>;
|
|
37
|
+
createRoot?: (container: Element | DocumentFragment, options?: CreateRootOptions_2) => Root_2;
|
|
38
|
+
/**
|
|
39
|
+
* Default options to pass to createRoot for React 18 and 19
|
|
40
|
+
* These options will be used when creating a root unless overridden by rootOptions in render params
|
|
41
|
+
* @example
|
|
42
|
+
* {
|
|
43
|
+
* identifierPrefix: 'app-',
|
|
44
|
+
* onRecoverableError: (err) => console.error(err)
|
|
45
|
+
* }
|
|
46
|
+
*/
|
|
47
|
+
defaultRootOptions?: CreateRootOptions_2;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Parameters for the provider function
|
|
52
|
+
*/
|
|
53
|
+
export declare interface ProviderParams {
|
|
54
|
+
moduleName?: string;
|
|
55
|
+
basename?: string;
|
|
56
|
+
memoryRoute?: {
|
|
57
|
+
entryPath: string;
|
|
58
|
+
initialState?: Record<string, unknown>;
|
|
59
|
+
};
|
|
60
|
+
style?: React_2.CSSProperties;
|
|
61
|
+
className?: string;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Parameters for the render function
|
|
66
|
+
*/
|
|
67
|
+
export declare interface RenderParams {
|
|
68
|
+
moduleName?: string;
|
|
69
|
+
basename?: string;
|
|
70
|
+
memoryRoute?: {
|
|
71
|
+
entryPath: string;
|
|
72
|
+
initialState?: Record<string, unknown>;
|
|
73
|
+
};
|
|
74
|
+
dom: HTMLElement;
|
|
75
|
+
/**
|
|
76
|
+
* Options to pass to createRoot for React 18 and 19
|
|
77
|
+
* @example
|
|
78
|
+
* {
|
|
79
|
+
* identifierPrefix: 'app-',
|
|
80
|
+
* onRecoverableError: (err) => console.error(err)
|
|
81
|
+
* }
|
|
82
|
+
*/
|
|
83
|
+
rootOptions?: CreateRootOptions_2;
|
|
84
|
+
[key: string]: unknown;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export declare interface Root {
|
|
88
|
+
render(children: default_2.ReactNode): void;
|
|
89
|
+
unmount(): void;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Interface for a React root object
|
|
94
|
+
*/
|
|
95
|
+
declare interface Root_2 {
|
|
96
|
+
render(children: React_2.ReactNode): void;
|
|
97
|
+
unmount(): void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Type for a root element, which can be either an HTMLElement or a React root
|
|
102
|
+
*/
|
|
103
|
+
export declare type RootType = HTMLElement | Root_2;
|
|
104
|
+
|
|
105
|
+
export { }
|
package/dist/v18.es.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@module-federation/bridge-react",
|
|
3
|
-
"version": "0.0.0-next-
|
|
3
|
+
"version": "0.0.0-next-20250410121036",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -21,6 +21,21 @@
|
|
|
21
21
|
"import": "./dist/index.es.js",
|
|
22
22
|
"require": "./dist/index.cjs.js"
|
|
23
23
|
},
|
|
24
|
+
"./legacy": {
|
|
25
|
+
"types": "./dist/legacy.d.ts",
|
|
26
|
+
"import": "./dist/legacy.es.js",
|
|
27
|
+
"require": "./dist/legacy.cjs.js"
|
|
28
|
+
},
|
|
29
|
+
"./v18": {
|
|
30
|
+
"types": "./dist/v18.d.ts",
|
|
31
|
+
"import": "./dist/v18.es.js",
|
|
32
|
+
"require": "./dist/v18.cjs.js"
|
|
33
|
+
},
|
|
34
|
+
"./v19": {
|
|
35
|
+
"types": "./dist/v19.d.ts",
|
|
36
|
+
"import": "./dist/v19.es.js",
|
|
37
|
+
"require": "./dist/v19.cjs.js"
|
|
38
|
+
},
|
|
24
39
|
"./router": {
|
|
25
40
|
"types": "./dist/router.d.ts",
|
|
26
41
|
"import": "./dist/router.es.js",
|
|
@@ -45,8 +60,8 @@
|
|
|
45
60
|
},
|
|
46
61
|
"dependencies": {
|
|
47
62
|
"react-error-boundary": "^4.1.2",
|
|
48
|
-
"@module-federation/bridge-shared": "0.0.0-next-
|
|
49
|
-
"@module-federation/sdk": "0.0.0-next-
|
|
63
|
+
"@module-federation/bridge-shared": "0.0.0-next-20250410121036",
|
|
64
|
+
"@module-federation/sdk": "0.0.0-next-20250410121036"
|
|
50
65
|
},
|
|
51
66
|
"peerDependencies": {
|
|
52
67
|
"react": ">=16.9.0",
|
|
@@ -67,7 +82,7 @@
|
|
|
67
82
|
"typescript": "^5.2.2",
|
|
68
83
|
"vite": "^5.4.12",
|
|
69
84
|
"vite-plugin-dts": "^4.3.0",
|
|
70
|
-
"@module-federation/runtime": "0.0.0-next-
|
|
85
|
+
"@module-federation/runtime": "0.0.0-next-20250410121036"
|
|
71
86
|
},
|
|
72
87
|
"scripts": {
|
|
73
88
|
"dev": "vite",
|
package/src/index.ts
CHANGED
|
@@ -6,3 +6,9 @@ export type {
|
|
|
6
6
|
DestroyParams,
|
|
7
7
|
RenderParams,
|
|
8
8
|
} from './types';
|
|
9
|
+
|
|
10
|
+
// 注意:对于特定React版本的支持,请使用以下导入路径:
|
|
11
|
+
// - React 16/17: import { createBridgeComponent } from '@module-federation/bridge-react/legacy'
|
|
12
|
+
// - React 18: import { createBridgeComponent } from '@module-federation/bridge-react/v18'
|
|
13
|
+
// - React 19: import { createBridgeComponent } from '@module-federation/bridge-react/v19'
|
|
14
|
+
// export * from './legacy';
|
package/src/legacy.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
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';
|
package/src/provider/create.tsx
CHANGED
|
@@ -6,15 +6,63 @@ import type {
|
|
|
6
6
|
RootType,
|
|
7
7
|
DestroyParams,
|
|
8
8
|
RenderParams,
|
|
9
|
+
CreateRootOptions,
|
|
9
10
|
} from '../types';
|
|
10
|
-
import { ErrorBoundary } from 'react-error-boundary';
|
|
11
|
+
import { ErrorBoundary, FallbackProps } from 'react-error-boundary';
|
|
11
12
|
import { RouterContext } from './context';
|
|
12
13
|
import { LoggerInstance } from '../utils';
|
|
13
14
|
import { federationRuntime } from './plugin';
|
|
14
|
-
import { createRoot as defaultCreateRoot } from './compat';
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Default createRoot function that automatically detects React version and uses the appropriate API(only support React 16/17, 18)
|
|
18
|
+
*
|
|
19
|
+
* Note: Users can also directly import version-specific bridge components:
|
|
20
|
+
* - import { createBridgeComponent } from '@module-federation/bridge-react/legacy'
|
|
21
|
+
* - import { createBridgeComponent } from '@module-federation/bridge-react/v18'
|
|
22
|
+
* - import { createBridgeComponent } from '@module-federation/bridge-react/v19'
|
|
23
|
+
*/
|
|
24
|
+
function defaultCreateRoot(
|
|
25
|
+
container: Element | DocumentFragment,
|
|
26
|
+
options?: CreateRootOptions,
|
|
27
|
+
): {
|
|
28
|
+
render(children: React.ReactNode): void;
|
|
29
|
+
unmount(): void;
|
|
30
|
+
} {
|
|
31
|
+
const reactVersion = ReactDOM.version || '';
|
|
32
|
+
const isReact18 = reactVersion.startsWith('18');
|
|
33
|
+
|
|
34
|
+
// For React 18, use createRoot API
|
|
35
|
+
if (isReact18) {
|
|
36
|
+
try {
|
|
37
|
+
// @ts-ignore - Types will be available in React 18
|
|
38
|
+
return (ReactDOM as any).createRoot(container, options);
|
|
39
|
+
} catch (e) {
|
|
40
|
+
console.warn(
|
|
41
|
+
'Failed to use React 18 createRoot API, falling back to legacy API',
|
|
42
|
+
e,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// For React 16/17, use legacy API
|
|
48
|
+
return {
|
|
49
|
+
render(children: React.ReactNode) {
|
|
50
|
+
// @ts-ignore - React 17's render method is deprecated but still functional
|
|
51
|
+
ReactDOM.render(children, container);
|
|
52
|
+
},
|
|
53
|
+
unmount() {
|
|
54
|
+
ReactDOM.unmountComponentAtNode(container as Element);
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Creates a bridge component factory that automatically detects and uses
|
|
61
|
+
* the appropriate React version (16/17, 18, or 19)
|
|
62
|
+
*/
|
|
16
63
|
export function createBridgeComponent<T>({
|
|
17
64
|
createRoot = defaultCreateRoot,
|
|
65
|
+
defaultRootOptions,
|
|
18
66
|
...bridgeInfo
|
|
19
67
|
}: ProviderFnParams<T>) {
|
|
20
68
|
return () => {
|
|
@@ -48,14 +96,23 @@ export function createBridgeComponent<T>({
|
|
|
48
96
|
basename,
|
|
49
97
|
memoryRoute,
|
|
50
98
|
fallback,
|
|
99
|
+
rootOptions,
|
|
51
100
|
...propsInfo
|
|
52
101
|
} = info;
|
|
53
102
|
|
|
103
|
+
// Merge default root options with render-specific root options
|
|
104
|
+
const mergedRootOptions: CreateRootOptions | undefined = {
|
|
105
|
+
...defaultRootOptions,
|
|
106
|
+
...(rootOptions as CreateRootOptions),
|
|
107
|
+
};
|
|
108
|
+
|
|
54
109
|
const beforeBridgeRenderRes =
|
|
55
110
|
instance?.bridgeHook?.lifecycle?.beforeBridgeRender?.emit(info) || {};
|
|
56
111
|
|
|
57
112
|
const rootComponentWithErrorBoundary = (
|
|
58
|
-
<ErrorBoundary
|
|
113
|
+
<ErrorBoundary
|
|
114
|
+
FallbackComponent={fallback as React.ComponentType<FallbackProps>}
|
|
115
|
+
>
|
|
59
116
|
<RawComponent
|
|
60
117
|
appInfo={{
|
|
61
118
|
moduleName,
|
|
@@ -63,29 +120,25 @@ export function createBridgeComponent<T>({
|
|
|
63
120
|
memoryRoute,
|
|
64
121
|
}}
|
|
65
122
|
propsInfo={
|
|
66
|
-
{
|
|
123
|
+
{
|
|
124
|
+
...propsInfo,
|
|
125
|
+
...(beforeBridgeRenderRes as any)?.extraProps,
|
|
126
|
+
} as T
|
|
67
127
|
}
|
|
68
128
|
/>
|
|
69
129
|
</ErrorBoundary>
|
|
70
130
|
);
|
|
71
131
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
let root = rootMap.get(dom);
|
|
78
|
-
// do not call createRoot multiple times
|
|
79
|
-
if (!root) {
|
|
80
|
-
root = createRoot(dom);
|
|
81
|
-
rootMap.set(dom, root);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if ('render' in root) {
|
|
85
|
-
root.render(rootComponentWithErrorBoundary);
|
|
86
|
-
}
|
|
132
|
+
let root = rootMap.get(dom);
|
|
133
|
+
// Do not call createRoot multiple times
|
|
134
|
+
if (!root) {
|
|
135
|
+
root = createRoot(dom, mergedRootOptions);
|
|
136
|
+
rootMap.set(dom, root);
|
|
87
137
|
}
|
|
88
138
|
|
|
139
|
+
if ('render' in root) {
|
|
140
|
+
root.render(rootComponentWithErrorBoundary);
|
|
141
|
+
}
|
|
89
142
|
instance?.bridgeHook?.lifecycle?.afterBridgeRender?.emit(info) || {};
|
|
90
143
|
},
|
|
91
144
|
|
|
@@ -97,7 +150,7 @@ export function createBridgeComponent<T>({
|
|
|
97
150
|
if ('unmount' in root) {
|
|
98
151
|
root.unmount();
|
|
99
152
|
} else {
|
|
100
|
-
ReactDOM.unmountComponentAtNode(
|
|
153
|
+
ReactDOM.unmountComponentAtNode(dom as HTMLElement);
|
|
101
154
|
}
|
|
102
155
|
rootMap.delete(dom);
|
|
103
156
|
}
|