Fix FieldColorNumber crash when no palette is configured#21
Merged
Conversation
makeSwatches() was called with an undefined colour list whenever a colour field had no `colours` field option AND the target defined no runtime.palette, throwing "Cannot read properties of undefined (reading 'map')". Because this happens during flyout show() block-inflation, the exception aborts show() before layout_ runs, leaving every block in that category unpositioned (piled at the flyout origin). Older pxt tolerated a missing palette; restore that by falling back to a default palette when neither field colours nor runtime.palette is set. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.
Problem
In the Blockly toolbox flyout, any category containing a colour field renders all its blocks piled on top of each other at the flyout origin (overlapping, the widest block overflowing horizontally). In FUSE this hits the Display category.
Root cause
FieldColorNumber's constructor callsmakeSwatches(valueMode, allColoursCSSFormat, titles). When a colour field has nocoloursfield option AND the target defines noruntime.palette,allColoursCSSFormatis leftundefined, andmakeSwatchesdoesallColoursCSSFormat.map(...)→Because the field is constructed during the flyout's
show()block-inflation, this exception abortsshow()beforelayout_runs, so every block in that category is left unpositioned (transform=null) and piles at the origin.Older pxt tolerated a missing palette; this path regressed.
Fix
Fall back to a default palette in the
FieldColorNumberconstructor when neither fieldcoloursnorruntime.paletteis set, somakeSwatchesnever receivesundefined. Targets that configure a palette are unaffected (it takes precedence).Verification
Built and re-vendored into the FUSE app. The Display flyout now stacks all blocks vertically with correct spacing, colour pickers render swatches, and switching between categories leaves no artifacts.
Co-Authored-By: Claude Opus 4.8 (1M context) noreply@anthropic.com
🤖 Generated with Claude Code