Skip to content

Fix spam-clicking Run button causing unhighlight error#6013

Open
gourijain029-del wants to merge 2 commits intosugarlabs:masterfrom
gourijain029-del:fix-spam-click-unhighlight-6010
Open

Fix spam-clicking Run button causing unhighlight error#6013
gourijain029-del wants to merge 2 commits intosugarlabs:masterfrom
gourijain029-del:fix-spam-click-unhighlight-6010

Conversation

@gourijain029-del
Copy link

@gourijain029-del gourijain029-del commented Mar 1, 2026

Fixes #6010

Problem

Rapidly clicking the Run button causes a runtime error:
Uncaught TypeError: Cannot read properties of undefined (reading 'unhighlight') at Blocks.unhighlight (blocks.js:2974)

This happens because overlapping executions create race conditions where blocks may be removed or modified while unhighlight operations are still queued.

Solution

This PR implements two safeguards:

  1. Added existence check in blocks.js: Before calling unhighlight() on a block, verify that the block exists in blockList to prevent accessing undefined objects.

  2. Prevent concurrent executions in activity.js: Added a guard in _doFastButton() to check the existing _alreadyRunning flag, preventing multiple simultaneous executions when the Run button is spam-clicked.

  • Bug Fix

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2026

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

@Ashutoshx7
Copy link
Contributor

Ashutoshx7 commented Mar 1, 2026

@gourijain029-del can u provide proper testing instruction as there is large diff ?
and also i don"t see run button error in my local repo /

@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2026

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

@gourijain029-del
Copy link
Author

Hi @Ashutosh7, thanks for the review! I've added detailed testing instructions in TESTING_INSTRUCTIONS_6010.md.

Regarding the "large diff" - the actual changes are very small (only 2 files, 6 lines added):

  • js/blocks.js: Added 1 condition check (line 2973)
  • js/activity.js: Added 5 lines to prevent spam-clicking (line 1656)

The large diff you're seeing might be because the branch includes recent upstream commits. The actual fix is minimal.

Regarding not seeing the error locally - this is a race condition bug that's timing-dependent and doesn't always reproduce. Here's why:

  1. It only happens when you click VERY fast (within milliseconds) while blocks are being highlighted
  2. You need a program with loops/repeats to make the execution window longer
  3. It's a classic race condition - it won't happen every time

To reproduce the bug:

  1. Create a program with Start → Repeat (10x) → Note → Pitch
  2. Open browser console
  3. Click the Run button 10-15 times as fast as possible
  4. Watch for: Uncaught TypeError: Cannot read properties of undefined (reading 'unhighlight')

Even if it's hard to reproduce, the defensive checks prevent potential crashes without affecting normal operation. The fix uses the existing _alreadyRunning flag that's already in the codebase.

Let me know if you need any clarification!

@Ashutoshx7
Copy link
Contributor

umm hy
we don"t add testing intruction in the pr
please remove just update your pr description with it

and also if your changes just 10 line of changes please remove unrelated changes

@Ashutoshx7
Copy link
Contributor

and its nothing you forgot to make new branch so commit from the previous branch followed here
so just rebase it
thanks

@gourijain029-del gourijain029-del force-pushed the fix-spam-click-unhighlight-6010 branch from b061a44 to fa0ed73 Compare March 1, 2026 21:07
@github-actions
Copy link
Contributor

github-actions bot commented Mar 1, 2026

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

@gourijain029-del
Copy link
Author

Hey @Ashutosh7! Fixed everything you mentioned:

  • Removed the testing instructions file
  • Rebased from upstream/master - now it's just 2 files, 7 lines changed
  • Updated the PR description with testing steps

The branch was messy before because I forgot to create a new one. Should be clean now. Let me know if anything else needs changing!

@Ashutoshx7
Copy link
Contributor

Hey @Ashutosh7! Fixed everything you mentioned:

  • Removed the testing instructions file
  • Rebased from upstream/master - now it's just 2 files, 7 lines changed
  • Updated the PR description with testing steps

The branch was messy before because I forgot to create a new one. Should be clean now. Let me know if anything else needs changing!

i haven't tested changes locally cause couldn"t reproduce the issue
pinging here someone for help here
@kartikktripathi hy kartik take a look if u could reproduce this locally

@gourijain029-del
Copy link
Author

I have now verified these changes locally. I've confirmed that spam-clicking the 'Run' button no longer causes the unhighlight crash, and the engine correctly handles multiple rapid clicks by ignoring redundant 'Run' requests while a sequence is already in progress. The core test suite also passes with no regressions.

@kartikktripathi
Copy link
Contributor

Sure @Ashutoshx7, I'll take a look.

Copy link
Contributor

@kartikktripathi kartikktripathi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gourijain029-del
I was able to reproduce instability when rapidly clicking Run, but I’m seeing some different runtime errors (length undefined and materialise tooltip errors) rather than the reported Blocks.unhighlight error. This suggests there may be a broader race condition during overlapping executions. Could you clarify the exact reproduction conditions where the unhighlight error occurs consistently?

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

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

@gourijain029-del
Copy link
Author

Hi @kartikktripathi ,I’ve updated the PR to set the _alreadyRunning flag synchronously and added a guard for the 500ms restart cooldown. This should fix both the length and tooltip errors you saw. can you please check it again.

@kartikktripathi
Copy link
Contributor

The changes made look good. I have tested your changes again, and as you mentioned - yes, this is fixing the console showing errors on rapid clicks. I have one concern though:
You mentioned that one will see Uncaught TypeError: Cannot read properties of undefined (reading 'unhighlight') in the browser console, but I could not reproduce it, if you still can reproduce this on the master branch, please do and attach the logs if possible, or maybe the test recorded, where the error shows up.

Also, if the message was a rare error to occur or environment specific, please share the details for the same.
else, we can proceed with a final code review, and I can approve the PR if everything looks good.

@gourijain029-del
Copy link
Author

The changes made look good. I have tested your changes again, and as you mentioned - yes, this is fixing the console showing errors on rapid clicks. I have one concern though: You mentioned that one will see Uncaught TypeError: Cannot read properties of undefined (reading 'unhighlight') in the browser console, but I could not reproduce it, if you still can reproduce this on the master branch, please do and attach the logs if possible, or maybe the test recorded, where the error shows up.

Also, if the message was a rare error to occur or environment specific, please share the details for the same. else, we can proceed with a final code review, and I can approve the PR if everything looks good.

The unhighlight error is a rare race condition that happens when the workspace resets the block index basically becomes stale for a split second. It’s really hard to trigger manually, so I just added that check as a defensive fail-safe to make it more robust.

@kartikktripathi
Copy link
Contributor

Alright, I've checked the code, and it looks good to me. Tested the code locally and ran npm test, everything looks fine. I think we're ready for a merge. Thanks for the contribution.

@walterbender, please have a look. Thanks!

@gourijain029-del gourijain029-del force-pushed the fix-spam-click-unhighlight-6010 branch from a0c2ec0 to fa0ed73 Compare March 2, 2026 16:46
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

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

Copy link
Contributor

@kartikktripathi kartikktripathi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like you've reverted your changes. I think that was not needed.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

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

@gourijain029-del
Copy link
Author

It seems like you've reverted your changes. I think that was not needed.

An accidental force-push from an older local branch temporarily overwrote the PR. I've restored the correct approved code back to the branch now.

@kartikktripathi
Copy link
Contributor

The number of added lines has increased. Please take a look.

@gourijain029-del gourijain029-del force-pushed the fix-spam-click-unhighlight-6010 branch from a0c2ec0 to 942cef4 Compare March 2, 2026 20:02
@github-actions
Copy link
Contributor

github-actions bot commented Mar 2, 2026

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

@kartikktripathi
Copy link
Contributor

took a final review, and everything looks good now.
Thanks!

@Ashutoshx7
Copy link
Contributor

seems good to me now
@kartikktripathi thanx for taking over

@gourijain029-del gourijain029-del force-pushed the fix-spam-click-unhighlight-6010 branch from 942cef4 to fa0ed73 Compare March 8, 2026 22:16
@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

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

@walterbender
Copy link
Member

Looks good but please fix the linting error.

- Add existence check before calling unhighlight() in blocks.js
- Prevent concurrent executions using _alreadyRunning flag in activity.js

Fixes sugarlabs#6010
@gourijain029-del gourijain029-del force-pushed the fix-spam-click-unhighlight-6010 branch from fa0ed73 to 2df9aeb Compare March 8, 2026 22:28
@github-actions
Copy link
Contributor

github-actions bot commented Mar 8, 2026

❌ Some Jest tests failed. Please check the logs and fix the issues before merging.

Failed Tests:

GraphicsBlocks.test.js

@github-actions github-actions bot added the bug fix Fixes a bug or incorrect behavior label Mar 8, 2026
@github-actions
Copy link
Contributor

github-actions bot commented Mar 9, 2026

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

@Ashutoshx7
Copy link
Contributor

@omsuneri Lgtm

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

Labels

bug fix Fixes a bug or incorrect behavior

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Spam-clicking Run button causes Blocks.unhighlight undefined error

4 participants