Skip to content

fix(hot-runtime): keep vitest-native's worker-lifetime globals through the per-file reset - #800

Draft
danfry1 wants to merge 2 commits into
mainfrom
fix/hot-resident-globals
Draft

danfry1 wants to merge 2 commits into
mainfrom
fix/hot-resident-globals

Conversation

@danfry1

@danfry1 danfry1 commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Summary

Under the hot runtime, the require bridge's counters and the resolution memo's stats now last for the worker's life instead of reading empty from its second file on.

Fixes #792

Why

bridge-client.mjs, bridge.mjs and hooks.mjs create these objects lazily, often during a worker's first file. The per-file reset deleted them as that file's globals, while the resident modules kept counting into the deleted objects.

Changes

  • src/native/resident-globals.mjs declares vitest-native's worker-lifetime globals in one list, RESIDENT_GLOBALS. The three modules create theirs through it, and the reset keeps exactly those keys. A resident-state audit can read the same list.
  • A unit test fails on any module that creates its own lazy Symbol.for("vitest-native.…") global outside the list. The asset-id map is the one exception: it is keyed by React Native's per-file asset registry, so it is per-file state.
  • New gate test:native:hot:resident-globals (two files on one hot worker, in test:native:hot:isolation).

Notes

…h the per-file reset

The require bridge and the resolution memo create their counter objects lazily, often
during a worker's first file, and the reset deleted them as that file's globals while the
resident modules kept counting into the deleted objects. They are now created through one
declared list, RESIDENT_GLOBALS, which the reset keeps.
@danfry1 danfry1 added this to the 0.16.0 milestone Nov 13, 2026
@danfry1 danfry1 added bug Something isn't working area:hot-runtime hotRuntime: worker reuse, per-file reset, memory plan priority:low Nice to have labels Nov 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:hot-runtime hotRuntime: worker reuse, per-file reset, memory plan bug Something isn't working priority:low Nice to have

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hot runtime: the per-file reset deletes the require bridge's counters after a worker's first file

1 participant