[Bug] View and widget ids: explicit ids are indistinguishable from defaults, and widget matching ignores the class

Open
#11,113 3 comments 0 reactions 0 assignees View on GitHub

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
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:

  • View resolves this.id = id || this.constructor.displayName || 'view' (#1379), then writes the resolved id back with this.props = {...props, id: this.id} (#3275, to fix #3259), then seals the instance. new MapView() and new MapView({id: 'MapView'}) look identical.
  • Widget merges {...defaultProps, ...props} and then reads this.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
  • InfoWidget and PopupWidget both default to 'info'
  • IconWidget and ToggleWidget both default to 'icon'
  • ScrollbarWidget has 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
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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from visgl/deck.gl

All issues in visgl/deck.gl

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.