Skip to content

Commit 287b467

Browse files
chrisgervangclaude
andcommitted
fix(mapbox): Update widget reference when reusing DeckWidgetControl
When _processWidgets reuses a DeckWidgetControl for a new widget instance with the same id and placement, the control's internal _widget reference must be updated. Otherwise the control references the old widget, causing incorrect behavior in onRemove() and potential memory leaks. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent c4f097d commit 287b467

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

modules/mapbox/src/deck-widget-control.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,12 @@ export class DeckWidgetControl implements IControl {
6767
get widget(): Widget {
6868
return this._widget;
6969
}
70+
71+
/**
72+
* Updates the wrapped widget reference.
73+
* Used when reusing this control for a new widget instance with the same id.
74+
*/
75+
setWidget(widget: Widget): void {
76+
this._widget = widget;
77+
}
7078
}

modules/mapbox/src/mapbox-overlay.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,8 @@ export default class MapboxOverlay implements IControl {
219219
// Same id and placement - reuse existing control to preserve container
220220
// Set _container on the new widget instance so WidgetManager uses it
221221
widget.props._container = existingControl.widget.props._container;
222+
// Update the control's widget reference to the new instance
223+
existingControl.setWidget(widget);
222224
newControls.push(existingControl);
223225
existingControlsById.delete(widget.id);
224226
} else {

0 commit comments

Comments
 (0)