@module-federation/modern-js 0.0.0-next-20240626050252 → 0.0.0-next-20240701075157

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/README.md CHANGED
@@ -92,8 +92,6 @@ type CreateRemoteSSRComponentOptions = {
92
92
  loader: () => Promise<T>;
93
93
  loading: React.ReactNode;
94
94
  fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
95
- injectScript?: boolean;
96
- injectLink?: boolean;
97
95
  export?: E;
98
96
  };
99
97
 
@@ -167,94 +165,3 @@ Set module loading status.
167
165
  A fault-tolerant component that is rendered when the component fails to **load** or **render**.
168
166
 
169
167
  Note: This component only renders this fault-tolerant component on the client side when **rendering** fails.
170
-
171
- #### injectLink
172
-
173
- - Type:`boolean`
174
- - Required: No
175
- - Default value: `true`
176
-
177
- Whether to inject the style of the corresponding component.
178
-
179
- #### injectScript
180
-
181
- - Type:`boolean`
182
- - Required: No
183
- - Default value: `true`
184
-
185
- Whether to inject the script of the corresponding component.
186
-
187
- ### collectSSRAssets
188
-
189
- ```ts
190
- declare function createRemoteSSRComponent(
191
- props: CollectSSRAssetsOptions
192
- ): React.ReactNode[];
193
-
194
- type CollectSSRAssetsOptions = {
195
- id: string;
196
- injectScript?: boolean;
197
- injectLink?: boolean;
198
- };
199
- ```
200
-
201
- This function collects producer-related scripts and styles rendered on the server side and returns the script/link tag.
202
-
203
- #### Example
204
-
205
- ```tsx
206
- import React from 'react';
207
- import { collectSSRAssets } from '@modern-js/runtime/mf';
208
- import Comp from 'remote/Image';
209
-
210
- export default (): JSX.Element => (
211
- <div>
212
- {collectSSRAssets({ id: 'remote/Image' })}
213
- <Comp />
214
- </div>
215
- );
216
- ```
217
-
218
- #### injectLink
219
-
220
- - Type:`boolean`
221
- - Required: No
222
- - Default value: `true`
223
-
224
- Whether to inject the style of the corresponding component.
225
-
226
- #### injectScript
227
-
228
- - Type:`boolean`
229
- - Required: No
230
- - Default value: `true`
231
-
232
- Whether to inject the script of the corresponding component.
233
-
234
- ### SSRLiveReload
235
-
236
- :::info
237
- This component will not take effect in the production environment!
238
- :::
239
-
240
- ```ts
241
- declare function SSRLiveReload(): React.JSX.Element | null;
242
- ```
243
-
244
- When remote components are updated, page reloads occur automatically.
245
-
246
- #### Example
247
-
248
- ```tsx
249
- import { Outlet } from '@modern-js/runtime/router';
250
- import { SSRLiveReload } from '@modern-js/runtime/mf';
251
-
252
- export default function Layout() {
253
- return (
254
- <div>
255
- <SSRLiveReload />
256
- <Outlet />
257
- </div>
258
- );
259
- }
260
- ```
@@ -149,9 +149,7 @@ function createRemoteSSRComponent(info) {
149
149
  }
150
150
  const moduleId = m && m[Symbol.for("mf_module_id")];
151
151
  const assets = collectSSRAssets({
152
- id: moduleId,
153
- injectLink: info.injectLink,
154
- injectScript: info.injectScript
152
+ id: moduleId
155
153
  });
156
154
  const Com = m[exportName];
157
155
  if (exportName in m && typeof Com === "function") {
@@ -19,18 +19,13 @@ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "defau
19
19
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
20
  var runtime_exports = {};
21
21
  __export(runtime_exports, {
22
- SSRLiveReload: () => import_SSRLiveReload.SSRLiveReload,
23
- collectSSRAssets: () => import_createRemoteSSRComponent.collectSSRAssets,
24
22
  createRemoteSSRComponent: () => import_createRemoteSSRComponent.createRemoteSSRComponent
25
23
  });
26
24
  module.exports = __toCommonJS(runtime_exports);
27
25
  __reExport(runtime_exports, require("@module-federation/enhanced/runtime"), module.exports);
28
26
  var import_createRemoteSSRComponent = require("./createRemoteSSRComponent");
29
- var import_SSRLiveReload = require("./SSRLiveReload");
30
27
  // Annotate the CommonJS export names for ESM import in node:
31
28
  0 && (module.exports = {
32
- SSRLiveReload,
33
- collectSSRAssets,
34
29
  createRemoteSSRComponent,
35
30
  ...require("@module-federation/enhanced/runtime")
36
31
  });
@@ -31,6 +31,9 @@ __export(plugin_exports, {
31
31
  mfPluginSSR: () => mfPluginSSR
32
32
  });
33
33
  module.exports = __toCommonJS(plugin_exports);
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var import_hoist_non_react_statics = __toESM(require("hoist-non-react-statics"));
36
+ var import_SSRLiveReload = require("./SSRLiveReload");
34
37
  const mfPluginSSR = () => ({
35
38
  name: "@module-federation/modern-js",
36
39
  setup: () => {
@@ -52,6 +55,20 @@ const mfPluginSSR = () => ({
52
55
  return next({
53
56
  context
54
57
  });
58
+ },
59
+ hoc({ App, config }, next) {
60
+ const AppWrapper = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, {
61
+ children: [
62
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_SSRLiveReload.SSRLiveReload, {}),
63
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(App, {
64
+ ...props
65
+ })
66
+ ]
67
+ });
68
+ return next({
69
+ App: (0, import_hoist_non_react_statics.default)(AppWrapper, App),
70
+ config
71
+ });
55
72
  }
56
73
  };
57
74
  }
@@ -121,9 +121,7 @@ function createRemoteSSRComponent(info) {
121
121
  }
122
122
  moduleId = m && m[Symbol.for("mf_module_id")];
123
123
  assets = collectSSRAssets({
124
- id: moduleId,
125
- injectLink: info.injectLink,
126
- injectScript: info.injectScript
124
+ id: moduleId
127
125
  });
128
126
  Com = m[exportName];
129
127
  if (exportName in m && typeof Com === "function") {
@@ -1,8 +1,5 @@
1
1
  export * from "@module-federation/enhanced/runtime";
2
- import { createRemoteSSRComponent, collectSSRAssets } from "./createRemoteSSRComponent";
3
- import { SSRLiveReload } from "./SSRLiveReload";
2
+ import { createRemoteSSRComponent } from "./createRemoteSSRComponent";
4
3
  export {
5
- SSRLiveReload,
6
- collectSSRAssets,
7
4
  createRemoteSSRComponent
8
5
  };
@@ -1,5 +1,9 @@
1
1
  import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
+ import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
2
3
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
4
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
5
+ import hoistNonReactStatics from "hoist-non-react-statics";
6
+ import { SSRLiveReload } from "./SSRLiveReload";
3
7
  var mfPluginSSR = function() {
4
8
  return {
5
9
  name: "@module-federation/modern-js",
@@ -57,6 +61,21 @@ var mfPluginSSR = function() {
57
61
  }
58
62
  });
59
63
  })();
64
+ },
65
+ hoc: function hoc(param, next) {
66
+ var App = param.App, config = param.config;
67
+ var AppWrapper = function(props) {
68
+ return /* @__PURE__ */ _jsxs(_Fragment, {
69
+ children: [
70
+ /* @__PURE__ */ _jsx(SSRLiveReload, {}),
71
+ /* @__PURE__ */ _jsx(App, _object_spread({}, props))
72
+ ]
73
+ });
74
+ };
75
+ return next({
76
+ App: hoistNonReactStatics(AppWrapper, App),
77
+ config
78
+ });
60
79
  }
61
80
  };
62
81
  }
@@ -115,9 +115,7 @@ function createRemoteSSRComponent(info) {
115
115
  }
116
116
  const moduleId = m && m[Symbol.for("mf_module_id")];
117
117
  const assets = collectSSRAssets({
118
- id: moduleId,
119
- injectLink: info.injectLink,
120
- injectScript: info.injectScript
118
+ id: moduleId
121
119
  });
122
120
  const Com = m[exportName];
