Skip to content

Commit

Permalink
fix: disable css cache busting in production (#41392)
Browse files Browse the repository at this point in the history
Continuation of #39664 The PR removes `?ts=` in the production mode.
The corresponding e2e test case is also added.

cc @shuding
  • Loading branch information
SukkaW committed Oct 13, 2022
1 parent 86050df commit e1cb7f7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/next/server/app-render.tsx
Expand Up @@ -1184,7 +1184,9 @@ export async function renderToHTMLOrFlight(
? stylesheets.map((href) => (
<link
rel="stylesheet"
href={`/_next/${href}?ts=${Date.now()}`}
// Add extra cache busting (DEV only) for https://github.com/vercel/next.js/issues/5860
// See also https://bugs.webkit.org/show_bug.cgi?id=187726
href={`/_next/${href}${dev ? `?ts=${Date.now()}` : ''}`}
// `Precedence` is an opt-in signal for React to handle
// resource loading and deduplication, etc:
// https://github.com/facebook/react/pull/25060
Expand Down
14 changes: 14 additions & 0 deletions test/e2e/app-dir/index.test.ts
Expand Up @@ -264,6 +264,20 @@ describe('app dir', () => {
expect(html).toContain('hello from app/partial-match-[id]. ID is: 123')
})

// This is a workaround to fix https://github.com/vercel/next.js/issues/5860
// TODO: remove this workaround when https://bugs.webkit.org/show_bug.cgi?id=187726 is fixed.
it('should use cache busting when loading css (dev only)', async () => {
const html = await renderViaHTTP(next.url, '/')
const $ = cheerio.load(html)
const links = $('link[rel=stylesheet]')
links.each((_, link) => {
const href = $(link).attr('href')
isDev
? expect(href).toMatch(/\?ts=/)
: expect(href).not.toMatch(/\?ts=/)
})
})

describe('rewrites', () => {
// TODO-APP: rewrite url is broken
it('should support rewrites on initial load', async () => {
Expand Down

0 comments on commit e1cb7f7

Please sign in to comment.