diff --git a/packages/nextjs-mf/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.test.ts b/packages/nextjs-mf/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.test.ts index 4d16f4e23c..cf39803267 100644 --- a/packages/nextjs-mf/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.test.ts +++ b/packages/nextjs-mf/src/plugins/NextFederationPlugin/remove-unnecessary-shared-keys.test.ts @@ -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(() => { diff --git a/packages/nextjs-mf/src/plugins/container/InvertedContainerPlugin.ts b/packages/nextjs-mf/src/plugins/container/InvertedContainerPlugin.ts index 34dbc71c4c..75265765e7 100644 --- a/packages/nextjs-mf/src/plugins/container/InvertedContainerPlugin.ts +++ b/packages/nextjs-mf/src/plugins/container/InvertedContainerPlugin.ts @@ -6,8 +6,6 @@ import { } from '@module-federation/enhanced'; class InvertedContainerPlugin { - constructor() {} - public apply(compiler: Compiler): void { compiler.hooks.thisCompilation.tap( 'EmbeddedContainerPlugin', diff --git a/packages/nextjs-mf/src/plugins/container/runtimePlugin.ts b/packages/nextjs-mf/src/plugins/container/runtimePlugin.ts index 049133e6f1..558dbcc0bb 100644 --- a/packages/nextjs-mf/src/plugins/container/runtimePlugin.ts +++ b/packages/nextjs-mf/src/plugins/container/runtimePlugin.ts @@ -1,8 +1,4 @@ import { FederationRuntimePlugin } from '@module-federation/runtime/types'; -import { - ModuleInfo, - ConsumerModuleInfoWithPublicPath, -} from '@module-federation/sdk'; export default function (): FederationRuntimePlugin { return { @@ -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; diff --git a/packages/nextjs-mf/utils/index.ts b/packages/nextjs-mf/utils/index.ts index 7ed60901de..cf867c8cf6 100644 --- a/packages/nextjs-mf/utils/index.ts +++ b/packages/nextjs-mf/utils/index.ts @@ -22,7 +22,7 @@ export type { FlushedChunksProps } from './flushedChunks'; */ export const revalidate = function ( fetchModule: any = undefined, - force: boolean = false, + force = false, ): Promise { if (typeof window !== 'undefined') { console.error('revalidate should only be called server-side');