From 118cd456107a4770af1781cf9d7c5908060ddc18 Mon Sep 17 00:00:00 2001 From: chrisgarrity Date: Tue, 17 Jul 2018 18:37:19 -0400 Subject: [PATCH 1/3] Only update blocks locale when blocks are visible In `blocks.jsx` only call setLocale if visible. Depends on `getLocale` being added to VM to know when global locale changed while not visible making the VM out of sync. --- src/containers/blocks.jsx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/containers/blocks.jsx b/src/containers/blocks.jsx index 1de665e33..6ac3c7d31 100644 --- a/src/containers/blocks.jsx +++ b/src/containers/blocks.jsx @@ -94,7 +94,9 @@ class Blocks extends React.Component { addFunctionListener(this.workspace, 'zoom', this.onWorkspaceMetricsChange); this.attachVM(); - this.setLocale(); + if (this.props.isVisible) { + this.setLocale(); + } analytics.pageview('/editors/blocks'); } @@ -117,9 +119,9 @@ class Blocks extends React.Component { this.ScratchBlocks.hideChaff(); } - if (prevProps.locale !== this.props.locale) { - this.setLocale(); - } + // if (prevProps.locale !== this.props.locale) { + // this.setLocale(); + // } if (prevProps.toolboxXML !== this.props.toolboxXML) { // rather than update the toolbox "sync" -- update it in the next frame @@ -138,10 +140,17 @@ class Blocks extends React.Component { // @todo hack to resize blockly manually in case resize happened while hidden // @todo hack to reload the workspace due to gui bug #413 if (this.props.isVisible) { // Scripts tab + this.workspace.setVisible(true); - this.props.vm.refreshWorkspace(); + if (prevProps.locale !== this.props.locale || this.props.locale !== this.props.vm.getLocale()) { + this.setLocale(); + } else { + this.props.vm.refreshWorkspace(); + } + // Re-enable toolbox refreshes without causing one. See #updateToolbox for more info. this.workspace.toolboxRefreshEnabled_ = true; + // this.workspace.setToolboxRefreshEnabled(true); window.dispatchEvent(new Event('resize')); } else { this.workspace.setVisible(false); From 446acfbe3198cfeaa30274205e6a2f00cfbb583e Mon Sep 17 00:00:00 2001 From: chrisgarrity Date: Wed, 18 Jul 2018 11:46:00 -0400 Subject: [PATCH 2/3] Update VM use VM that includes `getLocale()` --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6f3f5d81a..515cfd285 100644 --- a/package.json +++ b/package.json @@ -102,7 +102,7 @@ "scratch-render": "0.1.0-prerelease.20180618173030", "scratch-storage": "0.5.1", "scratch-svg-renderer": "0.2.0-prerelease.20180712223402", - "scratch-vm": "0.1.0-prerelease.1531502959", + "scratch-vm": "0.1.0-prerelease.1531927323", "selenium-webdriver": "3.6.0", "startaudiocontext": "1.2.1", "style-loader": "^0.21.0", From 483237767deba97dc35b122c54522d8e73019d9a Mon Sep 17 00:00:00 2001 From: chrisgarrity Date: Wed, 18 Jul 2018 13:35:53 -0400 Subject: [PATCH 3/3] cleanup Remove cruft and add comments to explain how setLocale is called. --- src/containers/blocks.jsx | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/containers/blocks.jsx b/src/containers/blocks.jsx index 6ac3c7d31..c0cb44d2b 100644 --- a/src/containers/blocks.jsx +++ b/src/containers/blocks.jsx @@ -94,6 +94,8 @@ class Blocks extends React.Component { addFunctionListener(this.workspace, 'zoom', this.onWorkspaceMetricsChange); this.attachVM(); + // Only update blocks/vm locale when visible to avoid sizing issues + // If locale changes while not visible it will get handled in didUpdate if (this.props.isVisible) { this.setLocale(); } @@ -119,10 +121,6 @@ class Blocks extends React.Component { this.ScratchBlocks.hideChaff(); } - // if (prevProps.locale !== this.props.locale) { - // this.setLocale(); - // } - if (prevProps.toolboxXML !== this.props.toolboxXML) { // rather than update the toolbox "sync" -- update it in the next frame clearTimeout(this.toolboxUpdateTimeout); @@ -140,9 +138,10 @@ class Blocks extends React.Component { // @todo hack to resize blockly manually in case resize happened while hidden // @todo hack to reload the workspace due to gui bug #413 if (this.props.isVisible) { // Scripts tab - this.workspace.setVisible(true); if (prevProps.locale !== this.props.locale || this.props.locale !== this.props.vm.getLocale()) { + // call setLocale if the locale has changed, or changed while the blocks were hidden. + // vm.getLocale() will be out of sync if locale was changed while not visible this.setLocale(); } else { this.props.vm.refreshWorkspace(); @@ -150,7 +149,6 @@ class Blocks extends React.Component { // Re-enable toolbox refreshes without causing one. See #updateToolbox for more info. this.workspace.toolboxRefreshEnabled_ = true; - // this.workspace.setToolboxRefreshEnabled(true); window.dispatchEvent(new Event('resize')); } else { this.workspace.setVisible(false);