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

Multiple exports in template file breaks HMR #34

Closed
7 tasks done
mkilpatrick opened this issue Mar 25, 2022 · 2 comments
Closed
7 tasks done

Multiple exports in template file breaks HMR #34

mkilpatrick opened this issue Mar 25, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@mkilpatrick
Copy link

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

@patak-dev
Copy link
Member

See vitejs/vite#7324 for initial work to make this works. And the discussion started by @rixo here vitejs/vite#7309

@ArnaudBarre
Copy link
Member

Hi!

This is a known limitation of React HMR: https://github.com/vitejs/vite-plugin-react-swc#consistent-components-exports

#79 will add a message to help users understand why the module was invalidated.

@github-actions github-actions bot locked and limited conversation to collaborators Feb 6, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants