Skip to content

/@vite/client stub's createHotContext returns a hot context without the documented "data" property #11528

Closed

Description

@Alxs39

Describe the bug

I am doing: running unit tests with environment: 'happy-dom'. Vite's importAnalysis
plugin rewrites any module whose source references import.meta.hot by prepending

import { createHotContext as __vite__createHotContext } from "/@vite/client";
import.meta.hot = __vite__createHotContext("…")`,

and Vitest serves the /@vite/client id with a hard-coded stub (defaultClientStub in
packages/vitest/src/runtime/moduleRunner/moduleEvaluator.ts).

What I expect is: the stub's hot context to honor the documented ViteHotContext contract
(https://vite.dev/guide/api-hmr readonly data, "Vite creates one import.meta.hot.data
object for each module path"). The stub already replicates the rest of the surface
(accept, prune, dispose, decline, invalidate, on, send).

What actually happens is: import.meta.hot is the stub object (truthy, so if (import.meta.hot)
guards pass) but import.meta.hot.data is undefined, so any legitimate hot.data[key] reader
crashes. Real-world example: @lexical/extension's HMRExtension (wired with the documented
configExtension(HMRExtension, { hot: import.meta.hot ?? null }) pattern) throws
TypeError: Cannot read properties of undefined (reading 'lexicalHMR:…') in every unit test
that mounts an editor.

Reproduction

https://github.com/Alxs39/vitest-hot-data-repro : npm install, then npm test.

Output (vitest 5.0.3, latest):

FAIL  hmr-data.test.js > import.meta.hot exposes the documented data object
AssertionError: expected undefined to deeply equal {}

- Expected:
{}

+ Received:
undefined

The first assertion (expect(import.meta.hot).toBeDefined()) passes the stub exists, only the documented data property is missing.

System Info

System:
    OS: macOS 26.5.2
    CPU: (10) arm64 Apple M4
    Memory: 1.09 GB / 32.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 26.8.1 - /Users/alexis/.local/bin/node
    npm: 11.19.0 - /Users/alexis/.local/bin/npm
    pnpm: 11.10.0 - /Users/alexis/.local/bin/pnpm
  Browsers:
    Safari: 26.5.2
  npmPackages:
    vitest: 5.0.3 => 5.0.3

Used Package Manager

npm

Validations

Activity

  1. added theissue type on Oct 8, 2026
  2. sheremet-va commented on Oct 8, 2026

    @sheremet-va
    Member

    createHotContext should probably return undefined, to be honest

  3. Alxs39 commented on Oct 8, 2026

    @Alxs39
    Author

    createHotContext should probably return undefined, to be honest

    Agreed, undefined seems like the right end state it matches what builds already do. Just noting the stub breaks the documented contract today (truthy context, missing data), so seeding it with data: {} would still be worth shipping either way

  4. added
    p3-minor-bugAn edge case that only affects very specific usage (priority)
    p2-edge-caseBug, but has workaround or limited in scope (priority)
    and removed
    p3-minor-bugAn edge case that only affects very specific usage (priority)
    on Oct 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    p2-edge-caseBug, but has workaround or limited in scope (priority)

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions