fix(react): DeckGL component avoid overwriting undefined props#10074
fix(react): DeckGL component avoid overwriting undefined props#10074Pessimistress merged 2 commits intomasterfrom
Conversation
chrisgervang
left a comment
There was a problem hiding this comment.
I agree in principle, for almost all cases this seems right.
The one case that does create a visible difference is when layers goes from a defined value to undefined at runtime:
// previous layers persist instead of clearing while loading
<DeckGL layers={isLoading ? undefined : myLayers} />
Before this change, <DeckGL> normalized undefined to [], which triggered an update and cleared the canvas. After this change, undefined reaches the truthiness guard in LayerManager.needsUpdate, so the update is skipped and the previous layers remain visible.
Initial render / first load should still be unaffected, since Deck.defaultProps initializes layers: [] before React-driven setProps is called.
I'm not sure in practice how often this is relied on, but we should note in our upgrade guide how to restore the old behavior:
<DeckGL layers={isLoading ? [] : myLayers} />
The behavior change seems really about whether undefined means “clear” or “leave current layers alone.”
|
The skip behavior of But obviously, Idiomatic React, on the other hand, always resets an absent prop to its default value. More like a full snapshot It seems more like a difference of semantics than a bug.. core can't tell react and purejs semantics apart. What do you think? |
|
We could give the React wrapper a full-snapshot entry point and track controlled props in core. By the time render runs, the wrapper already sees JSX props merged with defaultProps. What it needs to pass to core are the keys the user actually provided, so core can treat those as controlled, and the full snapshot of props to render, so it can keep the rendering pipeline complete: That matches the current imperative model, where once a prop is set it stays controlled, but lets React use replacement semantics instead of accumulating across renders. Then widgets can avoid writing to props React is controlling: |
|
Alternative proposal in #10075 |
|
In this PR, if you explicitly set As you noted, how LayerManager actually handle If I understand your solution correctly, you are saying we only leave |
|
Rolled back the layers changes for now. We can continue this discussion. |
| input: { | ||
| children: null, | ||
| views: null, | ||
| layers: null |
There was a problem hiding this comment.
I'd prefer we roll back the layers in the test too until we discuss it more
| layers = jsxLayers.length > 0 ? [...jsxLayers, ...layers] : layers; | ||
| layers = jsxLayers.length > 0 ? [jsxLayers, layers] : layers; |
There was a problem hiding this comment.
Should this be reverted as well for now?
Background
DeckGL overwrites the following props if not provided by the user:
layersto[]viewstonullThis makes it difficult to detect if the user intentionally set them to empty, or simply do not want to manage them.
This is technically a breaking change, though I do not expect any visible difference in existing applications.
Change List
viewsif needed