fix: a recreated module widget must invalidate the stale module - #82
Merged
Merged
Conversation
A fresh module widget can carry a name that is already in the page global registry: solara closes the per-kernel module widgets on a hot reload (a trait update on a closed widget never reaches the browser) and creates new ones. Only change:code/url/dependencies invalidated the registry, so consumers rendered after the reload could resolve the previous module - permanently, since nothing re-renders them when the new module is provided later. Whether that happened depended on which of the two won the race, so hot reload silently kept serving the old module on loaded machines. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
maartenbreddels
force-pushed
the
fix/invalidate-module-on-recreate
branch
from
July 28, 2026 15:58
7e52c51 to
c379e66
Compare
This was referenced Jul 28, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
Hot reload of an ES module can permanently stop reaching the browser: the page keeps rendering the previous version of the module, forever.
Module.initialize()callsaddModule()but neverinvalidateModule()— only thechange:code/change:url/change:dependencieshandler does. A freshly created widget can carry a name that is already in the page-global registry: solara closes the per-kernel module widgets on a hot reload (a trait update on a closed widget never reaches the browser) and creates new ones. The registry then still holds the previous, already-resolved module, so a consumer rendered after the reload resolves that one instantly — and nothing re-renders it when the new module is provided a moment later.It is a race between the new widget's async load and the consumer's
requestModule: module first → correct new version; consumer first → stale version, permanently.Evidence
Reproduced with solara's
esm_test.py::test_ipyreact_module_hot_reloadin a Linux container limited to 1 CPU (the race is essentially never lost on an unloaded machine, which is why this only shows on busy CI runners):The behaviour is bimodal — the new module arrives within seconds, or never — confirming it is a lost update rather than slowness.
The test
test_module_recreated_widget_hot_reloadcovers the recreate flow (render, close the module widget ascontext.restart()does, define again, render again). Note it needs CPU pressure to fail deterministically without the fix, so it documents the path rather than guarding it on a fast machine; the container comparison above is the real proof.🤖 Generated with Claude Code