Skip to content

Vite: Skip parsing stylesheets with the ?commonjs-proxy flag #16238

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

Merged
merged 2 commits into from
Feb 4, 2025

Conversation

philipp-spiess
Copy link
Member

Fixes #16233

Vite has a number of special parameters that can be appended to .css files that make it actually load as a JavaScript module. One such parameter that we haven't handled before is the ?commonjs-proxy flag. When importing e.g. plotly.js/lib/core, the dependency tree would eventually load a file called *.css?commonjs-proxy. We previously scanned this for candidates even though it was not, in-fact, a stylesheet.

This PR fixes this by adding the ?commonjs-proxy to the ignore list. I have also updated SPECIAL_QUERY_RE to more closely match the Vite implementation. It does seem like this was the only condition we were missing, though: https://github.com/vitejs/vite/blob/2b2299cbac37548a163f0523c0cb92eb70a9aacf/packages/vite/src/node/plugins/css.ts#L511-L517

Test plan

Add and import plotly.js/lib/core into a Vite app. I also added an integration test to do that.

@philipp-spiess philipp-spiess requested a review from a team as a code owner February 4, 2025 11:05
@philipp-spiess philipp-spiess force-pushed the fix/vite-commonjs-proxy-urls branch from f8a46ab to a06fcbf Compare February 4, 2025 11:05
Comment on lines +10 to 12
const SPECIAL_QUERY_RE = /[?&](?:worker|sharedworker|raw|url)\b/
const COMMON_JS_PROXY_RE = /\?commonjs-proxy/
const INLINE_STYLE_ID_RE = /[?&]index\=\d+\.css$/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@philipp-spiess philipp-spiess merged commit e1a85ac into main Feb 4, 2025
5 checks passed
@philipp-spiess philipp-spiess deleted the fix/vite-commonjs-proxy-urls branch February 4, 2025 11:45
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] [Vite] Invalid declaration
2 participants