Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hiding blockly injection div can break blockly #5930

Closed
markfinn opened this issue Feb 11, 2022 · 3 comments
Closed

hiding blockly injection div can break blockly #5930

markfinn opened this issue Feb 11, 2022 · 3 comments
Labels
component: rendering issue: bug Describes why the code or behaviour is wrong

Comments

@markfinn
Copy link
Contributor

markfinn commented Feb 11, 2022

If the div containing the Blockly workspace is hidden and Blockly.svgResize is called you end up in a state where the svg is forced to zero size and it will never some back.

The cause is that during the hidden svgResize WorkspaceSvg.setCachedParentSvgSize fails to record the zero size as noted here #5404(907989018), but the SVG is still made 0x0. Later when the div is un-hidden svgResize doesn't see that the size is growing since the cached value is bad, so the SVG is not set back to a visible size.

A real case of this is using NGX-Blockly which implements a changable readonly input by having two workspaces with one being readonly. That workspace is hidden/un-hidden to transition in and out of read-only mode. If anything calls Blockly.svgResize while in read-write mode (in other words while the readonly workspace is in a hidden div) the readonly workspace becomes 0x0 and won't display again even when its div is un-hidden. The problem manifests because Blockly.svgResize gets called in this case if the window is resized due to code in both NGX-Blockly and my own application. In fact in my application it's worse because I also call Blockly.svgResize for several other reflow events, one of which happens ever time you go into read-write mode.

Fix:
The same as what seemed to be noticed in #5404(907989018): change the truthy tests of width and height in WorkspaceSvg.setCachedParentSvgSize to actual comparisons with null so that zero value can be saved into the cache.

 Blockly.WorkspaceSvg.prototype.setCachedParentSvgSize = function(width, height) {
   var svg = this.getParentSvg();
-  if (width) {
+  if (width != null) {
     this.cachedParentSvgSize_.width = width;
     // This is set to support the public (but deprecated) Blockly.svgSize method.
     svg.cachedWidth_ = width;
   }
-  if (height) {
+  if (height != null) {
     this.cachedParentSvgSize_.height = height;
     // This is set to support the public (but deprecated) Blockly.svgSize method.
     svg.cachedHeight_ = height;

I have verified that this does solve my problem, and looking around the rest of Blockly I don't see any places where WorkspaceSvg.setCachedParentSvgSize was intentionally not caching based on a non-truthy input other than null.

Note that if you use NGX-Blockly to see this then this fix alone is not enough, you also need to re-call Blockly.svgSize until a different issue is fixed over there.

@BeksOmega
Copy link
Collaborator

Hi @markfinn Given your explanation, that fix sounds great to me! Would you be willing to put up a PR for this? We always really appreciate getting downstream fixes :D

Otherwise, hopefully we can get to this in a future bug bash.

Either way, thank you so much for reporting this!

@BeksOmega BeksOmega added component: rendering issue: bug Describes why the code or behaviour is wrong and removed issue: triage Issues awaiting triage by a Blockly team member labels Feb 23, 2022
@BeksOmega BeksOmega added this to the Bug Bash Backlog milestone Feb 23, 2022
@markfinn
Copy link
Contributor Author

Took me a while to notice this conversation, but I've made a pull request. Thanks!

alschmiedt pushed a commit that referenced this issue Mar 15, 2022
…achedParentSvgSize to actual comparisons with null so that zero value can be saved into the cache (#5997)

fixes #5930 and possibly #5404
@BeksOmega
Copy link
Collaborator

Closed by #5997

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: rendering issue: bug Describes why the code or behaviour is wrong
Projects
None yet
Development

No branches or pull requests

2 participants