Skip to content

fix(scratch-blocks-v2): resolve post-upstream-merge regressions#653

Merged
takaokouji merged 3 commits into
developfrom
fix/scratch-blocks-v2-post-merge-bugs
May 7, 2026
Merged

fix(scratch-blocks-v2): resolve post-upstream-merge regressions#653
takaokouji merged 3 commits into
developfrom
fix/scratch-blocks-v2-post-merge-bugs

Conversation

@takaokouji
Copy link
Copy Markdown

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) を実行。
    • 注: 拡張カテゴリ XML は <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) を使い、属性名を lowercase blockinfo に統一。
    • 読み取り側は両ケースを fallback (getAttribute('blockinfo') || getAttribute('blockInfo')) で受ける。

Test plan

  • npm exec eslint (3 ファイル): エラー 0 / 警告 0
  • npm exec jest test/unit/util/define-dynamic-block.test.js: 7 / 7 passed
  • npm exec jest test/unit/lib/{ruby-to-blocks-converter,ruby-generator}/smalruby-ruby.test.js: 35 / 35 passed
  • npm run build:dev: 成功 (disconnect.mp3 がコピーされていることを確認)
  • Playwright で実機確認:
    • (1) ブロックを作るモーダル: ブロックが正しい色 (ピンク) で描画、OK で閉じてもエラーなし、定義ブロックがワークスペースに追加される
    • (2) ルビー拡張機能を追加した瞬間、フライアウトが ルビー カテゴリにスクロールしブロックが見える
    • (3) smalrubyRuby_stringMethod をワークスペースに配置: RECEIVER ('hello' shadow) と METHOD ('reverse' dropdown) が保持され、コンソールエラーなし
  • CI all green

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

github-actions Bot commented May 7, 2026

takaokouji added 2 commits May 7, 2026 17:08
…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.
@takaokouji takaokouji merged commit 1e4fa4c into develop May 7, 2026
9 checks passed
@takaokouji takaokouji deleted the fix/scratch-blocks-v2-post-merge-bugs branch May 7, 2026 08:20
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
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.

1 participant