Skip to content

Commit 4239338

Browse files
fix(nextjs-mf): fix broken loading of non nextjs remotes (#3323)
Co-authored-by: Zack Jackson <[email protected]> Co-authored-by: ScriptedAlchemy <[email protected]>
1 parent af91416 commit 4239338

File tree

5 files changed

+16
-16
lines changed

5 files changed

+16
-16
lines changed

.changeset/rare-buttons-wash.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@module-federation/nextjs-mf': patch
3+
---
4+
5+
fix broken loading of non nextjs json remotes

packages/nextjs-mf/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { removeUnnecessarySharedKeys } from './remove-unnecessary-shared-keys';
22

33
describe('removeUnnecessarySharedKeys', () => {
44
beforeEach(() => {
5-
jest.spyOn(console, 'warn').mockImplementation(() => {});
5+
jest.spyOn(console, 'warn').mockImplementation(jest.fn());
66
});
77

88
afterEach(() => {

packages/nextjs-mf/src/plugins/container/InvertedContainerPlugin.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import {
66
} from '@module-federation/enhanced';
77

88
class InvertedContainerPlugin {
9-
constructor() {}
10-
119
public apply(compiler: Compiler): void {
1210
compiler.hooks.thisCompilation.tap(
1311
'EmbeddedContainerPlugin',

packages/nextjs-mf/src/plugins/container/runtimePlugin.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
import { FederationRuntimePlugin } from '@module-federation/runtime/types';
2-
import {
3-
ModuleInfo,
4-
ConsumerModuleInfoWithPublicPath,
5-
} from '@module-federation/sdk';
62

73
export default function (): FederationRuntimePlugin {
84
return {
@@ -199,22 +195,23 @@ export default function (): FederationRuntimePlugin {
199195
return args;
200196
}
201197

202-
// re-assign publicPath based on remoteEntry location
203-
if (options.inBrowser) {
204-
remoteSnapshot.publicPath = remoteSnapshot.publicPath.substring(
198+
// re-assign publicPath based on remoteEntry location if in browser nextjs remote
199+
const { publicPath } = remoteSnapshot;
200+
if (options.inBrowser && publicPath.includes('/_next/')) {
201+
remoteSnapshot.publicPath = publicPath.substring(
205202
0,
206-
remoteSnapshot.publicPath.lastIndexOf('/_next/') + 7,
203+
publicPath.lastIndexOf('/_next/') + 7,
207204
);
208205
} else {
209206
const serverPublicPath = manifestUrl.substring(
210207
0,
211208
manifestUrl.indexOf('mf-manifest.json'),
212209
);
213-
214210
remoteSnapshot.publicPath = serverPublicPath;
215-
if ('publicPath' in manifestJson.metaData) {
216-
manifestJson.metaData.publicPath = serverPublicPath;
217-
}
211+
}
212+
213+
if ('publicPath' in manifestJson.metaData) {
214+
manifestJson.metaData.publicPath = remoteSnapshot.publicPath;
218215
}
219216

220217
return args;

packages/nextjs-mf/utils/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export type { FlushedChunksProps } from './flushedChunks';
2222
*/
2323
export const revalidate = function (
2424
fetchModule: any = undefined,
25-
force: boolean = false,
25+
force = false,
2626
): Promise<boolean> {
2727
if (typeof window !== 'undefined') {
2828
console.error('revalidate should only be called server-side');

0 commit comments

Comments
 (0)