Subscribe on changes!

Relative URLs in srcset are not transformed

avatar
Oct 20th 2021

It looks like @vue/compiler-sfc has a bug, introduced in v3.0.0-beta.9 when adding support for absolute URLs in srcset. This bug bypasses the transformation that would've resolved the asset URLs in srcset.

Version

3.2.20

Reproduction link

https://github.com/tony19-sandbox/vue-srcset-relative-urls-bug

Steps to reproduce

  1. In a template, add an <img> with a srcset that contains relative URLs with path aliases:
<img srcset="@/assets/300.png 2x, @/assets/150.png 1x">
  1. Start the dev server with yarn dev.

  2. Observe no image is shown in the browser, and that the <img>.srcset URLs are unresolved.

What is expected?

  • The srcset URLs are resolved:
<img srcset="/src/assets/300.png 2x, /src/assets/150.png 1x">
  • The image appears in the browser.

What is actually happening?

  • The srcset URLs are unresolved:
<img srcset="/src/@/assets/300.png 2x, /src/@/assets/150.png 1x">
             ^^^^^^^^^^^^^^^^^^^^^     ^^^^^^^^^^^^^^^^^^^^^
  • The image is not shown.