[Bug] View and widget ids: explicit ids are indistinguishable from defaults, and widget matching ignores the class
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 45/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, typescript
- Domain
- frontend
Research direction
Read dev-docs/RFCs/v8.0/ui-module-rfc.md first for the intended widget-identity rules, then View in the core views module and Widget plus WidgetManager._setWidgets in the core lib, where ids are resolved and widgets are matched. Reproduce with the snippet in the report (Object.hasOwn on new MapView().props and new MapView({id: 'MapView'}), and the two widget defaults colliding). Done means a passed id is distinguishable from a default, a widget with a different constructor is replaced rather than updated, each widget class has a unique default id, and CustomProjectionView.makeViewport still passes id explicitly.
Written by the indexing model from the issue text.
Description
Description
Three related problems with view and widget ids.
1. An explicit id can't be told apart from the default
For layers, createProps puts the passed props on an object whose prototype holds the defaults, including id (getComponentName(cls)). Object.hasOwn(layer.props, 'id') therefore says whether the app passed an id. This came in for speed (#1336, #4007).
Views and widgets lose that information:
Viewresolvesthis.id = id || this.constructor.displayName || 'view'(#1379), then writes the resolved id back withthis.props = {...props, id: this.id}(#3275, to fix #3259), then seals the instance.new MapView()andnew MapView({id: 'MapView'})look identical.Widgetmerges{...defaultProps, ...props}and then readsthis.id = this.props.id(#9576). A passed'zoom'looks the same as the default'zoom'.
Code that wraps deck.gl needs to know the difference. The React Fiber renderer in deck.gl-community gives views and widgets an id from their React key, but it must keep an id the app passed. In visgl/deck.gl-community#1077, a keyed new MapView({id: 'MapView'}) was renamed to MapView/<key>, while initialViewState.MapView and widgets with viewId: 'MapView' still used the old id.
Plan: put the default id on a prototype, the way layers do. props.id keeps reading the resolved id, and Object.hasOwn(props, 'id') is true only when it was passed. makeViewport and CustomProjectionView.makeViewport spread this.props, so they set id: this.id explicitly, or #3259 would come back. View#equals compares resolved ids, so new MapView() still equals new MapView({id: 'MapView'}).
2. WidgetManager matches widgets by id only
The widget RFC (#7512, dev-docs/RFCs/v8.0/ui-module-rfc.md) says two controls "are be the "same" if they share the same constructor and the same id". WidgetManager._setWidgets only compares id, so a widget of a different class with the same id is updated with oldWidget.setProps(widget.props) instead of being replaced. The old instance keeps rendering with props meant for another class.
Plan (decided: proposal D; merged in #11115): the id stays the identity, and a type decides whether a matched widget is reused or replaced. The type is the class default id (defaultProps.id), not the constructor, so a hot module reload or a second copy of a package keeps the widget. A different type is treated like a changed viewId or placement: the old widget is removed before the new one is added. Duplicate ids within one list are handled separately in #11064 (#11066), also merged. #11287 is the fast follow that gives WidgetManager and ViewManager one shared matcher.
3. Default ids collide across widget classes
InfoWidgetandPopupWidgetboth default to'info'IconWidgetandToggleWidgetboth default to'icon'ScrollbarWidgethas no default, so it uses the base'widget'
Using two of these together without passing ids makes them collide. Combined with problem 2, one widget receives the other's props.
Plan: give each class its own default: 'popup', 'toggle' and 'scrollbar'. The docs don't list default ids, and nothing in deck.gl reads them besides widget matching.
TimelineWidget and TooltipWidget set id as a class field, which overwrites a passed id. That is fixed in #11099.
4. Views and widgets disagree on which ids count as not passed
View and Viewport treat any falsy id (undefined, null, '') as the class default. Widget keeps '' and null, so two such widgets collide in WidgetManager.
Plan (decided: the view rule; merged in #11135 for 10.0): a widget id of undefined, null or '' uses the class default, in the constructor and in setProps. Views can't take the widget rule without splitting a view's id from its viewport's (#3259). It changes behavior, so it ships in 10.0 with an upgrade-guide note, not in a 9.4 patch.
Flavors
- Script tag
- React
- Python/Jupyter notebook
- MapboxOverlay
- GoogleMapsOverlay
- CARTO
- ArcGIS
Steps to Reproduce
import {MapView, ZoomWidget} from '@deck.gl/core';
import {InfoWidget, PopupWidget} from '@deck.gl/widgets';
Object.hasOwn(new MapView().props, 'id'); // true, same as new MapView({id: 'MapView'})
Object.hasOwn(new ZoomWidget().props, 'id'); // true, same as new ZoomWidget({id: 'zoom'})
new InfoWidget().id === new PopupWidget().id; // true: both 'info'
Environment
- Framework version: [email protected] (master); also 9.4
Logs
No response
Generated by Claude Code
- Dominant language
- TypeScript
- Stars
- 14.8k
- Forks
- 2.3k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 230
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from visgl/deck.gl
-
[Bug] Tile3DLayer selects no tiles until the camera moves when tileset.json loads right after a layer updatePossibly taken @lee3Q claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 1 day
-
[Bug] SplitterWidget calls onDragStart on drag end; Deck._getViews writes into the app's views arrayPossibly taken @04jennet-coder claimed this 20 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
Maintainers usually reply within 1 day
-
[Bug] WMSLayer positions EPSG:4326 images as CARTESIANPossibly taken @athomct claimed this 3 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
[Bug] MapLibreOverlay under React StrictMode: 'WebGL context already attached to device' because the attach path omits _reuseDevicesPossibly taken @jsve claimed this 84 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
visgl/deck.gl#10681 · 1 comment · 1 reaction ·
Maintainers usually reply within 1 day
Similar issues
-
accessibility area:ci ci-test level:low priority:high type:test
Difficulty 2/5 1-3 hours Newbie friendliness 71/100
skytuhua-org/Gen-V1#3132 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
drmrd/vernacular#1238 ·
Maintainers usually reply within 1 day
-
question
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
enhancement migration-prioritized
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
Hudson-Pufferfish/local-party-console#136 ·
Maintainers usually reply within 1 day
-
priority:medium
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day