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

fix(plugin-react): account for querystring in transform hook #5333

Merged
merged 3 commits into from Oct 19, 2021

Conversation

frandiox
Copy link
Contributor

Description

@vite/plugin-react currently checks file extension in Rollup's transform hook. However, the id parameter can contain querystrings when importing a component like this:

import MyComponent from './MyComponent.jsx?query-here'

This makes the plugin fail when testing id.endsWith('x') and similar checks.

Additional context

Querystrings can be injected by other Vite plugins in order to apply conditional behavior.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

@frandiox
Copy link
Contributor Author

The tests passed but crashed at the end with

Error: Jest: Got error running globalTeardown - D:\a\vite\vite\scripts\jestGlobalTeardown.js, reason: ENOTEMPTY: directory not empty, rmdir 'D:\a\vite\vite\packages\temp\wasm\dist\assets'
 ELIFECYCLE  Command failed with exit code 1.

Any idea why? 👀

@patak-dev
Copy link
Member

@frandiox we have a glitch in the test suite, that we haven't been able to track down yet. Re-running the tests fixed the issue

@frandiox
Copy link
Contributor Author

@antfu It now uses the extension from the querystring first, if provided. Is that OK?

Also, tests failed again due to the same issue. Can anybody with permissions re-run it?

@aleclarson aleclarson changed the title fix(plugin-react): ignore querystring when checking file extension fix(plugin-react): account for querystring in transform hook Oct 19, 2021
@aleclarson aleclarson merged commit 13c3813 into vitejs:main Oct 19, 2021
@ArnaudBarre
Copy link
Member

@frandiox Can you share some examples for

Querystrings can be injected by other Vite plugins in order to apply conditional behavior.

I'm working on a react-swc plugin for Vite and I want to know a bit more to know if I should mimic this behaviour

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.

None yet

5 participants