Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use addDependency to track metadata route file changes #66714

Merged
merged 3 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 1 addition & 3 deletions packages/next/src/build/webpack/loaders/next-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,8 @@ async function createAppRouteCode({
const isDynamicRouteExtension = pageExtensions.includes(ext)

resolvedPagePath = `next-metadata-route-loader?${stringify({
page,
filePath: resolvedPagePath,
isDynamicRouteExtension: isDynamicRouteExtension ? '1' : '0',
})}!?${WEBPACK_RESOURCE_QUERIES.metadataRoute}`
})}!${resolvedPagePath}?${WEBPACK_RESOURCE_QUERIES.metadataRoute}`
}

const pathname = new AppPathnameNormalizer().normalize(page)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@ const cacheHeader = {
}

type MetadataRouteLoaderOptions = {
page: string
huozhi marked this conversation as resolved.
Show resolved Hide resolved
filePath: string
isDynamicRouteExtension: '1' | '0'
isDynamicMultiRoute: '1' | '0'
}

export function getFilenameAndExtension(resourcePath: string) {
Expand Down Expand Up @@ -246,7 +243,8 @@ ${staticGenerationCode}
// TODO-METADATA: improve the cache control strategy
const nextMetadataRouterLoader: webpack.LoaderDefinitionFunction<MetadataRouteLoaderOptions> =
async function () {
const { isDynamicRouteExtension, filePath } = this.getOptions()
const { isDynamicRouteExtension } = this.getOptions()
const filePath = this.resourcePath
const { name: fileBaseName } = getFilenameAndExtension(filePath)

let code = ''
Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { nextTestSetup } from 'e2e-utils'
import crypto from 'crypto'

function generateMD5(text: string) {
const hash = crypto.createHash('md5')
hash.update(text)
return hash.digest('hex')
}

describe('app dir - metadata static routes cache', () => {
const { next } = nextTestSetup({
files: __dirname,
skipStart: true,
})

it('should generate different content after replace the static metadata file', async () => {
await next.build()

const faviconBuildContent = await next.readFile(
'.next/server/app/favicon.ico.body'
)
const opengrpahImageBuildContent = await next.readFile(
'.next/server/app/opengraph-image.png.body'
)

const faviconMd5 = generateMD5(faviconBuildContent)
const opengraphImageMd5 = generateMD5(opengrpahImageBuildContent)

// Update favicon and opengraph image
const newFaviconContent = await next.readFile('app/favicon.ico.new')
await next.patchFile('app/favicon.ico', newFaviconContent)

const newOpengraphImageContent = await next.readFile(
'app/opengraph-image.png.new'
)
await next.patchFile('app/opengraph-image.png', newOpengraphImageContent)

await next.build()
const faviconBuildContentNew = await next.readFile(
'.next/server/app/favicon.ico.body'
)
const opengrpahImageBuildContentNew = await next.readFile(
'.next/server/app/opengraph-image.png.body'
)

const faviconMd5New = generateMD5(faviconBuildContentNew)
const opengraphImageMd5New = generateMD5(opengrpahImageBuildContentNew)

expect(faviconMd5).not.toBe(faviconMd5New)
expect(opengraphImageMd5).not.toBe(opengraphImageMd5New)
})
})
Loading