From b22ed4c2128cba55c1c490d1bf0eb2b1edf62e4f Mon Sep 17 00:00:00 2001 From: Jiachi Liu Date: Tue, 16 Jan 2024 19:51:44 +0100 Subject: [PATCH] use helper --- .../src/build/webpack/loaders/next-flight-loader/index.ts | 6 +++++- .../build/webpack/plugins/flight-client-entry-plugin.ts | 8 ++++++-- .../src/build/webpack/plugins/flight-manifest-plugin.ts | 8 ++++++-- packages/next/src/build/webpack/utils.ts | 7 +++++++ .../basic/barrel-optimization/barrel-optimization.test.ts | 2 +- 5 files changed, 25 insertions(+), 6 deletions(-) diff --git a/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts b/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts index d6c2a0a0cbde9..897f86b6ff7e8 100644 --- a/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts +++ b/packages/next/src/build/webpack/loaders/next-flight-loader/index.ts @@ -5,6 +5,7 @@ import { } from '../../../../shared/lib/constants' import { warnOnce } from '../../../../shared/lib/utils/warn-once' import { getRSCModuleInformation } from '../../../analysis/get-page-static-info' +import { formatBarrelOptimizedResource } from '../../utils' import { getModuleBuildInfo } from '../get-module-build-info' const noopHeadPath = require.resolve('next/dist/client/components/noop-head') @@ -41,7 +42,10 @@ export default function transformSource( // differentiate them. let resourceKey: string = this.resourcePath if (this._module?.matchResource?.startsWith(BARREL_OPTIMIZATION_PREFIX)) { - resourceKey += '@' + this._module.matchResource + resourceKey = formatBarrelOptimizedResource( + resourceKey, + this._module.matchResource + ) } // A client boundary. diff --git a/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts b/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts index e4cb0f96643c2..360f01a9612a6 100644 --- a/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts @@ -29,7 +29,11 @@ import { isCSSMod, regexCSS, } from '../loaders/utils' -import { traverseModules, forEachEntryModule } from '../utils' +import { + traverseModules, + forEachEntryModule, + formatBarrelOptimizedResource, +} from '../utils' import { normalizePathSep } from '../../../shared/lib/page-path/normalize-path-sep' import { getProxiedPluginState } from '../../build-context' import { generateRandomActionKeyRaw } from '../../../server/app-render/action-encryption-utils' @@ -196,7 +200,7 @@ export class FlightClientEntryPlugin { // so it's only necessary to add it for matchResource or mod.resourceResolveData const modResource = modPath ? modPath.startsWith(BARREL_OPTIMIZATION_PREFIX) - ? mod.resource + '@' + modPath + ? formatBarrelOptimizedResource(mod.resource, modPath) : modPath + modQuery : mod.resource diff --git a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts index 51fae4aa344be..f9af3cd2d4626 100644 --- a/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts +++ b/packages/next/src/build/webpack/plugins/flight-manifest-plugin.ts @@ -19,6 +19,7 @@ import { WEBPACK_LAYERS } from '../../../lib/constants' import { normalizePagePath } from '../../../shared/lib/page-path/normalize-page-path' import { CLIENT_STATIC_FILES_RUNTIME_MAIN_APP } from '../../../shared/lib/constants' import { getDeploymentIdQueryOrEmptyString } from '../../deployment-id' +import { formatBarrelOptimizedResource } from '../utils' interface Options { dev: boolean @@ -319,8 +320,11 @@ export class ClientReferenceManifestPlugin { // as multiple modules (depending on what you import from it). // See also: webpack/loaders/next-flight-loader/index.ts. if (mod.matchResource?.startsWith(BARREL_OPTIMIZATION_PREFIX)) { - ssrNamedModuleId += '@' + mod.matchResource - resource += '@' + mod.matchResource + ssrNamedModuleId = formatBarrelOptimizedResource( + ssrNamedModuleId, + mod.matchResource + ) + resource = formatBarrelOptimizedResource(resource, mod.matchResource) } function addClientReference() { diff --git a/packages/next/src/build/webpack/utils.ts b/packages/next/src/build/webpack/utils.ts index 95aa01b18bc23..dbc0fa1ccf24f 100644 --- a/packages/next/src/build/webpack/utils.ts +++ b/packages/next/src/build/webpack/utils.ts @@ -77,3 +77,10 @@ export function forEachEntryModule( callback({ name, entryModule }) } } + +export function formatBarrelOptimizedResource( + resource: string, + matchResource: string +) { + return `${resource}@${matchResource}` +} diff --git a/test/development/basic/barrel-optimization/barrel-optimization.test.ts b/test/development/basic/barrel-optimization/barrel-optimization.test.ts index 2343c4efc38ad..b20179e489cd5 100644 --- a/test/development/basic/barrel-optimization/barrel-optimization.test.ts +++ b/test/development/basic/barrel-optimization/barrel-optimization.test.ts @@ -130,7 +130,7 @@ createNextDescribe( expect(html).toContain(' { + it('should support MUI', async () => { let logs = '' next.on('stdout', (log) => { logs += log