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

feat: vitest deps.experimentalOptimizer (fixes #111) #115

Merged
merged 1 commit into from Jun 3, 2023

Conversation

ArnaudBarre
Copy link
Member

@ArnaudBarre ArnaudBarre commented Jun 3, 2023

Fixes #111

To be validated by @sheremet-va

@ArnaudBarre ArnaudBarre self-assigned this Jun 3, 2023
@sheremet-va
Copy link
Member

Is „refresh“ the option that injects react refresh into HTML? Can it only be configured by the plugin itself?

@ArnaudBarre
Copy link
Member Author

It's the option that enabled specific AST transformation for fast refresh (React HMR).

Then if this transformation is enabled and the output actually contains something React Refresh specific, we wrap the module with the import of the runtime code (which requires the transfromIndexHTML to run, which is not the case here)

My idea is to disable the HMR specific transform when running inside Vitest, and I wondering if process.env.TEST is a good check

@sheremet-va
Copy link
Member

sheremet-va commented Jun 3, 2023

I wondering if process.env.TEST is a good check

If you only want to target Vitest, you can use process.env.VITEST, but we also set process.env.TEST, so it will work in Vitest.

Then if this transformation is enabled and the output actually contains something React Refresh specific, we wrap the module with the import of the runtime code (which requires the transfromIndexHTML to run, which is not the case here)

Interesting. I've been wondering how to disable this on our side in @vitejs/plugin-react which I assume uses the same mechanism. 🤔 But I assume this PR fixes it?

@ArnaudBarre
Copy link
Member Author

ArnaudBarre commented Jun 3, 2023

The two plugins are independent but have the mechanism. I will update the Babel one just after.

I will go with process.env.TEST because this condition is more related to testing in general than juts Vitest (the problem did not surface before because of the ssr flag is on wihtout the optimizer)

@ArnaudBarre ArnaudBarre marked this pull request as ready for review June 3, 2023 11:59
@ArnaudBarre ArnaudBarre merged commit 10db2d5 into main Jun 3, 2023
1 check passed
@ArnaudBarre ArnaudBarre deleted the vitest-experimentalOptimizer branch June 3, 2023 12:03
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.

Support vitest experimentalOptimizer
2 participants