Skip to content

fix(core): replace a matched widget when its type changes in WidgetManager - #11115

Merged
chrisgervang merged 3 commits into
masterfrom
chr/widget-manager-match-constructor
Nov 23, 2026
Merged

chrisgervang merged 3 commits into
masterfrom
chr/widget-manager-match-constructor

Conversation

@chrisgervang

@chrisgervang chrisgervang commented Nov 14, 2026 •

Copy link
Copy Markdown
Collaborator

For #11113

Background

The widget RFC (#7512) treats two widgets as the same only if they share a constructor and an id. WidgetManager._setWidgets compares ids only, so a widget of another class with the same id is updated with oldWidget.setProps(widget.props) and keeps rendering as the old class. Independent of #11064, which handles duplicate ids within one list; the two merge without conflicts.

The id stays the widget's identity. The type only decides whether the old instance is reused or replaced. The type is the class default id (defaultProps.id, unique per class since #11116), not the constructor. A hot module reload, or a second copy of a package, creates a new class with the same default id, and comparing constructors would remount the widget and lose its state on every reload.

A custom widget that doesn't set its own default id has the same type as its parent class, so it is still updated in place, as today.

Change List

  • WidgetManager: replace a matched widget when its type (class default id) differs
  • Unit tests: a widget of another type with the same id is replaced; a reloaded copy of the same class keeps the old instance

Verified with the headless tests for widget-manager.spec.ts; the reload test fails with a constructor comparison. Prettier passes on the changed files.


Note

Low Risk
Low risk scoped bug fix in widget reconciliation logic with accompanying unit tests.

Overview
Updates WidgetManager to replace an existing widget instance when a new widget with the same id has a different widget type.

Previously, widgets were matched solely by id, which could pass props from one widget class to an instance of another. Widget types are determined by comparing defaultProps.id, ensuring different widget classes are replaced while still reusing instances across hot module reloads.

Reviewed by Cursor Bugbot for commit 9295542. Bugbot is set up for automated code reviews on this repo. Configure here.

The widget RFC treats two widgets as the same only if they share a
constructor and an id. WidgetManager compared ids only, so a widget of
another class with the same id was updated with the new widget's props
instead of being replaced.

For #11113

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGNhMnSJ94uYgx7ihcVwPn
@greptile-apps

greptile-apps Bot commented Nov 14, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issue remains.

Summary

WidgetManager now replaces a same-id widget when its class default id changes.

  • Widgets with a new type replace the matched instance.

Reviews (3) · Last reviewed commit: "Merge remote-tracking branch 'origin/mas..." · Reviewed by Greptile

@coveralls

coveralls commented Nov 14, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 83.583% (+0.001%) from 83.582% — chr/widget-manager-match-constructor into master

Match widgets by id, and use the class default id (defaultProps.id) rather
than the constructor to decide whether the old instance can be reused. The
default id is unique per class and survives hot module reloads, so a reloaded
widget class keeps its mounted instance.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGNhMnSJ94uYgx7ihcVwPn
@chrisgervang chrisgervang changed the title fix(core): match widgets by class and id in WidgetManager fix(core): replace a matched widget when its type changes in WidgetManager Nov 16, 2026
Comment thread modules/core/src/lib/widget-manager.ts Resolved

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 00c5d21. Configure here.

Comment thread modules/core/src/lib/widget-manager.ts Resolved
@ibgreen ibgreen added the bug label Nov 21, 2026
@chrisgervang
chrisgervang added this pull request to the merge queue Nov 23, 2026
Merged via the queue into master with commit b864248 Nov 23, 2026
9 checks passed
@chrisgervang
chrisgervang deleted the chr/widget-manager-match-constructor branch November 23, 2026 02:26
chrisgervang added a commit that referenced this pull request Nov 23, 2026
…nager (#11115)

* fix(core): match widgets by class and id in WidgetManager

The widget RFC treats two widgets as the same only if they share a
constructor and an id. WidgetManager compared ids only, so a widget of
another class with the same id was updated with the new widget's props
instead of being replaced.

For #11113

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGNhMnSJ94uYgx7ihcVwPn

* fix(core): compare the widget type by class default id

Match widgets by id, and use the class default id (defaultProps.id) rather
than the constructor to decide whether the old instance can be reused. The
default id is unique per class and survives hot module reloads, so a reloaded
widget class keeps its mounted instance.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01LGNhMnSJ94uYgx7ihcVwPn

---------

Co-authored-by: Claude <[email protected]>
(cherry picked from commit b864248)
@chrisgervang

Copy link
Copy Markdown
Collaborator Author

Released in deck.gl 9.4.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants