Skip to content

Commit b061a44

Browse files
author
gourijain026@gmail.com
committed
Add detailed testing instructions for spam-click fix
- Explains why bug might not always reproduce (race condition) - Provides step-by-step reproduction steps - Shows exact code changes (only 2 small modifications) - Includes multiple test cases
1 parent 7ce050d commit b061a44

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed

TESTING_INSTRUCTIONS_6010.md

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
# Testing Instructions for PR #6013 (Issue #6010)
2+
3+
## Issue Summary
4+
Spam-clicking the Run button causes a crash with error:
5+
```
6+
Uncaught TypeError: Cannot read properties of undefined (reading 'unhighlight')
7+
at Blocks.unhighlight (blocks.js:2974)
8+
```
9+
10+
## Changes Made
11+
This PR makes two minimal changes:
12+
13+
### 1. `js/blocks.js` (Line 2973)
14+
**Before:**
15+
```javascript
16+
if (thisBlock !== null) {
17+
this.blockList[thisBlock].unhighlight();
18+
}
19+
```
20+
21+
**After:**
22+
```javascript
23+
if (thisBlock !== null && this.blockList[thisBlock]) {
24+
this.blockList[thisBlock].unhighlight();
25+
}
26+
```
27+
**Why:** Adds defensive check to ensure block exists before calling unhighlight()
28+
29+
### 2. `js/activity.js` (Line 1656)
30+
**Before:**
31+
```javascript
32+
this._doFastButton = env => {
33+
this._onResize();
34+
this.blocks.activeBlock = null;
35+
hideDOMLabel();
36+
```
37+
38+
**After:**
39+
```javascript
40+
this._doFastButton = env => {
41+
// Prevent spam-clicking by checking if already running
42+
if (this.logo._alreadyRunning) {
43+
return;
44+
}
45+
46+
this._onResize();
47+
this.blocks.activeBlock = null;
48+
hideDOMLabel();
49+
```
50+
**Why:** Prevents multiple simultaneous executions when Run button is clicked rapidly
51+
52+
## How to Test
53+
54+
### Setup
55+
1. Checkout this branch: `git checkout fix-spam-click-unhighlight-6010`
56+
2. Install dependencies: `npm install`
57+
3. Start the server: `node index.js`
58+
4. Open browser: `http://localhost:3000`
59+
60+
### Test Case 1: Reproduce the Original Bug (Without Fix)
61+
To see the original issue, you need to create the right conditions:
62+
63+
1. Create a simple program with multiple blocks:
64+
- Add a **Start** block
65+
- Add a **Repeat** block (set to 10 or more)
66+
- Inside repeat, add **Note** block with **Pitch** block
67+
68+
2. Open browser console (F12 or Cmd+Option+I)
69+
70+
3. **Rapidly click the Run button (red play button) 10-15 times very quickly**
71+
- Click as fast as you can
72+
- The key is to click before the first execution completes
73+
74+
4. **Expected behavior WITHOUT fix:**
75+
- Console shows error: `Uncaught TypeError: Cannot read properties of undefined (reading 'unhighlight')`
76+
- Execution may stop or behave erratically
77+
- Block highlighting breaks
78+
79+
### Test Case 2: Verify the Fix Works
80+
With this PR's changes:
81+
82+
1. Use the same program from Test Case 1
83+
2. Open browser console
84+
3. **Rapidly click the Run button 10-15 times very quickly**
85+
4. **Expected behavior WITH fix:**
86+
- No errors in console
87+
- Program runs smoothly
88+
- Only one execution happens (subsequent clicks are ignored while running)
89+
- Block highlighting works correctly
90+
91+
### Test Case 3: Normal Operation Still Works
92+
1. Create any simple program
93+
2. Click Run button once
94+
3. Wait for completion
95+
4. Click Run button again
96+
5. **Expected:** Normal execution, no issues
97+
98+
### Test Case 4: Run Multiple Programs
99+
1. Create two separate Start blocks with different programs
100+
2. Click Run on first program
101+
3. Immediately click Run on second program
102+
4. **Expected:** First program completes, second program runs after
103+
104+
## Why the Bug Might Not Always Reproduce
105+
106+
The reviewer mentioned not seeing the error locally. This is because:
107+
108+
1. **Timing-dependent:** The bug only occurs when clicks happen during a specific window while blocks are being highlighted/unhighlighted
109+
2. **Speed-dependent:** You need to click VERY fast (within milliseconds)
110+
3. **Program-dependent:** Longer-running programs (with loops/repeats) make it easier to reproduce
111+
4. **Race condition:** It's a classic race condition that doesn't always manifest
112+
113+
## Verification
114+
Run the test suite to ensure no regressions:
115+
```bash
116+
npm test
117+
```
118+
119+
All 3827 tests should pass (one playwright test may fail due to unrelated issue).
120+
121+
## Additional Notes
122+
- The fix uses the existing `_alreadyRunning` flag that's already part of the codebase
123+
- Changes are minimal and defensive - they don't alter normal execution flow
124+
- Even if the bug is hard to reproduce, the defensive checks prevent potential crashes

0 commit comments

Comments
 (0)