Skip to content

Commit 0a6bf5a

Browse files
authored
Merge branch 'main' into fix-nextjs-mf-remote-loading
2 parents 3b7c08e + fa7a0bd commit 0a6bf5a

File tree

17 files changed

+494
-349
lines changed

17 files changed

+494
-349
lines changed

.changeset/shaggy-ligers-teach.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/manifest': patch
3+
---
4+
5+
fix(manifest): stats should add prefetchInterface if enable dataPrefetch

.changeset/small-eyes-change.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@module-federation/retry-plugin': patch
3+
'@module-federation/runtime': patch
4+
---
5+
6+
feat: add remote-entry script resource retry for retry-plugin

apps/router-demo/router-host-2000/rsbuild.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default defineConfig({
3131
shared: ['react', 'react-dom', 'antd'],
3232
runtimePlugins: [
3333
path.join(__dirname, './src/runtime-plugin/shared-strategy.ts'),
34-
// path.join(__dirname, './src/runtime-plugin/retry.ts'),
34+
path.join(__dirname, './src/runtime-plugin/retry.ts'),
3535
],
3636
// bridge: {
3737
// disableAlias: true,

apps/router-demo/router-host-2000/src/App.tsx

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,22 @@ init({
1414
remotes: [],
1515
plugins: [
1616
BridgeReactPlugin(),
17-
RetryPlugin({
18-
fetch: {
19-
url: 'http://localhost:2008/not-exist-mf-manifest.json',
20-
fallback: () => 'http://localhost:2001/mf-manifest.json',
21-
},
22-
script: {
23-
retryTimes: 3,
24-
retryDelay: 1000,
25-
moduleName: ['remote1'],
26-
cb: (resolve, error) => {
27-
return setTimeout(() => {
28-
resolve(error);
29-
}, 1000);
30-
},
31-
},
32-
}),
17+
// RetryPlugin({
18+
// fetch: {
19+
// url: 'http://localhost:2008/not-exist-mf-manifest.json',
20+
// fallback: () => 'http://localhost:2001/mf-manifest.json',
21+
// },
22+
// script: {
23+
// retryTimes: 3,
24+
// retryDelay: 1000,
25+
// moduleName: ['remote1'],
26+
// cb: (resolve, error) => {
27+
// return setTimeout(() => {
28+
// resolve(error);
29+
// }, 1000);
30+
// },
31+
// },
32+
// }),
3333
],
3434
});
3535

apps/website-new/docs/en/guide/basic/runtime.mdx

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,12 @@ type ShareArgs =
8787
| (SharedBaseArgs & { lib: () => Module });
8888

8989
type SharedBaseArgs = {
90-
version: string;
90+
version?: string;
9191
shareConfig?: SharedConfig;
9292
scope?: string | Array<string>;
9393
deps?: Array<string>;
9494
strategy?: 'version-first' | 'loaded-first';
95+
loaded?: boolean;
9596
};
9697

9798
type SharedGetter = (() => () => Module) | (() => Promise<() => Module>);
@@ -112,22 +113,32 @@ interface RemotesWithEntry {
112113

113114
type ShareInfos = {
114115
// The name of the dependency, basic information about the dependency, and sharing strategy
115-
[pkgName: string]: Share;
116+
[pkgName: string]: Shared[];
116117
};
117118

118-
type Share = {
119+
type Shared = {
119120
// The version of the shared dependency
120121
version: string;
121122
// Which modules are currently consuming this dependency
122-
useIn?: Array<string>;
123+
useIn: Array<string>;
123124
// From which module does the shared dependency come?
124-
from?: string;
125+
from: string;
125126
// Factory function to get the shared dependency instance. When no other existing dependencies, it will load its own shared dependencies.
126-
lib: () => Module;
127+
lib?: () => Module;
127128
// Sharing strategy, which strategy will be used to decide whether to reuse the dependency
128-
shareConfig?: SharedConfig;
129+
shareConfig: SharedConfig;
129130
// The scope where the shared dependency is located, the default value is default
130-
scope?: string | Array<string>;
131+
scope: Array<string>;
132+
// Function to retrieve the shared dependency instance.
133+
get: SharedGetter;
134+
// List of dependencies that this shared module depends on
135+
deps: Array<string>;
136+
// Indicates whether the shared dependency has been loaded
137+
loaded?: boolean;
138+
// Represents the loading state of the shared dependency
139+
loading?: null | Promise<any>;
140+
// Determines if the shared dependency should be loaded eagerly
141+
eager?: boolean;
131142
};
132143
```
133144

apps/website-new/docs/en/plugin/dev/index.mdx

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,36 @@ const changeScriptAttributePlugin: () => FederationRuntimePlugin = function () {
534534
};
535535
```
536536

537+
### fetch
538+
The `fetch` function allows customizing the request that fetches the manifest JSON. A successful `Response` must yield a valid JSON.
539+
540+
`AsyncHook`
541+
542+
- **Type**
543+
544+
```typescript
545+
function fetch(manifestUrl: string, requestInit: RequestInit): Promise<Response> | void | false;
546+
```
547+
548+
- Example for including the credentials when fetching the manifest JSON:
549+
550+
```typescript
551+
// fetch-manifest-with-credentials-plugin.ts
552+
import type { FederationRuntimePlugin } from '@module-federation/enhanced/runtime';
553+
554+
export default function (): FederationRuntimePlugin {
555+
return {
556+
name: 'fetch-manifest-with-credentials-plugin',
557+
fetch(manifestUrl, requestInit) {
558+
return fetch(manifestUrl, {
559+
...requestInit,
560+
credentials: 'include'
561+
});
562+
},
563+
}
564+
};
565+
```
566+
537567
### loadEntry
538568
The `loadEntry` function allows for full customization of remotes, enabling you to extend and create new remote types. The following two simple examples demonstrate loading JSON data and module delegation.
539569

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
"devDependencies": {
9898
"@babel/core": "^7.24.7",
9999
"@babel/plugin-transform-react-jsx": "7.25.9",
100-
"@babel/preset-react": "^7.24.7",
100+
"@babel/preset-react": "^7.26.3",
101101
"@changesets/cli": "^2.27.9",
102102
"@chromatic-com/storybook": "^1.7.0",
103103
"@commitlint/cli": "^19.4.1",

packages/chrome-devtools/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@modern-js/storybook": "2.60.6",
7575
"@modern-js/tsconfig": "2.60.6",
7676
"@module-federation/runtime": "workspace:*",
77-
"@playwright/test": "1.48.2",
77+
"@playwright/test": "1.49.1",
7878
"@storybook/addon-essentials": "^8",
7979
"@types/chrome": "^0.0.272",
8080
"@types/dagre": "^0.7.52",

packages/manifest/src/ManifestManager.ts

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import path from 'path';
21
import fs from 'fs';
32
import chalk from 'chalk';
43
import {
@@ -103,20 +102,6 @@ class ManifestManager {
103102
return sum;
104103
}, [] as ManifestRemote[]);
105104

106-
let prefetchInterface = false;
107-
const prefetchFilePath = path.resolve(
108-
compiler.options.context || process.cwd(),
109-
`node_modules/.mf/${encodeName(stats.name)}/${MFPrefetchCommon.fileName}`,
110-
);
111-
const existPrefetch = fs.existsSync(prefetchFilePath);
112-
if (existPrefetch) {
113-
const content = fs.readFileSync(prefetchFilePath).toString();
114-
if (content) {
115-
prefetchInterface = true;
116-
}
117-
}
118-
stats.metaData.prefetchInterface = prefetchInterface;
119-
120105
this._manifest = manifest;
121106

122107
const manifestFileName = this.fileName;

packages/manifest/src/StatsManager.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
/* eslint-disable max-lines-per-function */
22
/* eslint-disable @typescript-eslint/member-ordering */
33
/* eslint-disable max-depth */
4-
4+
import fs from 'fs';
5+
import path from 'path';
56
import {
67
StatsRemote,
78
StatsBuildInfo,
@@ -11,6 +12,8 @@ import {
1112
StatsAssets,
1213
moduleFederationPlugin,
1314
RemoteEntryType,
15+
encodeName,
16+
MFPrefetchCommon,
1417
} from '@module-federation/sdk';
1518
import {
1619
Compilation,
@@ -136,6 +139,20 @@ class StatsManager {
136139
pluginVersion: this._pluginVersion,
137140
};
138141

142+
let prefetchInterface = false;
143+
const prefetchFilePath = path.resolve(
144+
compiler.options.context || process.cwd(),
145+
`node_modules/.mf/${encodeName(name!)}/${MFPrefetchCommon.fileName}`,
146+
);
147+
const existPrefetch = fs.existsSync(prefetchFilePath);
148+
if (existPrefetch) {
149+
const content = fs.readFileSync(prefetchFilePath).toString();
150+
if (content) {
151+
prefetchInterface = true;
152+
}
153+
}
154+
metaData.prefetchInterface = prefetchInterface;
155+
139156
if (this._options.getPublicPath) {
140157
if ('publicPath' in metaData) {
141158
delete metaData.publicPath;

0 commit comments

Comments
 (0)