Skip to content

Commit

Permalink
use helper
Browse files Browse the repository at this point in the history
  • Loading branch information
huozhi committed Jan 16, 2024
1 parent 7ee4424 commit b22ed4c
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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() {
Expand Down
7 changes: 7 additions & 0 deletions packages/next/src/build/webpack/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,10 @@ export function forEachEntryModule(
callback({ name, entryModule })
}
}

export function formatBarrelOptimizedResource(
resource: string,
matchResource: string
) {
return `${resource}@${matchResource}`
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ createNextDescribe(
expect(html).toContain('<linearGradient')
})

it.only('should support MUI', async () => {
it('should support MUI', async () => {
let logs = ''
next.on('stdout', (log) => {
logs += log
Expand Down

0 comments on commit b22ed4c

Please sign in to comment.