Skip to content

fix: release previous exports after a hot update - #151

Merged
chenjiahan merged 2 commits into
rstackjs:mainfrom
alohaninja:fix/release-prev-exports
Dec 4, 2026
Merged

chenjiahan merged 2 commits into
rstackjs:mainfrom
alohaninja:fix/release-prev-exports

Conversation

@alohaninja

@alohaninja alohaninja commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor
Before: every hot update keeps the previous module version alive. After: only the first, previous and current versions remain.

Summary

Each hot update of a refresh boundary left the previous version's exports on the new version's hot.data, so every version of the module, and everything it had imported, stayed reachable for the life of the page. Delete hot.data.prevExports once it has been read. The boundary comparison still runs against the previous exports, and a regression test covers the release on an accepted update, an invalidated boundary and a module that stops being a boundary.

In the example app, I edited a large module imported by App.tsx six times. That left 7 live copies of the module before this change and 3 after: the current one in the module cache, plus the first and the previous one, which a heap snapshot shows are still referenced from React's fibers for App.

A boundary module that is removed from the module graph is never run again, so its last exports stay on the runtime's module data. That is one version per removed module, and this change does not affect it.

Related Links

Fixes #150

alohaninja and others added 2 commits December 3, 2026 11:49
Each module version kept the previous version's exports on `hot.data`, so
every version of a refresh boundary stayed reachable for the life of the page.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Assert that `hot.data` is empty after an accepted update, an invalidated
boundary and a module that stops being a boundary, and flush the refresh
timer before the assertions. Reword the comment on the release.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@chenjiahan chenjiahan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@chenjiahan
chenjiahan merged commit e820435 into rstackjs:main Dec 4, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hot updates retain every previous module version through hot.data.prevExports

2 participants