Skip to content

Fix horizontal compressed playground#8

Merged
supervoidcoder merged 3 commits intodevelopfrom
fix-horizontal-blocks
Nov 7, 2025
Merged

Fix horizontal compressed playground#8
supervoidcoder merged 3 commits intodevelopfrom
fix-horizontal-blocks

Conversation

@supervoidcoder
Copy link
Member

Load compressed message and block bundles and add toolbox XML so horizontal compressed playground works without Closure runtime.

… compressed playground to restore toolbox/flyout
@devloai
Copy link

devloai bot commented Nov 7, 2025

Unable to perform a code review. You have run out of credits 😔
Please upgrade your plan or buy additional credits from the subscription page.

@amazon-q-developer
Copy link

Code review in progress. Analyzing for code quality issues and best practices. You can monitor the review status in the checks section at the bottom of this pull request. Detailed findings will be posted upon completion.

Using Amazon Q Developer for GitHub

Amazon Q Developer1 is an AI-powered assistant that integrates directly into your GitHub workflow, enhancing your development process with intelligent features for code development, review, and transformation.

Slash Commands

Command Description
/q <message> Chat with the agent to ask questions or request revisions
/q review Requests an Amazon Q powered code review
/q help Displays usage information

Features

Agentic Chat
Enables interactive conversation with Amazon Q to ask questions about the pull request or request specific revisions. Use /q <message> in comment threads or the review body to engage with the agent directly.

Code Review
Analyzes pull requests for code quality, potential issues, and security concerns. Provides feedback and suggested fixes. Automatically triggered on new or reopened PRs (can be disabled for AWS registered installations), or manually with /q review slash command in a comment.

Customization

You can create project-specific rules for Amazon Q Developer to follow:

  1. Create a .amazonq/rules folder in your project root.
  2. Add Markdown files in this folder to define rules (e.g., cdk-rules.md).
  3. Write detailed prompts in these files, such as coding standards or best practices.
  4. Amazon Q Developer will automatically use these rules when generating code or providing assistance.

Example rule:

All Amazon S3 buckets must have encryption enabled, enforce SSL, and block public access.
All Amazon DynamoDB Streams tables must have encryption enabled.
All Amazon SNS topics must have encryption enabled and enforce SSL.
All Amazon SNS queues must enforce SSL.

Feedback

To provide feedback on Amazon Q Developer, create an issue in the Amazon Q Developer public repository.

For more detailed information, visit the Amazon Q for GitHub documentation.

Footnotes

  1. Amazon Q Developer uses generative AI. You may need to verify generated code before using it in your environment. See the AWS Responsible AI Policy.

@wellcode-ai wellcode-ai bot added the review-effort-2 Light review (15-30 min) label Nov 7, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 7, 2025

Summary by CodeRabbit

  • Documentation

    • Updated playground setup instructions with clearer guidance on opening and rebuilding compressed playgrounds locally.
    • Added note about restarting the development server when applying linked updates.
  • Tests

    • Added new horizontal layout playground for comprehensive testing with configurable parameters and stress-test utilities.

Walkthrough

Updated README guidance for opening and rebuilding compressed playgrounds; added a new self-contained compressed horizontal-playground HTML that initializes a horizontal Blockly workspace, supports URL-driven configuration, XML import/export, event logging, sound toggles, state persistence, and stress-test utilities.

Changes

Cohort / File(s) Change Summary
Documentation updates
README.md
Expanded instructions to recommend opening playgrounds in a browser, clarified compressed playgrounds work locally without fetching Closure, specified explicit compressed playground paths, changed rebuild guidance to npm run prepublish, and noted restart requirement for scratch-gui dev server to pick up linked scratch-blocks.
New horizontal playground
tests/horizontal_playground_compressed.html
Added a compressed, self-contained horizontal Blockly playground. Implements URL-param configuration (toolbox, dir, side), sessionStorage state restore/persist, XML import/export with validation, event and flyout logging toggles, sound controls, block/stack glow helpers, and stress-test functions (sprinkles, spaghetti, fake drags) plus public utilities like start() and getToolboxElement().

Sequence Diagram

