@@ -954,6 +954,16 @@ export function cssPostPlugin(config: ResolvedConfig): Plugin {
954954 delete bundle [ `${ fileName } .map` ]
955955 } )
956956 }
957+
958+ const cssAssets = Object . values ( bundle ) . filter (
959+ ( asset ) : asset is OutputAsset =>
960+ asset . type === 'asset' && asset . fileName . endsWith ( '.css' ) ,
961+ )
962+ for ( const cssAsset of cssAssets ) {
963+ if ( typeof cssAsset . source === 'string' ) {
964+ cssAsset . source = cssAsset . source . replace ( viteHashUpdateMarkerRE , '' )
965+ }
966+ }
957967 } ,
958968 }
959969}
@@ -1562,6 +1572,9 @@ function combineSourcemapsIfExists(
15621572 : map1
15631573}
15641574
1575+ const viteHashUpdateMarker = '/*$vite$:1*/'
1576+ const viteHashUpdateMarkerRE = / \/ \* \$ v i t e \$ : \d + \* \/ /
1577+
15651578async function finalizeCss (
15661579 css : string ,
15671580 minify : boolean ,
@@ -1574,6 +1587,16 @@ async function finalizeCss(
15741587 if ( minify && config . build . cssMinify ) {
15751588 css = await minifyCSS ( css , config , false )
15761589 }
1590+ // inject an additional string to generate a different hash for https://github.com/vitejs/vite/issues/18038
1591+ //
1592+ // pre-5.4.3, we generated CSS link tags without crossorigin attribute and generated an hash without
1593+ // this string
1594+ // in 5.4.3, we added crossorigin attribute to the generated CSS link tags but that made chromium browsers
1595+ // to block the CSSs from loading due to chromium's weird behavior
1596+ // (https://www.hacksoft.io/blog/handle-images-cors-error-in-chrome, https://issues.chromium.org/issues/40381978)
1597+ // to avoid that happening, we inject an additional string so that a different hash is generated
1598+ // for the same CSS content
1599+ css += viteHashUpdateMarker
15771600 return css
15781601}
15791602
0 commit comments