Vite: Don't rebase urls that appear to be aliases #16078
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #16039
This PR changes our URL rebasing logic used with Vite so that it does not rebase URLs that look like common alias paths (e.g. urls starting in
~
,@
or#
, etc.). Unfortunately this is only an approximation and you can configure an alias for a path that starts with a regular alphabetical character (e.g.foo
=>./my/foo
) so this isn't a perfect fix, however in practice most aliases will be prefixed with a symbol to make it clear that it's an alias anyways.One alternative we have considered is to only rebase URLs that we know are relative (so they need to start with a
.
). This, however, will break common CSS use cases where urls are loaded like this:So making this change felt like we only trade one GitHub issue for another one.
In a more ideal scenario we try to resolve the URL with the Vite resolver (we have to run the resolver and can't rely on the
resolve
setting alone due to packages likevite-tsconfig-paths
), however even then we can have relative paths being resolvable to different files based on wether they were rebased or not (e.g. when an image with the same filename exists in two different paths).So ultimately we settled on extending the already existing blocklist (which we have taken from the Vite implementation) for now.
Test plan