Skip to content

Bug fixes: Null guard in repositionBlocks and _setupPaletteMenu#6446

Open
Shiv0087 wants to merge 1 commit intosugarlabs:masterfrom
Shiv0087:fix/null-guard-repositionBlocks-and-paletteMenu
Open

Bug fixes: Null guard in repositionBlocks and _setupPaletteMenu#6446
Shiv0087 wants to merge 1 commit intosugarlabs:masterfrom
Shiv0087:fix/null-guard-repositionBlocks-and-paletteMenu

Conversation

@Shiv0087
Copy link
Copy Markdown

@Shiv0087 Shiv0087 commented Mar 30, 2026

Type: Bug

Bug fixes: Null guard in repositionBlocks and _setupPaletteMenu

Problem

Two uncaught TypeErrors occur during scroll and resize:

  • Cannot read properties of undefined (reading 'blockList') in repositionBlocks
  • Cannot read properties of undefined (reading 'hide') in _setupPaletteMenu

Fix

Added null checks before accessing:

  • activity.blocks.blockList
  • this.boundary

Testing

No TypeErrors observed in console.

Copilot AI review requested due to automatic review settings March 30, 2026 13:16
@github-actions
Copy link
Copy Markdown
Contributor

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

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses two runtime TypeErrors triggered during scroll/resize by adding defensive guards before accessing properties that may not be initialized yet.

Changes:

  • Added early-return guard in repositionBlocks() when activity.blocks.blockList is unavailable.
  • Wrapped this.boundary.hide() in a null check to prevent calling hide() on undefined.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

// FIX: guard against blocks not being initialized yet
if (!activity || !activity.blocks || !activity.blocks.blockList) {
return;
}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

The closing brace indentation is inconsistent (line 813 has extra leading whitespace), which makes the control flow harder to read and easy to mis-edit. Please align the braces/indentation with the surrounding style (i.e., } aligned with the if).

Suggested change
}
}

Copilot uses AI. Check for mistakes.
Comment on lines 818 to 822
//Array for storing individual dragGroups (the chunks of code linked together which are not connected)
const dragGroups = [];


// Identifying individual dragGroups
Object.values(activity.blocks.blockList).forEach(block => {
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

This comment states there is an array for storing dragGroups, but the dragGroups declaration was removed in this hunk. Either restore the declaration (if it’s still used later in repositionBlocks) or update/remove the comment to avoid misleading future edits.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +809 to +813
function repositionBlocks(activity) {
// FIX: guard against blocks not being initialized yet
if (!activity || !activity.blocks || !activity.blocks.blockList) {
return;
}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

The new null-guard block has inconsistent indentation/bracing compared to the surrounding file formatting (e.g., extra leading spaces and a misaligned closing brace). CI runs Prettier on changed JS files, so this will likely fail the formatting check; please reformat this block to match the project’s 4-space indentation (.editorconfig) / Prettier settings.

Copilot uses AI. Check for mistakes.
Comment on lines 6583 to +6587
);
this.boundary.hide();
// ✅ FIX: guard against boundary not being initialized
if (this.boundary) {
this.boundary.hide();
}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

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

This newly added this.boundary guard is misindented (extra leading spaces on the comment/if/body). Since the repo enforces Prettier formatting in CI for changed JS files, please reformat this section to match the surrounding indentation.

Copilot uses AI. Check for mistakes.
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