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/rare-buttons-wash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@module-federation/nextjs-mf': patch
---

fix broken loading of non nextjs json remotes
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { removeUnnecessarySharedKeys } from './remove-unnecessary-shared-keys';

describe('removeUnnecessarySharedKeys', () => {
beforeEach(() => {
jest.spyOn(console, 'warn').mockImplementation(() => {});
jest.spyOn(console, 'warn').mockImplementation(jest.fn());
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import {
} from '@module-federation/enhanced';

class InvertedContainerPlugin {
constructor() {}

public apply(compiler: Compiler): void {
compiler.hooks.thisCompilation.tap(
'EmbeddedContainerPlugin',
Expand Down
21 changes: 9 additions & 12 deletions packages/nextjs-mf/src/plugins/container/runtimePlugin.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { FederationRuntimePlugin } from '@module-federation/runtime/types';
import {
ModuleInfo,
ConsumerModuleInfoWithPublicPath,
} from '@module-federation/sdk';

export default function (): FederationRuntimePlugin {
return {
Expand Down Expand Up @@ -199,22 +195,23 @@ export default function (): FederationRuntimePlugin {
return args;
}

// re-assign publicPath based on remoteEntry location
if (options.inBrowser) {
remoteSnapshot.publicPath = remoteSnapshot.publicPath.substring(
// re-assign publicPath based on remoteEntry location if in browser nextjs remote
const { publicPath } = remoteSnapshot;
if (options.inBrowser && publicPath.includes('/_next/')) {
remoteSnapshot.publicPath = publicPath.substring(
0,
remoteSnapshot.publicPath.lastIndexOf('/_next/') + 7,
publicPath.lastIndexOf('/_next/') + 7,
);
} else {
const serverPublicPath = manifestUrl.substring(
0,
manifestUrl.indexOf('mf-manifest.json'),
);

remoteSnapshot.publicPath = serverPublicPath;
if ('publicPath' in manifestJson.metaData) {
manifestJson.metaData.publicPath = serverPublicPath;
}
}

if ('publicPath' in manifestJson.metaData) {
manifestJson.metaData.publicPath = remoteSnapshot.publicPath;
}

return args;
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs-mf/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export type { FlushedChunksProps } from './flushedChunks';
*/
export const revalidate = function (
fetchModule: any = undefined,
force: boolean = false,
force = false,
): Promise<boolean> {
if (typeof window !== 'undefined') {
console.error('revalidate should only be called server-side');
Expand Down