Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vite: Fix issues when loading files via static asset queries #14716

Conversation

philipp-spiess
Copy link
Member

@philipp-spiess philipp-spiess commented Oct 18, 2024

Fixes: #14558

This PR fixes an issue where our Vite plugin would crash when trying to load stylesheets via certain static asset query parameters:

import raw from './style.css?raw'
import url from './style.css?url'

The proper behavior for our extension is to not touch these file at all. The ?raw identifier should never transform anything and the ?url one will emit a module which points to the asset URL. However, if that URL is loaded as a stylesheet, another transform hook is called and the file is properly transformed. I verified this in the Vite setup and have added an integration test ensuring these two features work as expected.

I've also greatly reduced the complexity of the Vite playground to make it easier to set up examples like this in the future.

Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @philipp-spiess and the rest of your teammates on Graphite Graphite

@philipp-spiess philipp-spiess marked this pull request as ready for review October 18, 2024 12:25
@philipp-spiess philipp-spiess requested a review from a team as a code owner October 18, 2024 12:26
@philipp-spiess philipp-spiess force-pushed the 10-18-vite_fix_issues_when_loading_files_via_static_asset_queries branch 2 times, most recently from ff819b4 to b270f30 Compare October 18, 2024 14:27
@philipp-spiess philipp-spiess force-pushed the 10-18-vite_fix_issues_when_loading_files_via_static_asset_queries branch from b270f30 to 1aa561f Compare October 21, 2024 09:08
@philipp-spiess philipp-spiess force-pushed the 10-18-vite_fix_issues_when_loading_files_via_static_asset_queries branch from 1aa561f to 53e2159 Compare October 21, 2024 10:45
@philipp-spiess philipp-spiess requested a review from a team October 21, 2024 16:05
@philipp-spiess philipp-spiess force-pushed the 10-18-vite_fix_issues_when_loading_files_via_static_asset_queries branch from 53e2159 to 5655525 Compare October 22, 2024 11:33
Copy link
Member Author

philipp-spiess commented Oct 22, 2024

Merge activity

  • Oct 22, 12:02 PM EDT: The merge label 'merge-queue' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 22, 12:02 PM EDT: A user added this pull request to the Graphite merge queue.
  • Oct 22, 12:08 PM EDT: A user merged this pull request with the Graphite merge queue.

Fixes: #14558

This PR fixes an issue where our Vite plugin would crash when trying to load stylesheets via certain static asset query parameters:

```ts
import raw from './style.css?raw'
import url from './style.css?url'
```

The proper behavior for our extension is to _not touch these file at all_. The `?raw` identifier should never transform anything and the `?url` one will emit a module which points to the asset URL. However, if that URL is loaded as a stylesheet, another transform hook is called and the file is properly transformed. I verified this in the Vite setup and have added an integration test ensuring these two features work as expected.

I've also greatly reduced the complexity of the Vite playground to make it easier to set up examples like this in the future.
@philipp-spiess philipp-spiess force-pushed the 10-18-vite_fix_issues_when_loading_files_via_static_asset_queries branch from 92457e7 to d59f1b3 Compare October 22, 2024 16:03
@graphite-app graphite-app bot merged commit d59f1b3 into next Oct 22, 2024
2 checks passed
@graphite-app graphite-app bot deleted the 10-18-vite_fix_issues_when_loading_files_via_static_asset_queries branch October 22, 2024 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v4] Something has broken since alpha.15, causing imports in CSS files and vite URL imports to not work
6 participants