Skip to content

Comments

test(css): add test for #20520#20541

Merged
sapphi-red merged 4 commits intomainfrom
copilot/fix-bfb212b2-8126-4d48-9ce4-5440ec1417ac
Aug 6, 2025
Merged

test(css): add test for #20520#20541
sapphi-red merged 4 commits intomainfrom
copilot/fix-bfb212b2-8126-4d48-9ce4-5440ec1417ac

Conversation

Copy link
Contributor

Copilot AI commented Aug 5, 2025

Problem

After commit d59efd8, users encountered false warnings when building CSS files containing image-set() with url() functions, especially when processed through preprocessors like LESS or SCSS:

__VITE_ASSET__BgDL8UKD__ referenced in __VITE_ASSET__BgDL8UKD__ didn't resolve at build time, it will remain unchanged to be resolved at runtime

This occurred with CSS like:

.image-from-set(@prop; @path-1x) {
    @{prop}: image-set(@path-1x 1x);
}

.test {
    .image-from-set(background-image, url("./img.png"));
}

Root Cause

The issue was introduced by the sequential processing logic in UrlRewritePostcssPlugin when both isCssUrl and isCssImageSet are true:

  1. rewriteCssUrls() processes the CSS and replaces URLs with __VITE_ASSET__ tokens
  2. rewriteCssImageSet() then processes the result, which contains the asset tokens
  3. Inside rewriteCssImageSet(), the logic detects url(__VITE_ASSET__xxx__) patterns and attempts to process them again via rewriteCssUrls()
  4. This double processing causes the resolver to try resolving the __VITE_ASSET__ token as a file path, which fails and generates the warning

Solution

Enhanced the existing skipUrlReplacer() function to detect and skip asset tokens using simple startsWith checks:

function skipUrlReplacer(unquotedUrl: string) {
  return (
    isExternalUrl(unquotedUrl) ||
    isDataUrl(unquotedUrl) ||
    unquotedUrl[0] === '#' ||
    functionCallRE.test(unquotedUrl) ||
    unquotedUrl.startsWith('__VITE_ASSET__') ||
    unquotedUrl.startsWith('__VITE_PUBLIC_ASSET__')
  )
}

This approach prevents double processing of URLs that already contain asset tokens across all URL processing functions, eliminating false warnings while maintaining correct asset resolution and final CSS output. The solution covers both regular and public asset tokens with a more readable and performant implementation than the previous regex approach.

Testing

The fix resolves the warning in:

  • Original reproduction case with LESS preprocessing
  • Assets playground test case with image-set() and url() combinations
  • Maintains correct asset transformation and final CSS output

Added integration test playground/assets/__tests__/image-set-warning.spec.ts that verifies no __VITE_ASSET__ warnings are generated during build, preventing regression of this issue.

refs #20520

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • vite.dev
    • Triggering command: /home/REDACTED/.cache/playwright-bin/chromium_headless_shell-1181/chrome-linux/headless_shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AutoExpandDetailsElement,AvoidUnnecessaryBeforeUnloadCheckSync,CertificateTransparencyComponentUpdater,DestroyProfileOnBrowserClose,DialMediaRouteProvider,ExtensionManifestV2Disabled,GlobalMediaControls,HttpsUpgrades,ImprovedCookieControls,LazyFrameLoading,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate,AutoDeElevate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --edge-skip-compat-layer-relaunch --enable-automation --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-sandbox --disable-setuid-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-Urgqdd --remote-debugging-pipe --no-startup-window (dns block)
    • Triggering command: /home/REDACTED/.cache/playwright-bin/chromium_headless_shell-1181/chrome-linux/headless_shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AutoExpandDetailsElement,AvoidUnnecessaryBeforeUnloadCheckSync,CertificateTransparencyComponentUpdater,DestroyProfileOnBrowserClose,DialMediaRouteProvider,ExtensionManifestV2Disabled,GlobalMediaControls,HttpsUpgrades,ImprovedCookieControls,LazyFrameLoading,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate,AutoDeElevate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --edge-skip-compat-layer-relaunch --enable-automation --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-sandbox --disable-setuid-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-e2Bt8D --remote-debugging-pipe --no-startup-window (dns block)
    • Triggering command: /home/REDACTED/.cache/playwright-bin/chromium_headless_shell-1181/chrome-linux/headless_shell --disable-field-trial-config --disable-REDACTED-networking --disable-REDACTED-timer-throttling --disable-REDACTEDing-occluded-windows --disable-back-forward-cache --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-REDACTED-pages --disable-component-update --no-default-browser-check --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=AcceptCHFrame,AutoExpandDetailsElement,AvoidUnnecessaryBeforeUnloadCheckSync,CertificateTransparencyComponentUpdater,DestroyProfileOnBrowserClose,DialMediaRouteProvider,ExtensionManifestV2Disabled,GlobalMediaControls,HttpsUpgrades,ImprovedCookieControls,LazyFrameLoading,LensOverlay,MediaRouter,PaintHolding,ThirdPartyStoragePartitioning,Translate,AutoDeElevate --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-REDACTEDing --force-color-profile=srgb --metrics-recording-only --no-first-run --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --disable-search-engine-choice-screen --unsafely-disable-devtools-self-xss-warnings --edge-skip-compat-layer-relaunch --enable-automation --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --no-sandbox --disable-setuid-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-QFcRPl --remote-debugging-pipe --no-startup-window (dns block)
  • workers.cloudflare.com
    • Triggering command: node (vitest 3) (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Add a test for the issue @vitejs/vite/pull/20520 fixed. Check the tests whether the warning was happening before the change in that PR. If the warning was happening, add the test that ensures that warning is not output. fix(css): avoid warnings for image-set containing __VITE_ASSET__ tokens Aug 5, 2025
Copilot AI requested a review from sapphi-red August 5, 2025 09:01
Copilot AI requested a review from sapphi-red August 6, 2025 01:39
@sapphi-red sapphi-red marked this pull request as ready for review August 6, 2025 02:02
@sapphi-red sapphi-red changed the title fix(css): avoid warnings for image-set containing __VITE_ASSET__ tokens test(css): add test for #20520 Aug 6, 2025
@sapphi-red sapphi-red added p1-chore Doesn't change code behavior (priority) test labels Aug 6, 2025
@sapphi-red sapphi-red merged commit 8d31eea into main Aug 6, 2025
22 checks passed
@sapphi-red sapphi-red deleted the copilot/fix-bfb212b2-8126-4d48-9ce4-5440ec1417ac branch August 6, 2025 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

p1-chore Doesn't change code behavior (priority) test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants