fix(scratch-blocks-v2): resolve post-upstream-merge regressions#653
Merged
Conversation
Three regressions surfaced after the scratch-blocks v1 → v2 (Blockly v12) upgrade in PR #630. 1. CustomProcedures (ブロックを作る) modal - blocks.jsx: handleCustomProceduresClose now uses `refreshToolboxSelection` (was `refreshToolboxSelection_`) and `getToolbox().scrollToCategory(id)` (was `toolbox_.scrollToCategoryById`). - custom-procedures.jsx: pass `theme` + `scratchTheme` to `ScratchBlocks.inject` so the procedures_declaration block renders with the proper category colours instead of black. - webpack.config.js: also copy `blockly/media/` into `static/blocks-media/` so v2-only assets like `disconnect.mp3` are served (was 404). 2. Extension category does not auto-scroll on add - blocks.jsx: handleExtensionAdded sets `_pendingScrollToCategoryId`; the post-rebuild path in `updateToolbox` looks the category up by `toolboxItemDef_.id` (Blockly v12 ignores the `id` attribute we emit and assigns its own `blockly-XXX` ids), then calls `selectCategoryByName(name)` and `flyout.scrollToCategory(item)`. 3. smalrubyRuby blocks fail to drag from flyout - translations.json: add missing `smalrubyRuby.hashMethodWithBlock` ja / ja-Hira translations. - define-dynamic-block.js: `mutationToDom` now uses `ScratchBlocks.utils.xml.createElement` (XML namespace) and lowercase `blockinfo` attribute. `document.createElement` produces an HTMLUnknownElement which lowercases attribute names through the XMLSerializer round-trip used by Blockly v2 JSON serialization (`extraState`); after the round-trip `getAttribute('blockInfo')` returned `null`, so `domToMutation` aborted early, the block had no inputs/fields, and field/input load reported "Ignoring non-existant field METHOD" / "missing RECEIVER connection". Read side accepts both cases for forward compatibility.
|
🚀 Preview deployed: https://smalruby.jp/smalruby3-editor/fix/scratch-blocks-v2-post-merge-bugs/ |
…cedure `createProcedureCallbackFactory` creates the procedures_definition block, but the dynamic `custom="PROCEDURE"` flyout (My Blocks) only shows the new `procedures_call` block after the toolbox is rebuilt. scratch-blocks v1's `ContinuousToolbox.refreshSelection` rebuilt the flyout on every BLOCK_CREATE, so the call block appeared automatically. v2 made `refreshSelection` a no-op, leaving the flyout out of sync — the user defined a custom block, opened My Blocks, and saw only "ブロックを作る" with no call block to drag. Force a `toolbox.forceRerender()` from `handleCustomProceduresClose` (deferred via setTimeout to let pending block-create renders flush), then select + scroll the My Blocks category. Also rename a shadowed `flyout` local that lint flagged.
Smalruby's Modal container marks `id` as required (used to push a unique entry into history.state for back-button handling). Upstream omits it on the CustomProcedures modal — which produces a noisy "Failed prop type" warning in the console every time the modal opens. Pass `id="customProceduresModal"` to silence it.
github-actions Bot
pushed a commit
that referenced
this pull request
May 7, 2026
…locks-v2-post-merge-bugs fix(scratch-blocks-v2): resolve post-upstream-merge regressions
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.
Summary
upstream マージ (#630, scratch-blocks v1 → v2 / Blockly v12) で発生した 3 件のリグレッションを修正。
(1) ブロック定義モーダル
containers/blocks.jsx:handleCustomProceduresCloseを v2 API へ追従refreshToolboxSelection_()→refreshToolboxSelection()toolbox_.scrollToCategoryById(id)→getToolbox().scrollToCategory(id)containers/custom-procedures.jsx: モーダルのScratchBlocks.inject(...)にtheme+scratchThemeを渡し、procedures_declarationブロックをカテゴリ色 (ピンク) で描画。mapStateToPropsからcolorMode/useCatBlocksを取得。webpack.config.js:blockly/media/もstatic/blocks-media/にコピー。v2 が require するdisconnect.mp3の 404 を解消。(2) 拡張機能追加後にフライアウトが新カテゴリへスクロールしない
containers/blocks.jsx:handleExtensionAddedで_pendingScrollToCategoryIdを立てる。updateToolboxの末尾 (toolbox 再構築完了後) で、toolboxItemDef_.id一致でカテゴリを引き、toolbox.selectCategoryByName(name)+flyout.scrollToCategory(item)を実行。<category id="${extensionId}" ...>を出すが、Blockly v12 はidを DOM id として扱うため、toolboxItem 自身の id はblockly-XXXに変わる。toolboxItemDef_.idには元の値が残る。(3) smalrubyRuby 拡張ブロックがドラッグできない
extensions/smalruby_ruby/translations.json: 抜けていたsmalrubyRuby.hashMethodWithBlockの ja / ja-Hira 翻訳を追加。lib/define-dynamic-block.js:mutationToDom/domToMutation: 根本原因はdocument.createElement('mutation')がHTMLUnknownElementを返し、属性名が小文字化されてしまうこと。Blockly v2 はフライアウトからのドラッグ時に JSON シリアライズ (extraStateに XML テキストを格納) でラウンドトリップするため、camelCase のblockInfoがシリアライズ後blockinfoになり、getAttribute('blockInfo')がnullを返してdomToMutationが早期 return → METHOD フィールド / RECEIVER 入力未生成 → "Ignoring non-existant field METHOD" / "missing RECEIVER connection" となっていた。ScratchBlocks.utils.xml.createElement(XML namespace) を使い、属性名を lowercaseblockinfoに統一。getAttribute('blockinfo') || getAttribute('blockInfo')) で受ける。Test plan
npm exec eslint(3 ファイル): エラー 0 / 警告 0npm exec jest test/unit/util/define-dynamic-block.test.js: 7 / 7 passednpm exec jest test/unit/lib/{ruby-to-blocks-converter,ruby-generator}/smalruby-ruby.test.js: 35 / 35 passednpm run build:dev: 成功 (disconnect.mp3がコピーされていることを確認)smalrubyRuby_stringMethodをワークスペースに配置: RECEIVER ('hello' shadow) と METHOD ('reverse' dropdown) が保持され、コンソールエラーなし