Skip to content

Vite 3 regression: missing reload after fixing import error existing on dev server startup #9534

@fwouts

Description

@fwouts

Describe the bug

When spinning up the Vite dev server with code that contains an invalid import, an error is shown as expected. However, fixing the code does not cause the page to reload as it should. It needs to be reloaded manually.

This only seems to occur when the invalid import was present when the Vite dev server was first spun up. I suspect that's because Vite 3 doesn't set up the module graph in the same way as Vite 2 did, i.e. a file that contains a bad import isn't added to the module graph, so when that file is updated, Vite 3's dev server doesn't know about it and therefore no reload occurs.

I found out about it when upgrading Preview.js to Vite 3, as I have tests for that specific case. Yes, I'm considering adding it to the ecosystem test suite, but it's too flaky at the moment :)

Reproduction

https://github.com/fwouts/vite-not-refreshing (reproduction steps in README)

System Info

System:
    OS: macOS 12.5
    CPU: (8) arm64 Apple M1
    Memory: 119.88 MB / 8.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
    Yarn: 1.22.19 - ~/.yarn/bin/yarn
    npm: 8.9.0 - ~/.config/yarn/global/node_modules/.bin/npm
  Browsers:
    Chrome: 103.0.5060.134
    Firefox: 103.0
    Safari: 15.6
  npmPackages:
    vite: ^3.0.0 => 3.0.4

Used Package Manager

pnpm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: deps optimizerEsbuild Dependencies Optimizationfeat: hmrp3-minor-bugAn edge case that only affects very specific usage (priority)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions