Skip to content

Conversation

hi-ogawa
Copy link
Contributor

@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
Contributor 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
Contributor 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!

@sapphi-red sapphi-red merged commit cee4b25 into vitejs:main Jun 16, 2025
8 checks passed
sapphi-red added a commit that referenced this pull request Jun 16, 2025
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