diff --git a/src/data_category.js b/src/data_category.js index 303300e929..7e104cf2ef 100644 --- a/src/data_category.js +++ b/src/data_category.js @@ -426,7 +426,16 @@ function addCreateButton(xmlList, workspace, type) { } button.setAttribute("text", msg); button.setAttribute("callbackKey", callbackKey); - workspace.registerButtonCallback(callbackKey, callback); + workspace.registerButtonCallback(callbackKey, (b) => { + // Run the callback after a delay to avoid it getting captured by the React + // modal in scratch-gui and being registered as a click on the scrim that + // dismisses the dialog. + requestAnimationFrame(() => { + setTimeout(() => { + callback(b); + }); + }); + }); xmlList.push(button); } diff --git a/src/procedures.js b/src/procedures.js index 1ce112e0a2..3f59f52318 100644 --- a/src/procedures.js +++ b/src/procedures.js @@ -105,7 +105,14 @@ function addCreateButton_(workspace, xmlList) { var msg = Blockly.Msg.NEW_PROCEDURE; var callbackKey = "CREATE_PROCEDURE"; var callback = function () { - createProcedureDefCallback(workspace); + // Run the callback after a delay to avoid it getting captured by the React + // modal in scratch-gui and being registered as a click on the scrim that + // dismisses the dialog. + requestAnimationFrame(() => { + setTimeout(() => { + createProcedureDefCallback(workspace); + }); + }); }; button.setAttribute("text", msg); button.setAttribute("callbackKey", callbackKey);