Skip to content

fix(oxc): disable refresh transform when server.hmr: false #502

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

hi-ogawa
Copy link
Collaborator

@hi-ogawa hi-ogawa commented Jun 11, 2025

Description

I think another approach is to configure oxc instead of esbuild on Vitest side when rolldown-vite is detected. Probably it makes more sense since we should migrate from esbuild to oxc eventually anyways.

(Btw tests are failing because process.env.VITEST is true during test-serve e2e 🙃)

So, technically this is not Vitest specific issue. The same error would happen when server.hmr: false.

@ArnaudBarre
Copy link
Member

This issue with this way of configuring refresh is that we are enabling it for ssr too, but other plugins don't do it

@hi-ogawa
Copy link
Collaborator Author

Interesting point. It looks like rolldown-vite actually configures refresh: false in a delayed way for ssr https://github.com/vitejs/rolldown-vite/blob/52e24901d155515b3f30cfb877391e9851bb5497/packages/vite/src/node/plugins/oxc.ts#L332-L340

@ArnaudBarre
Copy link
Member

Ok so we need to find a way to make the tests works now

@sapphi-red
Copy link
Member

How about adding a plugin like below?

  const viteConfigPost: Plugin = {
    name: 'vite:react-oxc:config',
    enforce: 'post',
    config(userConfig) {
      if (userConfig.oxc?.jsx && !userConfig.server.hmr) {
        userConfig.oxc.jsx.refresh = false
      }
    }
}

@hi-ogawa hi-ogawa changed the title fix(oxc): disable oxc config on vitest fix(oxc): disable refresh transform when server.hmr: false Jun 12, 2025
@hi-ogawa hi-ogawa marked this pull request as ready for review June 12, 2025 01:45
Co-authored-by: 翠 <[email protected]>
expect(await page.textContent('button')).toMatch('count is 0')
expect(await page.click('button'))
expect(await page.textContent('button')).toMatch('count is 1')
})
Copy link
Member

Choose a reason for hiding this comment

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

Can you add that for serve, edit to App.tsx does full page reload?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I was wondering about that too but it turns out server.hmr: false even disables full reload and test actually failed.

Copy link
Member

@ArnaudBarre ArnaudBarre Jun 12, 2025

Choose a reason for hiding this comment

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

Ok let's keep it like this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Getting $RefreshReg$ is not defined error when running tests with vitest and plugin-react-oxc
3 participants