Skip to content

Let a renderer stop the browser syncing named traits to Python - #487

Open
cpsievert wants to merge 3 commits into
plotly-slim-selectionsfrom
client-mute-traits
Open

cpsievert wants to merge 3 commits into
plotly-slim-selectionsfrom
client-mute-traits

Conversation

@cpsievert

@cpsievert cpsievert commented Nov 13, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #479. Stacked on #484 (main ← #483 ← #484 ← this ← #488); the plotly PR on top is where behavior changes.

Some widgets sync traits from the browser to Python that are expensive and that nothing on the server reads. plotly.py's per-point selection report is the motivating case (#479), but nothing about the mechanism is plotly-specific. This PR lets a renderer say "don't sync these traits from the browser", and the browser then drops them from outgoing updates, including their binary buffers. No renderer uses it yet, so this changes no behavior on its own.

It also adds SHINYWIDGETS_NATIVE_EVENTS=1, a single switch that turns muting off for every output. That's the escape hatch for a deployment you can't edit app code for, and it will apply to any renderer that mutes something later.

Where to look

  • js/src/comm.ts: ShinyComm.send() filters an update message's state (and the matching buffer_paths/buffers) against the muted set. If nothing is left it isn't sent, and the comm reports idle itself, since nothing will ack a message that never went out and ipywidgets holds later changes until the in-flight one is idle.
  • shinywidgets/_render_widget_base.py: a renderer overrides _muted_traits(widget); after each render the base class sends the browser a {"shinywidgets": "mute", "traits": [...]} request. Each render restates the full set.
  • js/src/output.ts: routes that request to the model's comm, next to the existing bind requests.

Custom messages are never filtered, only updates.

Interaction with #481

#481 edits the same ShinyComm.send(). main is merged into the stack, with the one real collision resolved: both sides declared const onIdle, so I kept a single declaration at the top of send(). The mute filter runs first and the size guard second, so a message that only sets muted traits is never measured. Both sets of vitest tests pass together.

Testing

  • Vitest: update filtering (all-muted, mixed, binary buffers, custom messages untouched, un-muting) and request recognition.
  • Unit: a stub renderer gets the mute request; renderers mute nothing by default; the env var's on values (1, true) and off values.
  • shinywidgets/static/output.js is the rebuilt bundle.

Infrastructure for gating widget traits that are expensive to sync and that
nothing on the server reads. A renderer lists them in _muted_traits(); the
browser comm then drops them from outgoing updates (with their binary
buffers). No renderer mutes anything yet.

SHINYWIDGETS_NATIVE_EVENTS=1 turns muting off for every output.
…ent-mute-traits

# Conflicts:
#	js/src/comm.test.ts
#	js/src/output.ts
#	shinywidgets/static/output.js

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant