Skip to content

Multiple exports in template file breaks HMR #34

Closed
@mkilpatrick

Description

@mkilpatrick

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions