Skip to content

fix: revive deephaven.ui widgets after a reconnect#1390

Open
fyrkov wants to merge 3 commits into
deephaven:mainfrom
fyrkov:fix-ui-widget-reconnect
Open

fix: revive deephaven.ui widgets after a reconnect#1390
fyrkov wants to merge 3 commits into
deephaven:mainfrom
fyrkov:fix-ui-widget-reconnect

Conversation

@fyrkov

@fyrkov fyrkov commented Jul 15, 2026

Copy link
Copy Markdown

The deephaven-plugins half of a two-repo fix. Depends on a companion deephaven-core change (not yet submitted) that makes JsWidget fire a reconnect event after reopening its stream; also relies on the transport-reconnect fix deephaven/deephaven-core#8238. Should not merge before the core PR lands (linked here once opened).

On that reconnect event, WidgetHandler now closes stale exported objects, clears the exported-object and callable maps, resets the document, and re-sends the last setState so the server re-renders from scratch instead of patching onto a stale document with dead callables.

Fixes #1389

When the frontend<->backend connection drops and recovers, the patched
JsWidget (deephaven-core) reopens its message stream on the same widget
object and fires a `reconnect` event. WidgetHandler previously keyed every
per-stream reset on the widget *object reference* changing, so nothing reset
on a same-object revive: the new stream's from-empty document patch was
applied on top of the stale document and stale callable closures were reused,
so the button invoked a dead-stream callable the new server stream never
registered (`Callable not found: cbN`).

Listen for the widget `reconnect` event and, on it, close stale exported
objects, clear the exported-object and callable maps, reset the document, and
re-send `setState` so the server re-renders from scratch. Track the latest
state received from the server (not just the panel-open snapshot) so the
widget is restored to its current state after reconnect.

Requires the companion JsWidget/WorkerConnection reconnect support in
deephaven-core, which provides the `reconnect` event this keys off.

Ref: deephaven/deephaven-core#3604

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR updates the deephaven.ui widget client to correctly recover after a same-session disconnect/reconnect by resetting per-stream client state and re-sending the last known widget state so the server re-renders from scratch.

Changes:

  • Track and persist the last widget state received from the server, and re-send it on widget reconnect.
  • On reconnect, clear stale exported objects/callables and reset the rendered document/loading state.
  • Expand test utilities and add/adjust unit tests to cover reconnect behavior and optional state transport.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
plugins/ui/src/js/src/widget/WidgetTestUtils.ts Extend documentPatched test helpers to optionally include the serialized state param.
plugins/ui/src/js/src/widget/WidgetHandler.tsx Add reconnect handling, last-received-state tracking, and cleanup/reset logic to revive widgets after reconnect.
plugins/ui/src/js/src/widget/WidgetHandler.test.tsx Add reconnect unit test and update existing tests for the additional event listener and cleanup behavior.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread plugins/ui/src/js/src/widget/WidgetHandler.tsx
Comment thread plugins/ui/src/js/src/widget/WidgetHandler.tsx
fyrkov and others added 2 commits July 16, 2026 08:51
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Address Copilot review feedback on deephaven#1390: type the METHOD_DOCUMENT_PATCHED
state param as optional and validate the parsed state is a plain object
before using it, so unexpected server values don't flow into setState/onDataChange.
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.

deephaven.ui button becomes unresponsive after a same-session reconnect

2 participants