From e6457714be2e0211b8dfd3a3ab0a20cb576ee172 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Henrique=20Rodrigues=20Ara=C3=BAjo?= Date: Mon, 18 Nov 2024 09:03:26 -0300 Subject: [PATCH 1/2] fix(runtime): fix snapshot for server manifest without ssrRemoteEntry --- CONTRIBUTING.md | 8 +++++++ packages/runtime/__tests__/tool.spec.ts | 29 +++++++++++++++++++++++++ packages/runtime/src/utils/tool.ts | 7 ++++++ 3 files changed, 44 insertions(+) create mode 100644 packages/runtime/__tests__/tool.spec.ts diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 47f54e363e7..fcf7614f7d6 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -18,6 +18,7 @@ Thank you for your interest in contributing to Module Federation! Before startin **Note:** - Keep your PRs concise, addressing a single issue or feature. - Include a detailed description in your PR and link to related issues. +- For an up-to-date sequency of tasks to be performed in order to buil/test the libraries refer to the [buil-and-test workflow](./.github/workflows/build-and-test.yml) ## Setup Development Environment @@ -58,6 +59,13 @@ What this will do: - Install all dependencies - Create symlinks between packages in the monorepo +### Building + +To properly run some tests and packages you may need to build the existing packages, to do that simply run: + +```sh +px nx run-many --targets=build --projects=tag:type:pkg +``` ## Testing diff --git a/packages/runtime/__tests__/tool.spec.ts b/packages/runtime/__tests__/tool.spec.ts new file mode 100644 index 00000000000..8c546f1b65c --- /dev/null +++ b/packages/runtime/__tests__/tool.spec.ts @@ -0,0 +1,29 @@ +import { type ModuleInfo } from '@module-federation/sdk'; +import { getRemoteEntryInfoFromSnapshot } from '../src/utils'; + +const originalWindow = global.window; + +describe('tool', () => { + afterAll(() => { + global.window = originalWindow; + }); + it('return remoteEntry when server manifest does not contain ssrRemoteEntry', () => { + // Server environment + (global as any).window = undefined; + + const snapshot = { + remoteEntry: + 'http://localhost:1111/resources/snapshot/remote1/federation-manifest.json', + remoteEntryType: 'global', + globalName: 'remote1', + } as ModuleInfo; + + const result = getRemoteEntryInfoFromSnapshot(snapshot); + + expect(result).toEqual({ + url: 'http://localhost:1111/resources/snapshot/remote1/federation-manifest.json', + type: 'global', + globalName: 'remote1', + }); + }); +}); diff --git a/packages/runtime/src/utils/tool.ts b/packages/runtime/src/utils/tool.ts index f7cafbfda6c..3c8a54d63ca 100644 --- a/packages/runtime/src/utils/tool.ts +++ b/packages/runtime/src/utils/tool.ts @@ -103,6 +103,13 @@ export function getRemoteEntryInfoFromSnapshot(snapshot: ModuleInfo): { type: snapshot.ssrRemoteEntryType || defaultRemoteEntryInfo.type, globalName: snapshot.globalName, }; + } else if ('remoteEntry' in snapshot) { + // Some plugins may not have ssrRemoteEntry, but have remoteEntry on their manifest (like nextjs-mf) + return { + url: snapshot.remoteEntry || defaultRemoteEntryInfo.url, + type: snapshot.remoteEntryType || defaultRemoteEntryInfo.type, + globalName: snapshot.globalName || defaultRemoteEntryInfo.globalName, + }; } return defaultRemoteEntryInfo; } From 734d305f911eaf8cff5f2c868a7835cc0d85ecad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Henrique=20Rodrigues=20Ara=C3=BAjo?= Date: Mon, 18 Nov 2024 09:13:44 -0300 Subject: [PATCH 2/2] fix(runtime): add changeset --- .changeset/short-lizards-behave.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/short-lizards-behave.md diff --git a/.changeset/short-lizards-behave.md b/.changeset/short-lizards-behave.md new file mode 100644 index 00000000000..a5f2fa625b1 --- /dev/null +++ b/.changeset/short-lizards-behave.md @@ -0,0 +1,5 @@ +--- +'@module-federation/runtime': minor +--- + +fix snapshot for server manifest without ssrRemoteEntry (nextjs-mfe for instance)