Skip to content

Inline modules cause full page refresh instead of HMR for SSR #9054

@mkilpatrick

Description

@mkilpatrick

Describe the bug

When inlining code in a <script type="module">//some code</script> HMR does not seem to work when in SSR mode. Inside the script is a call to import.meta.glob to load other files (not sure if that is relevant). What I believe is happening is that the virtual module created always causes a full reload based on this PR. When the module actually references a file and is not virtual then HMR works appropriately. Can this be fixed?

Potential other relevant PR I found - #5279

Secondary question, which might be off topic: is it possible for an index.html (provided by an SSR server) to load a file from an npm package, rather than assuming it's local to the repo root? My use case is providing a framework that people use (which uses Vite in SSR mode under the hood), and the index and entry is provided for them. They only need to add template files in their repo. So my entry is an inline module in the index.html due to the above issue. If I could not inline it then that would satisfy my use case as long as the script module can reference a file provided by my package (in node_modules).

Reproduction

https://github.com/mkilpatrick/vite-ssr-react-base/tree/inline-module

System Info

System:
    OS: macOS 12.4
    CPU: (10) arm64 Apple M1 Max
    Memory: 279.39 MB / 64.00 GB
    Shell: 5.1.16 - /usr/local/bin/bash
  Binaries:
    Node: 17.9.0 - ~/.nvm/versions/node/v17.9.0/bin/node
    npm: 8.5.5 - ~/.nvm/versions/node/v17.9.0/bin/npm
  Browsers:
    Chrome: 103.0.5060.114
    Safari: 15.5
  npmPackages:
    @vitejs/plugin-react: 2.0.0-beta.1 => 2.0.0-beta.1 

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: ssrp3-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