Skip to content

fix: prevent crash when dragging blocks after rapidly creating projects - #7985

Open
UtkarshAnandd wants to merge 1 commit into
sugarlabs:masterfrom
UtkarshAnandd:fix/drag-group-undefined-block-crash
Open

fix: prevent crash when dragging blocks after rapidly creating projects#7985
UtkarshAnandd wants to merge 1 commit into
sugarlabs:masterfrom
UtkarshAnandd:fix/drag-group-undefined-block-crash

Conversation

@UtkarshAnandd

@UtkarshAnandd UtkarshAnandd commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes a crash that could occur when repeatedly using New Project and then Play before dragging a block onto the workspace.

The drag controller could encounter an uninitialised/undefined entry in blockList and attempt to read its connections property. This PR adds a guard in _calculateDragGroup so invalid block entries are safely ignored.

Changes

  • Guard _calculateDragGroup against undefined blockList entries.
  • Preserve handling for both null and undefined blocks.
  • Add a regression test for the undefined-block scenario.

Testing

  • Reproduced the issue by clicking Next Project and Play repeatedly, then dragging a block.
  • Verified the app no longer crashes.
  • Ran the relevant test suite successfully.
  • I corrected the typo and added exact reproduction steps to the PR description.

Quick verification:

  1. Open Music Blocks.
  2. Rapidly create several projects using New Project.
  3. Open the latest project.
  4. Drag any palette block onto the workspace.

Before this fix, this could crash. With this PR, the block is added normally.

Screenshot 2026-08-07 at 4 12 47 PM ## Category
  • Bug fix

Cannot read properties of undefined (reading 'connections') crashed on
rapid next-project + play. myBlock === null never caught the undefined
case, which is what blockList[blk] actually returns for an index past
the currently-populated portion of the array. Widened the guard to a
falsy check (covers both null and undefined) and added a regression test.
@codecov

codecov Bot commented Aug 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.13%. Comparing base (4c41f62) to head (d379194).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #7985   +/-   ##
=======================================
  Coverage   62.13%   62.13%           
=======================================
  Files         187      187           
  Lines       58275    58275           
=======================================
+ Hits        36209    36211    +2     
+ Misses      22066    22064    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@github-actions github-actions Bot added bug fix Fixes a bug or incorrect behavior size/S Small: 10-49 lines changed area/javascript Changes to JS source files area/tests Changes to test files labels Aug 7, 2026
@walterbender

Copy link
Copy Markdown
Member

Maybe there is a typo in your description? I don't know what the "Next Project" button is, so I don't know how to reproduce this bug or test your solution.

@UtkarshAnandd

UtkarshAnandd commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

@walterbender Thanks — it was a typo. I meant New Project , not “Next Project.” I’ve updated the PR description with the exact reproduction and verification steps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/javascript Changes to JS source files area/tests Changes to test files bug fix Fixes a bug or incorrect behavior size/S Small: 10-49 lines changed

Projects

Development

Successfully merging this pull request may close these issues.

2 participants