Draft
Fix Blockly "Invalid block definition" error and add Next.js integration with fullscreen support#1
Conversation
…nitions Co-authored-by: shaynlink <38408035+shaynlink@users.noreply.github.com>
Co-authored-by: shaynlink <38408035+shaynlink@users.noreply.github.com>
Co-authored-by: shaynlink <38408035+shaynlink@users.noreply.github.com>
Co-authored-by: shaynlink <38408035+shaynlink@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add configuration for Blockly toolbox blocks
Fix Blockly "Invalid block definition" error and add Next.js integration with fullscreen support
Oct 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When trying to use Blockly blocks in the toolbox, the following error occurred:
This happened with the following code:
Root Cause
The error occurred because Blockly's standard block definitions were not imported before workspace initialization. Blockly requires explicit import of block definition modules to register block types.
Solution
Added the critical imports of block definitions before
Blockly.inject():For Next.js compatibility (to avoid SSR issues), these are loaded dynamically in
useEffect:Changes Made
Core Component
app/_components/BlocklyBootstrap.tsx- Reusable Blockly componentwidth,height,fullScreenExample Pages
app/page.tsx- Main page with Blockly workspaceapp/fullscreen-example/page.tsx- Fullscreen mode demonstrationapp/layout.tsx- Root application layoutProject Configuration
package.json- Dependencies (Blockly 12.3.1, Next.js 14, TypeScript)tsconfig.json- TypeScript configuration.eslintrc.json- ESLint configurationnext.config.js- Next.js configuration.gitignore- Build artifacts and dependenciesDocumentation
README.md- Updated with quick start guide and usage examplesSOLUTION.md- Focused summary of the block definition fixBLOCKLY_GUIDE.md- Comprehensive 256-line guide covering:Features
✅ No more "Invalid block definition" errors - All standard Blockly blocks work correctly
✅ Next.js compatible - Client-side dynamic loading prevents SSR issues
✅ Fullscreen mode - Optional prop for immersive editing experience
✅ TypeScript - Fully typed for better developer experience
✅ Proper cleanup - Workspace disposal on component unmount
✅ All standard blocks available - Logic, loops, math, text, lists, variables, and functions
Screenshots
Main Interface with Blocks
Fullscreen Mode
Usage
Basic usage:
Fullscreen mode:
Testing
Key Takeaway
The fix is simple but critical: always import
blockly/blocksbefore using any blocks in your toolbox. The order matters:blockly/blocks)blockly/javascript)Blockly.inject()This is now handled automatically in the
BlocklyBootstrapcomponent.Original prompt
The following is a snapshot of a chat conversation between a user and an AI coding assistant. Prioritize later messages in the conversation.
User: Aide moi à configurer Blocky
AI: Je vais d'abord créer une todo list pour organiser le travail (lecture du fichier existant, vérifier les dépendances, mettre à jour le composant et tester). Ensuite je lirai le fichier
AI: pour voir l'état actuel et proposer des modifications. Expected outcome: todo list created and fichier lu.
AI: Je vais lire le fichier
AI: pour comprendre l'implémentation actuelle et repérer ce qui doit être adapté pour Next.js (attendu: contenu du fichier).
AI: Je marque la lecture du fichier comme terminée et je passe à la vérification des dépendances (recherche de
blocklydansAI: ). Ensuite j'ouvrirai
AI: .
AI: Je vais mettre à jour la todo list (marquer la vérification des dépendances terminée et passer la modification du composant en cours), puis modifier
AI: pour charger Blockly dynamiquement, stocker/vider le workspace proprement et éviter les imports côté serveur. Ensuite je vérifierai les erreurs de build. Expected outcome: fichier mis à jour et erreurs rapportées.
AI: Je vais appliquer un patch pour améliorer
AI: : enlever l'import statique global de Blockly (qui peut s'exécuter côté serveur) et le charger dynamiquement dans useEffect, gérer proprement la destruction du workspace et exposer un prop optionnel pour la taille. Outcome: fichier mis à jour.
AI:
AI: I will fix the lint/type issues: make Props readonly, tighten workspaceRef typing to 'Blockly.WorkspaceSvg | null' by importing types via dynamic import type or using unknown and casting, remove unnecessary eslint-disable and provide proper ts-expect-error comments, and handle the catch by logging. I'll update the file accordingly.
AI:
AI: I'll update the component to use a type-only import for
WorkspaceSvg, avoid 'any' and remove ts-expect-error comments by casting the dynamic import to a narrow interface usingunknown. This should satisfy the linter/type rules. I'll apply the patch now.AI:
AI: Progress update: I read the component and dependencies, then refactored
AI: to dynamically load Blockly on the client, type the workspace, and handle disposal cleanly. Next I'll run TypeScript/ESLint checks to ensure there are no remaining errors; I'll use the task runner to run a quick TypeScript build or run
pnpm -wisn't necessary — I'll runpnpm -wnot needed. I'll runpnpm -v? Instead I'll runpnpm -P? The workspace uses pnpm; I'll run a TypeScript check withpnpm dlx tsc --noEmitor runpnpm -w... I'll runpnpm -w? Simpler: runpnpm -wis wrong. I'll runpnpm -w... Hmm. Better: runpnpm -w --silent install? The guidance: use run_in_terminal. I'll runpnpm installthenpnpm devpartial. But running full dev may be slow. The requirement: run typecheck/build. Usepnpm dlx tsc --noEmitto run TS. I'll runpnpm dlx tsc --noEmitin workspace root.AI: The terminal command produced no visible output (likely because the environment didn't run the command). I'll instead run the project's lint script
pnpm -wis unnecessary; runpnpm -w? The workspace has pnpm; I'll runpnpm -w dlx tsc --noEmit? Simpler: runpnpm dlx tsc --noEmitagain with full path. I'll run it again.AI: The terminal returned no output again—this environment's terminal may not show output for these commands. I'll instead run the project's dev script to surface any runtime errors. I'll run
pnpm devwhich starts Next dev; it may be long-running but will show build errors. I'll run it in background so we can capture initial build output.AI: Progress: I updated the component, ran the dev server in background and saw it started on an alternate port (3001) with no build errors reported so far. Next I'll update the todo list: mark the component adaptation completed and add the steps for installation instructions as in-progress. Then I'll prepare a short guidance message in French explaining how to install and test Blockly locally and any caveats.
AI: J'ai mis en place la base pour intégrer Blockly côté client et vérifié rapidement le build/dev. Voici ce que j'ai fait, ce que je recommande ensuite, et comment tester localement.
Actions réalisées
AI: .
blocklyest déjà présent dansAI: (version ^12.3.1).
AI: pour :
Created from VS Code via the GitHub Pull Request extension.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.