Skip to content

Fix: null check in setSmallerLargerStatus to prevent TypeError on wheel scroll#6437

Open
swapnachoudhary43 wants to merge 4 commits intosugarlabs:masterfrom
swapnachoudhary43:fix/null-check-setSmallerLargerStatus
Open

Fix: null check in setSmallerLargerStatus to prevent TypeError on wheel scroll#6437
swapnachoudhary43 wants to merge 4 commits intosugarlabs:masterfrom
swapnachoudhary43:fix/null-check-setSmallerLargerStatus

Conversation

@swapnachoudhary43
Copy link
Copy Markdown
Contributor

Fixes #6436

Problem

When scrolling the mouse wheel on the canvas before the UI is
fully initialized, setSmallerLargerStatus crashes with:

TypeError: Cannot read properties of null (reading 'children')
    at Activity.setSmallerLargerStatus (activity.js:2188:43)
    at Activity._doSmallerBlocks (activity.js:2176:24)
    at doSmallerBlocks (activity.js:2145:28)
    at HTMLCanvasElement.__wheelHandler (activity.js:2525:55)

Root Cause

this.smallerContainer and this.largerContainer can be null
when the wheel event fires before containers are initialized.

Fix

Added a single null guard at the top of setSmallerLargerStatus:

if (!this.smallerContainer || !this.largerContainer) return;

Testing

  • All 123 test suites passing
  • Manually verified no console errors on mouse wheel scroll

Checklist

  • I have read the contributing guidelines
  • Tests pass locally
  • Fix is minimal and focused

@github-actions github-actions bot added tests Adds or updates test coverage size/M Medium: 50-249 lines changed area/javascript Changes to JS source files area/tests Changes to test files labels Mar 29, 2026
@github-actions
Copy link
Copy Markdown
Contributor

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

Failed Tests:

synthutils.test.js

Copy link
Copy Markdown
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.

Initially, the code looks good, but while trying to reproduce the bug, I was not able to. Can you give the exact steps to reproduce or maybe a clip of this error showing up while you test it?

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 4, 2026

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

@swapnachoudhary43
Copy link
Copy Markdown
Contributor Author

Hi @kartikktripathi! Thanks for the review. Here are the exact steps to reproduce:

Open Music Blocks in browser
Immediately scroll the mouse wheel on the canvas (within the first 1-2 seconds before UI fully loads)
Open DevTools Console (F12)
You will see: TypeError: Cannot read properties of null (reading 'children') at Activity.setSmallerLargerStatus

This happens because smallerContainer and largerContainer are initialized as null in setupDependencies() and only get assigned later in _setupPaletteMenu(). If the wheel event fires in that window, the crash occurs.
The fix adds a single null guard at the top of setSmallerLargerStatus to return early if containers aren't ready yet.

@kartikktripathi
Copy link
Copy Markdown
Contributor

Hey, I tried to reproduce it, but I'm still not able to do so on the master branch. Can you record a video of this bug if possible, and attach it here? That'll be helpful.

@Ashutoshx7
Copy link
Copy Markdown
Contributor

hy any updates on this

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 size/M Medium: 50-249 lines changed tests Adds or updates test coverage

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] TypeError: Cannot read properties of null (reading 'children') in setSmallerLargerStatus on mouse wheel scroll

3 participants