Describe the bug
After upgrading Vite to 6.3.0+, almost all of my tests running in Vitest started failing. I eventually figured out that all of the failing tests relied on a React Testing Library custom render function. RTL recommends implementing custom render functions in the following way, by overriding the render export with a local implementation:
// re-export everything
export * from '@testing-library/react'
// override render method
export {customRender as render}
In all versions of Vite prior to 6.3.0 this worked fine, but in 6.3.0 and newer it no longer works. Instead, the original render function from @testing-library/react is exported rather than the custom render function. It seems like Vite is remembering the first render it sees and ignoring the subsequent export which had previously acted as an override.
I didn't see anything in the changelog about this override behavior changing. The only recent change I see in 6.3.0 related to export handling is this: #18983
I haven't been able to come up with a reproduction case that works with Vite alone. It seems to occur only when the exports are being imported by a test running with Vitest. So I'm not sure if this is actually a Vite issue, a Vitest issue, or only an issue when the two are used together. I thought I'd start with a Vite issue, but I can move this over to Vitest if it would be more appropriate.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-mrcqdpn5?file=src%2Fbasic.ts
Steps to reproduce
I created 2 stackblitz examples. The only difference between the two is that one uses Vite 6.2.6 and the other uses Vite 6.3.0. The tests pass in 6.2.6 but fail in 6.3.0 because 6.3.0 does not override the export properly.
The basic.ts imports a broken implementation of the squared function and then overrides it with a working implementation:
export const correctSquared = (n: number) => n * n;
export * from './wrong.ts';
export { correctSquared as squared };
With Vite 6.2.0 the working implementation overrides the broken one, and the tests pass. With Vite 6.3.0 the override is ignored, and the tests fail.
System Info
System:
OS: Linux 6.12 Gentoo Linux
CPU: (16) x64 AMD Ryzen 7 PRO 8840HS w/ Radeon 780M Graphics
Memory: 14.03 GB / 89.99 GB
Container: Yes
Shell: 5.2.37 - /bin/bash
Binaries:
Node: 23.6.0 - ~/.nvm/versions/node/v23.6.0/bin/node
Yarn: 1.22.22 - ~/.nvm/versions/node/v23.6.0/bin/yarn
npm: 10.9.2 - ~/.nvm/versions/node/v23.6.0/bin/npm
pnpm: 9.15.9 - ~/.nvm/versions/node/v23.6.0/bin/pnpm
Browsers:
Brave Browser: 135.1.77.100
Used Package Manager
pnpm
Logs
No response
Validations
Describe the bug
After upgrading Vite to
6.3.0+, almost all of my tests running in Vitest started failing. I eventually figured out that all of the failing tests relied on a React Testing Library custom render function. RTL recommends implementing custom render functions in the following way, by overriding therenderexport with a local implementation:In all versions of Vite prior to
6.3.0this worked fine, but in6.3.0and newer it no longer works. Instead, the originalrenderfunction from@testing-library/reactis exported rather than the customrenderfunction. It seems like Vite is remembering the firstrenderit sees and ignoring the subsequent export which had previously acted as an override.I didn't see anything in the changelog about this override behavior changing. The only recent change I see in
6.3.0related to export handling is this: #18983I haven't been able to come up with a reproduction case that works with Vite alone. It seems to occur only when the exports are being imported by a test running with Vitest. So I'm not sure if this is actually a Vite issue, a Vitest issue, or only an issue when the two are used together. I thought I'd start with a Vite issue, but I can move this over to Vitest if it would be more appropriate.
Reproduction
https://stackblitz.com/edit/vitest-dev-vitest-mrcqdpn5?file=src%2Fbasic.ts
Steps to reproduce
I created 2 stackblitz examples. The only difference between the two is that one uses Vite 6.2.6 and the other uses Vite 6.3.0. The tests pass in 6.2.6 but fail in 6.3.0 because 6.3.0 does not override the export properly.
The
basic.tsimports a broken implementation of thesquaredfunction and then overrides it with a working implementation:With Vite 6.2.0 the working implementation overrides the broken one, and the tests pass. With Vite 6.3.0 the override is ignored, and the tests fail.
System Info
System: OS: Linux 6.12 Gentoo Linux CPU: (16) x64 AMD Ryzen 7 PRO 8840HS w/ Radeon 780M Graphics Memory: 14.03 GB / 89.99 GB Container: Yes Shell: 5.2.37 - /bin/bash Binaries: Node: 23.6.0 - ~/.nvm/versions/node/v23.6.0/bin/node Yarn: 1.22.22 - ~/.nvm/versions/node/v23.6.0/bin/yarn npm: 10.9.2 - ~/.nvm/versions/node/v23.6.0/bin/npm pnpm: 9.15.9 - ~/.nvm/versions/node/v23.6.0/bin/pnpm Browsers: Brave Browser: 135.1.77.100Used Package Manager
pnpm
Logs
No response
Validations