fix(react-color-picker): use nullish fallback in adjustChannel so zero channel values resolve - #36664
Open
Ray Knight (ArrayKnight) wants to merge 2 commits into
Conversation
…o channel values resolve adjustChannel picked its per-channel result with ||, so a legitimately falsy value — channel value 0 on a fully dark colour — fell through to the hue branch. Measured consequence: a channel="value" ColorSlider on a dark colour rendered value="210" max="100", the thumb at 210% of its own track. ?? falls back only on missing entries. Found during the windmod ColorPicker planning probes; recorded in the campaign findings roster as fixed-in-tree. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013wmpBCYJpDJCLXcScCWz1i
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Aj9uA3rCVgosnh2zNn8qkc
| */ | ||
| export function adjustChannel<T>(channel: ColorChannel, actions: ChannelActions<T>): T { | ||
| return actions[channel] || actions.hue; | ||
| return actions[channel] ?? actions.hue; |
Contributor
There was a problem hiding this comment.
Good catch! Could we add a test to cover the bug and help prevent regressions in the future?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
adjustChannel.tsselects the per-channel action withactions[channel] || actions.hue. The||arm was presumably meant as a default for an unknown channel, but in the code path that reaches it the expression evaluates on the channel's value — so a channel whose value is0(zero saturation, zero alpha, …) takes the falsy branch and is handled by the hue action instead of its own. The visible symptom is the slider for that channel rendering with hue's domain:<input value="210" max="100">, with the thumb painted off the end of the track.The fix is
actions[channel] ?? actions.hue, so the fallback fires only when the channel key is genuinely absent. No API or type change.Fixes #36646.
Extracted from #36656 per maintainer request — each in-tree fix from that PR as an isolated change.