From f037135f5e51559e766ee471f4888807a257a1fd Mon Sep 17 00:00:00 2001 From: Dan Smilkov Date: Tue, 26 Apr 2016 12:33:16 -0800 Subject: [PATCH] Fix flaky test failure in firefox where asking for bounding box of an svg element that has been detached from the dom produces NS_ERROR_FAILURE Change: 120846455 --- .../tf-graph-common/lib/scene/minimap.ts | 15 +++++++++++---- .../components/tf-graph-common/lib/scene/scene.ts | 13 ++++++++++--- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/tensorflow/tensorboard/components/tf-graph-common/lib/scene/minimap.ts b/tensorflow/tensorboard/components/tf-graph-common/lib/scene/minimap.ts index db6fcfee5700cc..40030122de14ab 100644 --- a/tensorflow/tensorboard/components/tf-graph-common/lib/scene/minimap.ts +++ b/tensorflow/tensorboard/components/tf-graph-common/lib/scene/minimap.ts @@ -138,8 +138,17 @@ export class Minimap { * was updated (e.g. when a node was expanded). */ update(): void { - // The origin hasn't rendered yet. Ignore making an update. - if (this.zoomG == null || this.zoomG.childElementCount === 0) { + let sceneSize = null; + try { + // Get the size of the entire scene. + sceneSize = this.zoomG.getBBox(); + if (sceneSize.width === 0) { + // There is no scene anymore. We have been detached from the dom. + return; + } + } catch (e) { + // Firefox produced NS_ERROR_FAILURE if we have been + // detached from the dom. return; } let $download = d3.select('#graphdownload'); @@ -182,8 +191,6 @@ export class Minimap { let zoomTransform = $zoomG.attr('transform'); $zoomG.attr('transform', null); - // Get the size of the entire scene. - let sceneSize = this.zoomG.getBBox(); // Since we add padding, account for that here. sceneSize.height += this.labelPadding * 2; sceneSize.width += this.labelPadding * 2; diff --git a/tensorflow/tensorboard/components/tf-graph-common/lib/scene/scene.ts b/tensorflow/tensorboard/components/tf-graph-common/lib/scene/scene.ts index d5c63f89ce2b10..0451fb308d1c30 100644 --- a/tensorflow/tensorboard/components/tf-graph-common/lib/scene/scene.ts +++ b/tensorflow/tensorboard/components/tf-graph-common/lib/scene/scene.ts @@ -78,9 +78,16 @@ export let Class = { */ export function fit(svg, zoomG, d3zoom, callback) { let svgRect = svg.getBoundingClientRect(); - let sceneSize = zoomG.getBBox(); - if (sceneSize.width === 0) { - // There is no scene anymore. + let sceneSize = null; + try { + sceneSize = zoomG.getBBox(); + if (sceneSize.width === 0) { + // There is no scene anymore. We have been detached from the dom. + return; + } + } catch (e) { + // Firefox produced NS_ERROR_FAILURE if we have been + // detached from the dom. return; } let scale = 0.9 * Math.min(