Skip to content

Fix duplicate listener name collision between DuplicateBlock and Arpe…#5806

Merged
walterbender merged 2 commits intosugarlabs:masterfrom
Ady0333:fix/duplicate-listener-name-collision
Mar 8, 2026
Merged

Fix duplicate listener name collision between DuplicateBlock and Arpe…#5806
walterbender merged 2 commits intosugarlabs:masterfrom
Ady0333:fix/duplicate-listener-name-collision

Conversation

@Ady0333
Copy link
Contributor

@Ady0333 Ady0333 commented Feb 19, 2026

Summary

This PR fixes a listener name collision between DuplicateBlock and ArpeggioBlock that caused silent block-graph corruption when one was nested inside the other. Both blocks constructed their teardown listener name as "_duplicate_" + turtle, and since setTurtleListener() stores listeners in a flat dictionary keyed by this string, the inner block registration overwrote the outer block’s listener. When the outer DuplicateBlock clamp ended, its teardown never executed, leaving connectionStore[turtle][duplicateBlk] populated and permanently corrupting the block graph across runs.


Impact

When nesting Arpeggio inside Duplicate notes (or vice versa), the outer block’s cleanup was silently swallowed. This caused connection rewiring performed by DuplicateBlock to never be restored, leading to progressively broken playback behavior across runs. The corruption persisted until page reload and produced no visible runtime error, making it especially misleading in classroom usage.


Steps to Reproduce

  1. Open Music Blocks.
  2. Create: Start → Arpeggio (Cm) clamp → Duplicate notes (2×) clamp → Note 1/4.
  3. Click Run.
  4. Stop and Run again.

Observed: incorrect duplication behavior and progressive corruption across runs.
Expected: each clamp restores its original connections after execution.


Root Cause

Both blocks used the identical listener key:

const listenerName = "_duplicate_" + turtle;
When nested, the second setTurtleListener() call evicted the first listener, so the outer teardown callback was permanently lost.

Fix

Append blk to the listener name so each block instance has a unique teardown listener, matching the convention used by other clamp blocks.

// FlowBlocks.js
- const listenerName = "_duplicate_" + turtle;
+ const listenerName = "_duplicate_" + turtle + "_" + blk;

// IntervalsBlocks.js
- const listenerName = "_duplicate_" + turtle;
+ const listenerName = "_duplicate_" + turtle + "_" + blk;

Scope

Two-line change in:

  • js/blocks/FlowBlocks.js
  • js/blocks/IntervalsBlocks.js

No logic changes, no API changes, no new state introduced.


Verification

Nested Duplicate and Arpeggio blocks now clean up correctly.
connectionStore is restored after execution.
Multiple runs do not accumulate corruption.
Lint and tests pass.

…ggioBlock

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
@Ady0333
Copy link
Contributor Author

Ady0333 commented Feb 19, 2026

@vanshika2720 and @walterbender , please review this pr once.

@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
@github-actions
Copy link
Contributor

✅ All Jest tests passed! This PR is ready to merge.

@walterbender walterbender merged commit fbb3afb into sugarlabs:master Mar 8, 2026
7 checks passed
parthdagia05 pushed a commit to parthdagia05/musicblocks that referenced this pull request Mar 15, 2026
sugarlabs#5806)

* Fix duplicate listener name collision between DuplicateBlock and ArpeggioBlock

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>

* Format FlowBlocks.js to pass Prettier check

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>

---------

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
parthdagia05 pushed a commit to parthdagia05/musicblocks that referenced this pull request Mar 15, 2026
sugarlabs#5806)

* Fix duplicate listener name collision between DuplicateBlock and ArpeggioBlock

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>

* Format FlowBlocks.js to pass Prettier check

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>

---------

Signed-off-by: Ady0333 <adityashinde1525@gmail.com>
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.

3 participants