Vite: Skip parsing stylesheets with the ?commonjs-proxy flag#16238
Merged
philipp-spiess merged 2 commits intomainfrom Feb 4, 2025
Merged
Vite: Skip parsing stylesheets with the ?commonjs-proxy flag#16238philipp-spiess merged 2 commits intomainfrom
?commonjs-proxy flag#16238philipp-spiess merged 2 commits intomainfrom
Conversation
f8a46ab to
a06fcbf
Compare
RobinMalfait
approved these changes
Feb 4, 2025
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$/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.

Fixes #16233
Vite has a number of special parameters that can be appended to
.cssfiles that make it actually load as a JavaScript module. One such parameter that we haven't handled before is the?commonjs-proxyflag. 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-proxyto the ignore list. I have also updatedSPECIAL_QUERY_REto 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-L517Test plan
Add and import
plotly.js/lib/coreinto a Vite app. I also added an integration test to do that.