Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/weak-spoons-begin.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/modern-js': patch
---

fix(modern-js-plugin): adjust fetch type
20 changes: 14 additions & 6 deletions packages/modernjs/src/cli/mfRuntimePlugins/auto-fetch-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,26 @@ const autoFetchData: () => FederationRuntimePlugin = () => ({
}

const dataFetchMap = getDataFetchMap();
const downgradeType = remoteSnapshot.modules.find(
(module) =>
module.moduleName === `${dataFetchName}${DATA_FETCH_CLIENT_SUFFIX}`,
)
const hasSSRAsset = Boolean(remoteSnapshot.ssrRemoteEntry);
const hasDataFetchClient = Boolean(
remoteSnapshot.modules.find(
(module) =>
module.moduleName === `${dataFetchName}${DATA_FETCH_CLIENT_SUFFIX}`,
),
);
const downgradeType = hasDataFetchClient
? MF_DATA_FETCH_TYPE.FETCH_CLIENT
: MF_DATA_FETCH_TYPE.FETCH_SERVER;
: hasSSRAsset
? MF_DATA_FETCH_TYPE.FETCH_SERVER
: MF_DATA_FETCH_TYPE.FETCH_CLIENT;
let finalDataFetchId = dataFetchId;

if (typeof window !== 'undefined') {
finalDataFetchId =
downgradeType === MF_DATA_FETCH_TYPE.FETCH_CLIENT
? `${dataFetchId}${DATA_FETCH_CLIENT_SUFFIX}`
? hasDataFetchClient
? `${dataFetchId}${DATA_FETCH_CLIENT_SUFFIX}`
: dataFetchId
: dataFetchId;
}

Expand Down
1 change: 1 addition & 0 deletions packages/node/src/runtimePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ export const resolveUrl = (
} catch {
const entryUrl =
returnFromCache(remoteName) || returnFromGlobalInstances(remoteName);

if (!entryUrl) return null;

const url = new URL(entryUrl);
Expand Down