sequenceDiagram
    autonumber
    participant User
    participant Browser
    participant Playground as horizontal_playground_compressed.html
    participant Blockly
    participant Storage as sessionStorage

    User->>Browser: Open playground URL (with params)
    Browser->>Playground: Load HTML -> call start()
    Playground->>Playground: parse URL params (toolbox, dir, side)
    Playground->>Storage: restore saved state (XML, logs, sounds)
    Playground->>Blockly: init workspace with horizontal layout
    Blockly-->>Playground: workspace ready
    Note right of Playground: Render UI controls (import/export, toggles, tests)
    
    User->>Playground: Interact (import XML, toggle logging, trigger tests)
    Playground->>Blockly: apply changes / synthetic events (fakeDrag)
    Blockly-->>Playground: emit events (logged if enabled)
    Playground->>Storage: persist updated state
    Playground->>Browser: update UI display
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Attention areas:
    • tests/horizontal_playground_compressed.html: verify correct use of Blockly compressed bundles, URL-param parsing, sessionStorage keys, XML validation and error handling, event listener management, and synthetic drag event sequencing.
    • README.md: confirm npm run prepublish exists and referenced paths match repository layout.

Poem

🐰 A compressed playground hops into view,
Blocks glance and glow in a horizontal hue.
XML flows, fake drags tumble and play,
Logs whisper secrets of each tiny sway.
Hop, hop—new tests brighten the day!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix horizontal compressed playground' clearly and concisely summarizes the main change: fixing the horizontal compressed playground file to work without Closure runtime.
Description check ✅ Passed The description 'Load compressed message and block bundles and add toolbox XML so horizontal compressed playground works without Closure runtime' directly relates to the changes, specifying what was added and why.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-horizontal-blocks

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@wellcode-ai
Copy link

wellcode-ai bot commented Nov 7, 2025

🔍 General Code Quality Feedback

🔍 Comprehensive Code Review

Consolidated Feedback

  • 🔍 Code Review Analysis

Overall Assessment: The pull request introduces a new HTML file for a compressed playground, which is a useful addition. However, there are several areas that require attention to ensure code quality, maintainability, and security.

Critical Issues:

  • Issue 1: Lack of Input Validation → The code does not validate URL parameters before using them. This could lead to unexpected behavior or security vulnerabilities (e.g., XSS). Implement input validation for URL parameters to ensure they conform to expected formats.

  • Issue 2: Hardcoded File Paths → The script tags use relative paths that may not work in all environments. This can lead to broken links. Consider using a configuration file or environment variables to manage paths dynamically.

Improvements:

  • Suggestion 1: Improve Code Readability → The JavaScript code could benefit from additional comments explaining the purpose of key functions and variables. For example, add comments to describe the start function's purpose and the significance of the soundsEnabled variable.

  • Suggestion 2: Modularize JavaScript Code → The JavaScript code is currently inline within the HTML file. Consider moving it to a separate .js file to enhance maintainability and separation of concerns. This will also facilitate easier testing and debugging.

Positive Notes:

  • The addition of the toolbox XML is a good practice as it enhances the functionality of the playground without requiring external dependencies. The README updates are also helpful for developers to understand how to use the new compressed playgrounds.

Next Steps:

  1. Implement input validation for URL parameters to prevent potential security vulnerabilities.
  2. Refactor the JavaScript code into a separate file for better maintainability and readability.
  3. Review and update the file paths to ensure they are dynamic and adaptable to different environments.
  4. Add unit tests for the new functionality introduced in the compressed playground to ensure it behaves as expected.
  5. Enhance comments and documentation within the JavaScript code to improve clarity for future developers.

By addressing these issues and suggestions, the code quality and maintainability of the project will be significantly improved, reducing the risk of bugs and enhancing developer productivity.

🤖 Generated by Wellcode.ai

Copy link

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

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

Summary

This PR successfully adds a horizontal compressed playground to enable testing horizontal block layouts without requiring Closure runtime dependencies. The implementation includes proper script loading, toolbox configuration, and UI controls for testing various layout options.

Key Issues Found

Critical Issues:

  • Logic Error: Incorrect setTimeout usage in fakeDrag function that will cause immediate execution instead of delayed execution
  • Null Reference Risk: Potential crash when accessing flyout workspace without proper null checks

Minor Issues:

  • Incorrect boolean assignment to checkbox.checked property
  • Unused variable declaration
  • Minor style inconsistency with spacing

Recommendation

The PR addresses the stated goal but requires fixes for the critical logic error and null reference handling before merge. The other issues are minor improvements that enhance code quality.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.


