Closed
Description
Describe the bug
If there is only a single export in a template file then vite will hmr update that file correctly after making an update.
// src/templates/test.tsx
const Test = (props: any) => {
return (
<>
<div>
Test
</div>
</>
);
};
export default Test;
[vite] hmr update /src/templates/test.tsx
But when there's also another export in the file it instead hmr updates the entry file, causing React state to reset
// src/templates/test.tsx
export const foo = {}
[vite] hmr update /react-sites-scripts/entry.tsx
Reproduction
https://stackblitz.com/edit/vitejs-vite-krniy8?file=src/App.jsx
System Info
System:
OS: macOS 12.2.1
CPU: (8) x64 Intel(R) Core(TM) i7-7700HQ CPU @ 2.80GHz
Memory: 45.29 MB / 16.00 GB
Shell: 5.1.16 - /usr/local/bin/bash
Binaries:
Node: 17.7.1 - ~/.nvm/versions/node/v17.7.1/bin/node
Yarn: 1.22.17 - /usr/local/bin/yarn
npm: 8.5.2 - ~/.nvm/versions/node/v17.7.1/bin/npm
Watchman: 2021.10.18.00 - /usr/local/bin/watchman
Browsers:
Chrome: 99.0.4844.83
Firefox: 52.0.2
Safari: 15.3
Used Package Manager
npm
Logs
No response
Validations
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.