From c5aef9b4b2ce78e1703cfd3e6ed47cd62a7015ea Mon Sep 17 00:00:00 2001 From: Josep Sanz Date: Sat, 9 Oct 2021 00:24:45 +0200 Subject: [PATCH 1/7] Widget & Tooltip: Regression from 1.12.1 The 1.13.0 release remove the try-catch that prevents spurious errors Fixes: 1f2011e Closes: jquerygh-1990 --- ui/widget.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/ui/widget.js b/ui/widget.js index 3b149f11ada..6c88d8ec23d 100644 --- a/ui/widget.js +++ b/ui/widget.js @@ -36,12 +36,16 @@ $.cleanData = ( function( orig ) { return function( elems ) { var events, elem, i; for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) { + try { - // Only trigger remove when necessary to save time - events = $._data( elem, "events" ); - if ( events && events.remove ) { - $( elem ).triggerHandler( "remove" ); - } + // Only trigger remove when necessary to save time + events = $._data( elem, "events" ); + if ( events && events.remove ) { + $( elem ).triggerHandler( "remove" ); + } + + // Http://bugs.jquery.com/ticket/8235 + } catch ( e ) {} } orig( elems ); }; From 1a9947fdfc108cca7a18e7be54bd0c3d1900df60 Mon Sep 17 00:00:00 2001 From: Josep Sanz Date: Tue, 12 Oct 2021 09:39:33 +0200 Subject: [PATCH 2/7] Widget & Tooltip: Regression from 1.12.1 Removed the previous sanctioning crashing code in favor to control the real problem inside the tooltip widget, thanks to the @mgol clarification. Fixes: c5aef9b Closes: jquerygh-1990 --- ui/widget.js | 14 +++++--------- ui/widgets/tooltip.js | 5 ++++- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ui/widget.js b/ui/widget.js index 6c88d8ec23d..3b149f11ada 100644 --- a/ui/widget.js +++ b/ui/widget.js @@ -36,16 +36,12 @@ $.cleanData = ( function( orig ) { return function( elems ) { var events, elem, i; for ( i = 0; ( elem = elems[ i ] ) != null; i++ ) { - try { - // Only trigger remove when necessary to save time - events = $._data( elem, "events" ); - if ( events && events.remove ) { - $( elem ).triggerHandler( "remove" ); - } - - // Http://bugs.jquery.com/ticket/8235 - } catch ( e ) {} + // Only trigger remove when necessary to save time + events = $._data( elem, "events" ); + if ( events && events.remove ) { + $( elem ).triggerHandler( "remove" ); + } } orig( elems ); }; diff --git a/ui/widgets/tooltip.js b/ui/widgets/tooltip.js index f1cea47d1c0..27a8f9a9590 100644 --- a/ui/widgets/tooltip.js +++ b/ui/widgets/tooltip.js @@ -352,7 +352,10 @@ $.widget( "ui.tooltip", { // tooltips will handle this in destroy. if ( target[ 0 ] !== this.element[ 0 ] ) { events.remove = function() { - this._removeTooltip( this._find( target ).tooltip ); + var theTarget = this._find( target ); + if ( theTarget !== null ) { + this._removeTooltip( theTarget.tooltip ); + } }; } From dea398bf1d4ffea9d5ba87d7fbd393271d58c17a Mon Sep 17 00:00:00 2001 From: Josep Sanz Date: Tue, 12 Oct 2021 19:00:25 +0200 Subject: [PATCH 3/7] Update ui/widgets/tooltip.js Co-authored-by: Claas Augner --- ui/widgets/tooltip.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ui/widgets/tooltip.js b/ui/widgets/tooltip.js index 27a8f9a9590..fba70cd1b2f 100644 --- a/ui/widgets/tooltip.js +++ b/ui/widgets/tooltip.js @@ -352,9 +352,9 @@ $.widget( "ui.tooltip", { // tooltips will handle this in destroy. if ( target[ 0 ] !== this.element[ 0 ] ) { events.remove = function() { - var theTarget = this._find( target ); - if ( theTarget !== null ) { - this._removeTooltip( theTarget.tooltip ); + var targetElement = this._find( target ); + if ( targetElement !== null ) { + this._removeTooltip( targetElement.tooltip ); } }; } From 8a079751b82e6991f3fa51ccca3c359ee733025f Mon Sep 17 00:00:00 2001 From: Josep Sanz Date: Fri, 15 Oct 2021 08:07:31 +0200 Subject: [PATCH 4/7] Update ui/widgets/tooltip.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Michał Gołębiowski-Owczarek --- ui/widgets/tooltip.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/widgets/tooltip.js b/ui/widgets/tooltip.js index fba70cd1b2f..06282338afb 100644 --- a/ui/widgets/tooltip.js +++ b/ui/widgets/tooltip.js @@ -353,7 +353,7 @@ $.widget( "ui.tooltip", { if ( target[ 0 ] !== this.element[ 0 ] ) { events.remove = function() { var targetElement = this._find( target ); - if ( targetElement !== null ) { + if ( targetElement ) { this._removeTooltip( targetElement.tooltip ); } }; From f8f320a50d403a9766d61893c08da0ed12d5cda2 Mon Sep 17 00:00:00 2001 From: Josep Sanz Date: Sat, 30 Oct 2021 19:33:00 +0200 Subject: [PATCH 5/7] Widget & Tooltip: Regression from 1.12.1 Add a unit test for the #1990 and the PR#1994 --- tests/unit/tooltip/core.js | 70 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/tests/unit/tooltip/core.js b/tests/unit/tooltip/core.js index 5ce49aeb7f6..a9e7e34c0b8 100644 --- a/tests/unit/tooltip/core.js +++ b/tests/unit/tooltip/core.js @@ -254,4 +254,74 @@ QUnit.test( "remove conflicting attributes from live region", function( assert ) .tooltip( "open" ); } ); +// #1990 +QUnit.test( "widget and tooltip regression from 1.12.1", function( assert ) { + var ready = assert.async(); + assert.expect( 1 ); + + var anchor = $( "#tooltipped1" ), + input = anchor.next(), + actions = []; + + $( document ).tooltip( { + show: false, + hide: false, + content: function() { + var title = $( this ).attr( "title" ); + if ( title === "inputtitle" ) { + return ""; + } + return title; + }, + open: function( event, ui ) { + actions.push( "open:" + ui.tooltip.text() ); + }, + close: function( event, ui ) { + actions.push( "close:" + ui.tooltip.text() ); + } + } ); + + function step1() { + anchor.simulate( "mouseover" ); + setTimeout( step2 ); + } + + function step2() { + anchor.simulate( "mouseout" ); + setTimeout( step3 ); + } + + function step3() { + input.simulate( "focus" ); + setTimeout( step4 ); + } + + function step4() { + input.simulate( "blur" ); + setTimeout( step5 ); + } + + function step5() { + anchor.simulate( "mouseover" ); + setTimeout( step6 ); + } + + function step6() { + anchor.simulate( "mouseout" ); + setTimeout( step7 ); + } + + function step7() { + assert.deepEqual( actions, [ + "open:anchortitle", + "close:anchortitle", + "open:anchortitle", + "close:anchortitle" + ], "The tooltip open and close" ); + ready(); + } + + step1(); +} ); + } ); From b6150dc064914102a5b00debe8112623d5b2fcaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Sun, 7 Nov 2021 13:12:50 +0100 Subject: [PATCH 6/7] Tooltip: Fix a reference to a GitHub issue --- tests/unit/tooltip/core.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/tooltip/core.js b/tests/unit/tooltip/core.js index a9e7e34c0b8..398dd64953a 100644 --- a/tests/unit/tooltip/core.js +++ b/tests/unit/tooltip/core.js @@ -254,7 +254,7 @@ QUnit.test( "remove conflicting attributes from live region", function( assert ) .tooltip( "open" ); } ); -// #1990 +// gh-1990 QUnit.test( "widget and tooltip regression from 1.12.1", function( assert ) { var ready = assert.async(); assert.expect( 1 ); From d29cb28387e969f0a04c4ddd8bc5d7bb5039b4c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Go=C5=82=C4=99biowski-Owczarek?= Date: Mon, 8 Nov 2021 11:50:22 +0100 Subject: [PATCH 7/7] Apply suggestions from code review --- tests/unit/tooltip/core.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/tooltip/core.js b/tests/unit/tooltip/core.js index 398dd64953a..a3eedbd6af0 100644 --- a/tests/unit/tooltip/core.js +++ b/tests/unit/tooltip/core.js @@ -255,7 +255,7 @@ QUnit.test( "remove conflicting attributes from live region", function( assert ) } ); // gh-1990 -QUnit.test( "widget and tooltip regression from 1.12.1", function( assert ) { +QUnit.test( "don't crash on empty tooltip content", function( assert ) { var ready = assert.async(); assert.expect( 1 ); @@ -317,7 +317,7 @@ QUnit.test( "widget and tooltip regression from 1.12.1", function( assert ) { "close:anchortitle", "open:anchortitle", "close:anchortitle" - ], "The tooltip open and close" ); + ], "Tooltip opens and closes without crashing" ); ready(); }