Skip to content

fix(status): prevent TypeError when updating status for trashed or missing blocks #8264

Description

@yush-1018

Describe the bug

In js/widgets/status.js, when updating the Status Matrix widget for bpm, bpmfactor, or outputtools status fields (lines 158 and 169), the code directly accesses this.activity.blocks.blockList[statusField[0]].protoblock.staticLabels[0] without optional chaining.

If a tracked block is deleted/trashed while the Status Matrix widget is open, blockList[statusField[0]] is undefined, causing an unhandled TypeError: Cannot read properties of undefined (reading 'protoblock') console exception.

Notice that line 176 in the default switch branch already uses optional chaining (block?.protoblock?.staticLabels?.[0] || ""), but lines 158 and 169 were accidentally missed.

Steps to reproduce

  1. Open Music Blocks.
  2. Add a bpm or outputtools block to the workspace.
  3. Open the Status Matrix widget.
  4. Trash or delete the block while the Status Matrix widget is open.
  5. Inspect the developer console: TypeError: Cannot read properties of undefined (reading 'protoblock') is thrown at status.js:158 / status.js:169.

Expected behavior

status.js should use optional chaining (?.protoblock?.staticLabels?.[0] || "") consistently across all case branches (bpm, bpmfactor, and outputtools) to prevent runtime exceptions when blocks are deleted.

Cause & Code Location

In js/widgets/status.js:

  • Line 158: this.activity.blocks.blockList[statusField[0]].protoblock.staticLabels[0]
  • Line 169: this.activity.blocks.blockList[statusField[0]].protoblock.staticLabels[0]

Proposed Fix

Add optional chaining guards to lines 158 and 169 to match line 176:

label = this.activity.blocks.blockList[statusField[0]]?.protoblock?.staticLabels?.[0] || "";

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugFixes a bug or incorrect behavior

    Type

    No type

    Projects

    Status
    In Progress

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions