File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed
packages/vite/src/node/plugins
playground/assets/__tests__ Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -2021,7 +2021,10 @@ function skipUrlReplacer(unquotedUrl: string) {
2021
2021
isExternalUrl ( unquotedUrl ) ||
2022
2022
isDataUrl ( unquotedUrl ) ||
2023
2023
unquotedUrl [ 0 ] === '#' ||
2024
- functionCallRE . test ( unquotedUrl )
2024
+ functionCallRE . test ( unquotedUrl ) ||
2025
+ // skip if it is already a placeholder
2026
+ unquotedUrl . startsWith ( '__VITE_ASSET__' ) ||
2027
+ unquotedUrl . startsWith ( '__VITE_PUBLIC_ASSET__' )
2025
2028
)
2026
2029
}
2027
2030
async function doUrlReplace (
Original file line number Diff line number Diff line change
1
+ import { describe , expect , test } from 'vitest'
2
+ import { isBuild , serverLogs } from '~utils'
3
+
4
+ // Test for CSS image-set warning issue (PR #20520)
5
+ // This test ensures that when CSS contains image-set() with url() functions,
6
+ // and those URLs get processed to __VITE_ASSET__ tokens, subsequent image-set
7
+ // processing doesn't try to resolve the tokens again, which would cause warnings.
8
+ test . runIf ( isBuild ) (
9
+ 'should not warn about VITE_ASSET tokens in image-set' ,
10
+ async ( ) => {
11
+ // The warning we're looking for:
12
+ // "__VITE_ASSET__xxx__ referenced in __VITE_ASSET__xxx__ didn't resolve at build time"
13
+
14
+ const warningPattern = / V I T E _ A S S E T _ _ .* ?d i d n ' t r e s o l v e a t b u i l d t i m e /
15
+ const warningLogs = serverLogs . filter ( ( log ) => warningPattern . test ( log ) )
16
+
17
+ // The issue occurs when:
18
+ // 1. CSS has image-set with url() functions
19
+ // 2. URL processing converts URLs to __VITE_ASSET__ tokens
20
+ // 3. Image-set processing then tries to process the tokens again
21
+ // 4. This causes false warnings since tokens can't be resolved as files
22
+
23
+ // With the fix in skipUrlReplacer(), asset tokens should be skipped
24
+ expect ( warningLogs . length ) . toBe ( 0 )
25
+ } ,
26
+ )
You can’t perform that action at this time.
0 commit comments