Repository navigation
fix: fall back to the default instead of crashing on a removed IconButton/FAB prop value - #5315
Open
biggdawg320 wants to merge 1 commit into
Conversation
… value
IconButton's `mode` and `size`, and FAB's `variant`, indexed straight into
their token maps, so a value that 6.x removed (or any other string cast
past the types, such as 5.x's `contained`/`contained-tonal` modes, a
numeric `size`, or a 6.0-alpha FAB variant like `tonalPrimary`) crashed
with a TypeError that named neither the prop nor its replacement.
Appbar.Action and TextInput.Icon hit the same crash, since both forward
`size`/`mode` straight through to IconButton.
Resolve the value against the token map before using it, falling back
to the documented default ("standard" mode, "small" size, the
"primaryContainer" FAB variant). The resolvers stay pure; IconButton and
FAB's Shell warn once per change, in a `useEffect` keyed on the prop,
following the same dev-warning convention as Switch and TextInput.Icon
instead of warning on every render.
Co-Authored-By: Claude <noreply@anthropic.com>
|
Found potential problems with the pull request:
|
This branch has not been deployed
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.
Motivation
IconButton's
mode/sizeand FAB'svariantindexed straight into their token maps. A value that 6.x removed — 5.x'scontained/contained-tonalmodes, a numericsize, or a 6.0-alpha FAB variant such astonalPrimaryorsurface— crashed the render with a TypeError that named neither the prop nor the value that replaces it. SinceAppbar.ActionandTextInput.Iconforwardsize/modestraight through toIconButtonProps, they crashed the same way.Related issue
Screenshots / Videos
Not applicable: this is a logic fix with no visual change for valid prop values. An invalid value now renders with the component's existing default appearance instead of crashing.
Test plan
removed 5.x prop valuestests insrc/components/__tests__/IconButton.test.tsxcovering a removedmodeand a numericsize, asserting the resolved value matches the default and thatconsole.warnfires once (via the component's effect) with the rejected value.falls back instead of crashing on a removed variant valuetest insrc/components/__tests__/FAB.test.tsxfor an invalid FABvariant, and a matching pure fallback test insrc/components/__tests__/FABUtils.test.tsx.yarn jest src/components/__tests__/IconButton.test.tsx src/components/__tests__/FAB.test.tsx src/components/__tests__/FABUtils.test.tsx src/components/__tests__/TextInput.test.tsx src/components/__tests__/Appbar/Appbar.test.tsx --coverage=falseto confirm the new tests pass and nothing else regressed.This change was drafted with AI assistance (Claude) and verified against the project's test suite.
Fixes #5309