function setSoundsEnabled(state) {
var checkbox = document.getElementById('soundsEnabled');
checkbox.checked = (state) ? 'checked' : '';

Choose a reason for hiding this comment

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

Incorrect boolean assignment to checkbox.checked property. The checked property expects a boolean value, not a string.

Suggested change
checkbox.checked = (state) ? 'checked' : '';
checkbox.checked = state;

Comment on lines +158 to +159
var flyoutWorkspace = (workspace.flyout_) ? workspace.flyout_.workspace_ :
workspace.toolbox_.flyout_.workspace_;

Choose a reason for hiding this comment

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

Potential null reference error when accessing flyout workspace. The code assumes either workspace.flyout_ or workspace.toolbox_.flyout_ exists, but doesn't handle cases where both might be null.

Suggested change
var flyoutWorkspace = (workspace.flyout_) ? workspace.flyout_.workspace_ :
workspace.toolbox_.flyout_.workspace_;
var flyoutWorkspace = null;
if (workspace.flyout_) {
flyoutWorkspace = workspace.flyout_.workspace_;
} else if (workspace.toolbox_ && workspace.toolbox_.flyout_) {
flyoutWorkspace = workspace.toolbox_.flyout_.workspace_;
}
if (!flyoutWorkspace) {
console.warn('Flyout workspace not found');
return;
}

Comment on lines +196 to +197
var prototypes = [];
var toolbox = workspace.options.languageTree;

Choose a reason for hiding this comment

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

Unused variable declaration. The prototypes array is declared but never used in the function.

Suggested change
var prototypes = [];
var toolbox = workspace.options.languageTree;
function sprinkles(n) {
var toolbox = workspace.options.languageTree;


function spaghetti(n) {
var xml = spaghettiXml;
for(var i = 0; i < n; i++) {

Choose a reason for hiding this comment

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

Missing space after for keyword violates JavaScript style conventions.

Suggested change
for(var i = 0; i < n; i++) {
for (var i = 0; i < n; i++) {

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4bf9173 and 63a6873.

📒 Files selected for processing (2)
  • README.md (1 hunks)
  • tests/horizontal_playground_compressed.html (1 hunks)
🔇 Additional comments (6)
README.md (1)

21-34: Documentation improvements are clear and well-organized. The guidance now explicitly directs users to compressed playgrounds for local development without Closure runtime overhead, specifies rebuild conditions, and clarifies the need to restart the scratch-gui dev server. The changes align well with the new horizontal compressed playground.

tests/horizontal_playground_compressed.html (5)

1-14: Script loading strategy is appropriate. Compressed bundles are loaded first, avoiding runtime Closure network dependencies, followed by message catalogs and block definitions. The loading order and bundle selection enable the playground to function as a standalone, self-contained resource.


22-100: Workspace initialization and state restoration logic is well-structured. URL parameter parsing and sessionStorage management for layout preferences, event logging state, and XML content follow a sensible pattern with appropriate fallbacks. The Blockly configuration covers grid, zoom, colors, and layout orientation comprehensively.


107-165: XML import/export and event logging setup are sound. Validation via try/catch and delegation to Blockly's safe XML parsing methods prevents injection risks. Event listener management correctly distinguishes between workspace and flyout contexts.


352-427: Inline toolbox with Categories layout is well-formed. The XML defines a representative set of Scratch block types (Events, Control, Wedo) with appropriate shadow values and nested field structures. Blocks are properly structured for horizontal layout.


437-496: UI controls and forms are comprehensive and accessible. The form provides intuitive options for layout direction (LTR/RTL), toolbox type, and toolbox position. Export/import controls, event logging toggles, sound configuration, and stress-test utilities expose useful developer features. Button and input bindings follow a clear naming convention.

…delayed execution. The function call fakeDragWrapper() is being executed immediately and its return value (undefined) is passed to setTimeout.


Critical bug in fakeDrag timing logic. Line 278 invokes fakeDragWrapper() immediately in the setTimeout call instead of passing a function reference. This breaks the intended asynchronous drag sequence and will cause premature execution of queued drags before the current mousemove/mouseup cycle completes.

Co-authored-by: amazon-q-developer[bot] <208079219+amazon-q-developer[bot]@users.noreply.github.com>
@wellcode-ai wellcode-ai bot added review-effort-2 Light review (15-30 min) and removed review-effort-2 Light review (15-30 min) labels Nov 7, 2025
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@wellcode-ai wellcode-ai bot added review-effort-2 Light review (15-30 min) and removed review-effort-2 Light review (15-30 min) labels Nov 7, 2025
@supervoidcoder supervoidcoder merged commit 3444b45 into develop Nov 7, 2025
0 of 3 checks passed
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

♻️ Duplicate comments (1)
tests/horizontal_playground_compressed.html (1)

158-159: Potential null reference error on missing toolbox or flyout.

If workspace.toolbox_ or workspace.toolbox_.flyout_ is null, this code will throw a runtime error. Add null checks before accessing nested properties.

  function logFlyoutEvents(state) {
    var checkbox = document.getElementById('logFlyoutCheck');
    checkbox.checked = state;
    if (sessionStorage) {
-     sessionStorage.setItem('logFlyoutEvents', state ? 'checked' : '');
+     sessionStorage.setItem('logFlyoutEvents', state);
    }
-   var flyoutWorkspace = (workspace.flyout_) ? workspace.flyout_.workspace_ :
-     workspace.toolbox_.flyout_.workspace_;
+   var flyoutWorkspace = null;
+   if (workspace.flyout_) {
+     flyoutWorkspace = workspace.flyout_.workspace_;
+   } else if (workspace.toolbox_ && workspace.toolbox_.flyout_) {
+     flyoutWorkspace = workspace.toolbox_.flyout_.workspace_;
+   }
+   if (!flyoutWorkspace) {
+     console.warn('Flyout workspace not found');
+     return;
+   }
    if (state) {
      flyoutWorkspace.addChangeListener(logger);
    } else {
      flyoutWorkspace.removeChangeListener(logger);
    }
  }
🧹 Nitpick comments (4)
tests/horizontal_playground_compressed.html (4)

195-212: Remove unused variable declaration.

The prototypes array is declared at line 196 but never used in the function.

  function sprinkles(n) {
-   var prototypes = [];
    var toolbox = workspace.options.languageTree;
    if (!toolbox) {
      console.error('Toolbox not found; add a toolbox element to the DOM.');
      return;
    }

214-225: Add space after for keyword for consistent style.

Line 216 is missing a space after for, inconsistent with line 203.

  function spaghetti(n) {
    var xml = spaghettiXml;
-   for(var i = 0; i < n; i++) {
+   for (var i = 0; i < n; i++) {
      xml = xml.replace(/(<(statement|next)( name="SUBSTACK")?>)<\//g,
      '$1' + spaghettiXml + '</');
    }

143-143: Standardize sessionStorage value format.

Lines 143 and 156 store 'checked' or '' strings, but this is semantically inconsistent with line 243 which stores the boolean directly, and with the 'true'/'false' pattern used for soundsEnabled retrieval (line 30). Standardize to store 'true'/'false' strings for consistency.

  function logEvents(state) {
    var checkbox = document.getElementById('logCheck');
    checkbox.checked = state;
    if (sessionStorage) {
-     sessionStorage.setItem('logEvents', state ? 'checked' : '');
+     sessionStorage.setItem('logEvents', state ? 'true' : 'false');
    }
    // ...
  }
  
  function logFlyoutEvents(state) {
    var checkbox = document.getElementById('logFlyoutCheck');
    checkbox.checked = state;
    if (sessionStorage) {
-     sessionStorage.setItem('logFlyoutEvents', state ? 'checked' : '');
+     sessionStorage.setItem('logFlyoutEvents', state ? 'true' : 'false');
    }
    // ...
  }

Also applies to: 156-156


40-40: Use strict equality (===) for string comparisons.

Lines 40, 62, and 63 use loose equality (==) to compare strings. Use strict equality (===) to avoid unintended type coercion and follow JavaScript best practices.

-       var rtl = match && match[1] == 'rtl';
+       var rtl = match && match[1] === 'rtl';
        // ...
-         horizontalLayout: side == 'top' || side == 'bottom',
-         toolboxPosition: side == 'top' || side == 'start' ? 'start' : 'end',
+         horizontalLayout: side === 'top' || side === 'bottom',
+         toolboxPosition: side === 'top' || side === 'start' ? 'start' : 'end',

Also applies to: 62-62, 63-63

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 63a6873 and 438bbf1.

📒 Files selected for processing (1)
  • tests/horizontal_playground_compressed.html (1 hunks)
🔇 Additional comments (1)
tests/horizontal_playground_compressed.html (1)

52-82: Workspace initialization is well-configured.

The Blockly workspace initialization includes appropriate options for horizontal layout, media paths, and compression-friendly settings. The configuration correctly handles URL parameters for direction, toolbox, and positioning.

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

Labels

review-effort-2 Light review (15-30 min) size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant