From e909afc93a328e91637082f07fd75f724adead33 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Sat, 17 Dec 2016 21:01:41 -0500 Subject: [PATCH 1/2] Due to jQuery propagating events, the window resize event could be triggered by a bubbled event. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See https://bugs.jquery.com/ticket/9841. In our case, the OutputArea was triggering a ‘resize’ event on its element, which was bubbling up and causing this handler to execute every time an output was appended. This was a pretty big drain on output areas that quickly changed (like for interact widgets), presumably since this function involves a DOM read to get heights. --- notebook/static/base/js/page.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/notebook/static/base/js/page.js b/notebook/static/base/js/page.js index bb522dcfe..fc7d4f137 100644 --- a/notebook/static/base/js/page.js +++ b/notebook/static/base/js/page.js @@ -52,9 +52,13 @@ define([ this._resize_site(); }; - Page.prototype._resize_site = function() { + Page.prototype._resize_site = function(e) { // Update the site's size. - $('div#site').height($(window).height() - $('#header').height()); + // only trigger if the event actually is the window's, not bubbling up. + // See https://bugs.jquery.com/ticket/9841#comment:8 + if (!e.target.tagName) { + $('div#site').height($(window).height() - $('#header').height()); + } }; return {'Page': Page}; From 935af4358281c380a2bbc903f93a5e0725cae420 Mon Sep 17 00:00:00 2001 From: Jason Grout Date: Mon, 19 Dec 2016 09:15:31 -0500 Subject: [PATCH 2/2] handle window sizing even when it is not from a resize event. --- notebook/static/base/js/page.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/notebook/static/base/js/page.js b/notebook/static/base/js/page.js index fc7d4f137..771ae38fa 100644 --- a/notebook/static/base/js/page.js +++ b/notebook/static/base/js/page.js @@ -52,11 +52,17 @@ define([ this._resize_site(); }; + + Page.prototype._resize_site = function(e) { - // Update the site's size. - // only trigger if the event actually is the window's, not bubbling up. - // See https://bugs.jquery.com/ticket/9841#comment:8 - if (!e.target.tagName) { + /** + * Update the site's size. + */ + + // In the case an event is passed in, only trigger if the event does + // *not* have a target DOM node (i.e., it is not bubbling up). See + // https://bugs.jquery.com/ticket/9841#comment:8 + if (!(e && e.target && e.target.tagName)) { $('div#site').height($(window).height() - $('#header').height()); } };