Skip to content

HMR failure, must restart Vite #1477

@jods4

Description

@jods4

I am opening this FYI. As I don't have the time to find out what is required for a proper repro, I'm going to close it immediately. @yyx990803 if you want to look at a private repository that reproduces this issue get in touch with me on discord (same handle).

Describe the bug

I start Vite on one of my projects.
Everything works fine.

Now touch any .ts file with an irrelevant edit. Let's say sequence.ts.
This appears on the terminal and looks quite suspicious given the simple edit:
image

Application doesn't work anymore, because of a JS bug.
Full app refresh with F5 doesn't work either!

Only solution seems to be a full restart of Vite: now app works again.

My Analysis

The JS failure in browser is related to a static global field exported by one TS module, that seems to be undefined after the edit, always.

Turns out the containing module is imported twice.
First with a timestamp: state.ts?t=1610318299861.
But then a later file action.ts imports the same module as just state.ts, no timestamp in querystring.

Needless to say for the browser that's 2 different modules, and they don't share variables which leads to all kind of bugs.

Why Vite references 2 different versions of the same file after HMR, I haven't found out.

System Info

  • vite version: 2.0.0-beta.19
  • Operating System: win 10
  • Node version: 15
  • Package manager and version: npm 7

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions