Skip to content
Merged
Changes from all commits
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
23 changes: 23 additions & 0 deletions packages/vite/src/node/plugins/css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,16 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
delete bundle[`${fileName}.map`]
})
}

const cssAssets = Object.values(bundle).filter(
(asset): asset is OutputAsset =>
asset.type === 'asset' && asset.fileName.endsWith('.css'),
)
for (const cssAsset of cssAssets) {
if (typeof cssAsset.source === 'string') {
cssAsset.source = cssAsset.source.replace(viteHashUpdateMarkerRE, '')
}
}
},
}
}
Expand Down Expand Up @@ -1562,6 +1572,9 @@ function combineSourcemapsIfExists(
: map1
}

const viteHashUpdateMarker = '/*$vite$:1*/'
const viteHashUpdateMarkerRE = /\/\*\$vite\$:\d+\*\//

async function finalizeCss(
css: string,
minify: boolean,
Expand All @@ -1574,6 +1587,16 @@ async function finalizeCss(
if (minify && config.build.cssMinify) {
css = await minifyCSS(css, config, false)
}
// inject an additional string to generate a different hash for https://github.com/vitejs/vite/issues/18038
//
// pre-5.4.3, we generated CSS link tags without crossorigin attribute and generated an hash without
// this string
// in 5.4.3, we added crossorigin attribute to the generated CSS link tags but that made chromium browsers
// to block the CSSs from loading due to chromium's weird behavior
// (https://www.hacksoft.io/blog/handle-images-cors-error-in-chrome, https://issues.chromium.org/issues/40381978)
// to avoid that happening, we inject an additional string so that a different hash is generated
// for the same CSS content
css += viteHashUpdateMarker
return css
}

Expand Down