fix: coalesce comm_msg state updates within a flush cycle#238
Draft
fix: coalesce comm_msg state updates within a flush cycle#238
Conversation
Pure style change — no functional difference. This separates the indentation change from the upcoming API signature update, keeping that diff focused on the meaningful changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Upgrade the HTML manager dependency to v1.0.14 (ipywidgets 8.x line). Key changes: - Adapt display_view() / create_view() call signatures to new API - Add get_model() override with async waiter to handle out-of-order comm_open messages (parent model referencing not-yet-registered children) - Replace wildcard `.forward-fill-potential > *` CSS selector with `.forward-fill-potential > .lm-Widget` to avoid sizing transient tooltip siblings - Update static libembed-amd.js bundle and font assets - Add Playwright regression test for ipyleaflet GeoJSON hover Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When multiple reactive effects modify the same widget in a single flush cycle (e.g., map.remove(old_layer) then map.add(new_layer)), each trait change previously sent a separate comm_msg to the client. These rapid intermediate states caused race conditions in widget JS views — ipyleaflet's LayersControl would lose track of layers even though the final map rendering was correct. Now, state-update comm_msg messages (method="update") for the same model are merged within each flush cycle, sending only the final value of each changed trait. This is equivalent to wrapping every reactive effect in ipywidgets' hold_sync(), but applied automatically at the transport layer. Non-update messages (method="custom") are still sent individually. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
Summary
Fixes #212 — ipyleaflet LayersControl losing track of layers when reactive effects do remove+add within a single flush cycle.
Root cause: When multiple reactive effects modify the same widget (e.g.,
map.remove(old_layer)thenmap.add(new_layer)), each trait change sends a separatecomm_msgto the client. The intermediate states (e.g., "layers after remove but before add") cause race conditions in ipyleaflet's async JS layer management. The final map rendering was correct, but the LayersControl overlay list would lose entries.Fix: State-update
comm_msgmessages (method="update") for the same model are now merged within each flush cycle, sending only the final value of each changed trait. This is equivalent to wrapping every reactive effect in ipywidgets'hold_sync(), but applied automatically at the transport layer. Non-update messages (method="custom") are still sent individually.Key changes:
_comm.py: Added coalescing logic in_publish_msg— first update for acomm_idregisters anon_flushedcallback; subsequent updates merge their state dict into the pending entrycomm_closeand non-updatecomm_msgmessages are unaffectedTest plan
ipyleaflet_layer_update) that verifies LayersControl stays consistent after remove+add cyclesmake checkpasses (format + types + unit tests)🤖 Generated with Claude Code