123
121
  if (exportName in m && typeof Com === "function") {
@@ -1,8 +1,5 @@
1
1
  export * from "@module-federation/enhanced/runtime";
2
- import { createRemoteSSRComponent, collectSSRAssets } from "./createRemoteSSRComponent";
3
- import { SSRLiveReload } from "./SSRLiveReload";
2
+ import { createRemoteSSRComponent } from "./createRemoteSSRComponent";
4
3
  export {
5
- SSRLiveReload,
6
- collectSSRAssets,
7
4
  createRemoteSSRComponent
8
5
  };
@@ -1,3 +1,6 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import hoistNonReactStatics from "hoist-non-react-statics";
3
+ import { SSRLiveReload } from "./SSRLiveReload";
1
4
  const mfPluginSSR = () => ({
2
5
  name: "@module-federation/modern-js",
3
6
  setup: () => {
@@ -19,6 +22,20 @@ const mfPluginSSR = () => ({
19
22
  return next({
20
23
  context
21
24
  });
25
+ },
26
+ hoc({ App, config }, next) {
27
+ const AppWrapper = (props) => /* @__PURE__ */ _jsxs(_Fragment, {
28
+ children: [
29
+ /* @__PURE__ */ _jsx(SSRLiveReload, {}),
30
+ /* @__PURE__ */ _jsx(App, {
31
+ ...props
32
+ })
33
+ ]
34
+ });
35
+ return next({
36
+ App: hoistNonReactStatics(AppWrapper, App),
37
+ config
38
+ });
22
39
  }
23
40
  };
24
41
  }
@@ -5,39 +5,39 @@ export type ConfigType<T> = T extends 'webpack' ? webpack.Configuration : T exte
5
5
  export declare const getMFConfig: (userConfig: PluginOptions) => Promise<moduleFederationPlugin.ModuleFederationPluginOptions>;
6
6
  export declare const patchMFConfig: (mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean) => {
7
7
  runtimePlugins: string[];
8
- exposes?: moduleFederationPlugin.Exposes | undefined;
9
- filename?: string | undefined;
10
- library?: moduleFederationPlugin.LibraryOptions | undefined;
11
- name?: string | undefined;
12
- remoteType?: moduleFederationPlugin.ExternalsType | undefined;
13
- remotes?: moduleFederationPlugin.Remotes | undefined;
14
- runtime?: moduleFederationPlugin.EntryRuntime | undefined;
15
- shareScope?: string | undefined;
16
- shared?: moduleFederationPlugin.Shared | undefined;
17
- getPublicPath?: string | undefined;
18
- implementation?: string | undefined;
19
- manifest?: boolean | moduleFederationPlugin.PluginManifestOptions | undefined;
20
- dev?: boolean | moduleFederationPlugin.PluginDevOptions | undefined;
21
- dts?: boolean | moduleFederationPlugin.PluginDtsOptions | undefined;
22
- async?: boolean | moduleFederationPlugin.AsyncBoundaryOptions | undefined;
8
+ exposes?: moduleFederationPlugin.Exposes;
9
+ filename?: string;
10
+ library?: moduleFederationPlugin.LibraryOptions;
11
+ name?: string;
12
+ remoteType?: moduleFederationPlugin.ExternalsType;
13
+ remotes?: moduleFederationPlugin.Remotes;
14
+ runtime?: moduleFederationPlugin.EntryRuntime;
15
+ shareScope?: string;
16
+ shared?: moduleFederationPlugin.Shared;
17
+ getPublicPath?: string;
18
+ implementation?: string;
19
+ manifest?: boolean | moduleFederationPlugin.PluginManifestOptions;
20
+ dev?: boolean | moduleFederationPlugin.PluginDevOptions;
21
+ dts?: boolean | moduleFederationPlugin.PluginDtsOptions;
22
+ async?: boolean | moduleFederationPlugin.AsyncBoundaryOptions;
23
23
  };
24
24
  export declare function getTargetEnvConfig(mfConfig: moduleFederationPlugin.ModuleFederationPluginOptions, isServer: boolean): {
25
25
  runtimePlugins: string[];
26
- exposes?: moduleFederationPlugin.Exposes | undefined;
27
- filename?: string | undefined;
28
- library?: moduleFederationPlugin.LibraryOptions | undefined;
29
- name?: string | undefined;
30
- remoteType?: moduleFederationPlugin.ExternalsType | undefined;
31
- remotes?: moduleFederationPlugin.Remotes | undefined;
32
- runtime?: moduleFederationPlugin.EntryRuntime | undefined;
33
- shareScope?: string | undefined;
34
- shared?: moduleFederationPlugin.Shared | undefined;
35
- getPublicPath?: string | undefined;
36
- implementation?: string | undefined;
37
- manifest?: boolean | moduleFederationPlugin.PluginManifestOptions | undefined;
38
- dev?: boolean | moduleFederationPlugin.PluginDevOptions | undefined;
39
- dts?: boolean | moduleFederationPlugin.PluginDtsOptions | undefined;
40
- async?: boolean | moduleFederationPlugin.AsyncBoundaryOptions | undefined;
26
+ exposes?: moduleFederationPlugin.Exposes;
27
+ filename?: string;
28
+ library?: moduleFederationPlugin.LibraryOptions;
29
+ name?: string;
30
+ remoteType?: moduleFederationPlugin.ExternalsType;
31
+ remotes?: moduleFederationPlugin.Remotes;
32
+ runtime?: moduleFederationPlugin.EntryRuntime;
33
+ shareScope?: string;
34
+ shared?: moduleFederationPlugin.Shared;
35
+ getPublicPath?: string;
36
+ implementation?: string;
37
+ manifest?: boolean | moduleFederationPlugin.PluginManifestOptions;
38
+ dev?: boolean | moduleFederationPlugin.PluginDevOptions;
39
+ dts?: boolean | moduleFederationPlugin.PluginDtsOptions;
40
+ async?: boolean | moduleFederationPlugin.AsyncBoundaryOptions;
41
41
  };
42
42
  export declare function patchWebpackConfig<T>(options: {
43
43
  bundlerConfig: ConfigType<T>;
@@ -10,8 +10,6 @@ export declare function createRemoteSSRComponent<T, E extends keyof T>(info: {
10
10
  loader: () => Promise<T>;
11
11
  loading: React.ReactNode;
12
12
  fallback: ErrorBoundaryPropsWithComponent['FallbackComponent'];
13
- injectScript?: boolean;
14
- injectLink?: boolean;
15
13
  export?: E;
16
14
  }): (props: T[E] extends (...args: any) => any ? Parameters<T[E]>[0] extends undefined ? Record<string, never> : Parameters<T[E]>[0] : Record<string, never>) => React.JSX.Element;
17
15
  export {};
@@ -1,3 +1,2 @@
1
1
  export * from '@module-federation/enhanced/runtime';
2
- export { createRemoteSSRComponent, collectSSRAssets, } from './createRemoteSSRComponent';
3
- export { SSRLiveReload } from './SSRLiveReload';
2
+ export { createRemoteSSRComponent } from './createRemoteSSRComponent';
@@ -1,2 +1 @@
1
- /// <reference types="react" />
2
1
  export declare function SSRLiveReload(): import("react").JSX.Element | null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@module-federation/modern-js",
3
- "version": "0.0.0-next-20240626050252",
3
+ "version": "0.0.0-next-20240701075157",
4
4
  "files": [
5
5
  "dist/",
6
6
  "types.d.ts",
@@ -47,17 +47,19 @@
47
47
  "@modern-js/node-bundle-require": "^2.54.2",
48
48
  "node-fetch": "~3.3.0",
49
49
  "react-error-boundary": "4.0.13",
50
- "@module-federation/sdk": "0.0.0-next-20240626050252",
51
- "@module-federation/enhanced": "0.0.0-next-20240626050252",
52
- "@module-federation/node": "0.0.0-next-20240626050252"
50
+ "hoist-non-react-statics": "3.3.2",
51
+ "@module-federation/sdk": "0.0.0-next-20240701075157",
52
+ "@module-federation/enhanced": "0.0.0-next-20240701075157",
53
+ "@module-federation/node": "0.0.0-next-20240701075157"
53
54
  },
54
55
  "devDependencies": {
56
+ "@types/hoist-non-react-statics": "3.3.2",
55
57
  "@modern-js/app-tools": "^2.54.2",
56
58
  "@modern-js/core": "^2.54.2",
57
59
  "@modern-js/runtime": "^2.54.2",
58
60
  "@modern-js/module-tools": "^2.54.2",
59
61
  "@modern-js/tsconfig": "^2.54.2",
60
- "@module-federation/manifest": "0.0.0-next-20240626050252"
62
+ "@module-federation/manifest": "0.0.0-next-20240701075157"
61
63
  },
62
64
  "peerDependencies": {
63
65
  "react": ">=17",