Skip to content

fix(runtime) Fix snapshot for server manifest without ssr remote entry #3249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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/short-lizards-behave.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/runtime': minor
---

fix snapshot for server manifest without ssrRemoteEntry (nextjs-mfe for instance)
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
29 changes: 29 additions & 0 deletions packages/runtime/__tests__/tool.spec.ts
Original file line number Diff line number Diff line change
@@ -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',
});
});
});
7 changes: 7 additions & 0 deletions packages/runtime/src/utils/tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Loading