You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 svgResizeWorkspaceSvg.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.
The text was updated successfully, but these errors were encountered:
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.
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-hiddensvgResize
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 becauseBlockly.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 callBlockly.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.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.The text was updated successfully, but these errors were encountered: