Skip to content

Fix FieldColorNumber crash when no palette is configured#21

Merged
jeperkins4 merged 1 commit into
custom/masterfrom
fix/colour-field-missing-palette
May 28, 2026
Merged

Fix FieldColorNumber crash when no palette is configured#21
jeperkins4 merged 1 commit into
custom/masterfrom
fix/colour-field-missing-palette

Conversation

@jeperkins4

Copy link
Copy Markdown

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 calls makeSwatches(valueMode, allColoursCSSFormat, titles). When a colour field has no colours field option AND the target defines no runtime.palette, allColoursCSSFormat is left undefined, and makeSwatches does allColoursCSSFormat.map(...)

TypeError: Cannot read properties of undefined (reading 'map')
  at makeSwatches (field_colour.ts)
  at new FieldColorNumber
  at createFieldEditor

Because the field is constructed during the flyout's show() block-inflation, this exception aborts show() before layout_ 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 FieldColorNumber constructor when neither field colours nor runtime.palette is set, so makeSwatches never receives undefined. 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

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>
@jeperkins4 jeperkins4 merged commit 235e300 into custom/master May 28, 2026
16 checks passed
@jeperkins4 jeperkins4 deleted the fix/colour-field-missing-palette branch May 28, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant