-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use addDependency to track metadata route file changes (#66714)
Use `addDependency` to track the file path passed to `next-metadata-route-loader` NOTE: We cannot apply the `next-metadata-route-loader` directly to the metatda convention source files, since the json file could be processed by json loader (Related previous fix #62615) Previously when we passed down the file path as argument to the loader, which sort of breaking the caching of webpack as the actual resource path is string, it's not tracked as a dependency. This change fixed the bad caching issue of static metadata routes. Based on the above reason we use `addDependency` here to track the dependency change Closes NEXT-3521 Closes #65755
- Loading branch information
Showing
7 changed files
with
73 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file added
BIN
+5.3 KB
test/production/app-dir/metadata-static-route-cache/app/favicon.ico.new
Binary file not shown.
Binary file added
BIN
+1.51 KB
test/production/app-dir/metadata-static-route-cache/app/opengraph-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+45.6 KB
test/production/app-dir/metadata-static-route-cache/app/opengraph-image.png.new
Binary file not shown.
52 changes: 52 additions & 0 deletions
52
test/production/app-dir/metadata-static-route-cache/metadata-static-route-cache.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters