jenkins-bot has submitted this change and it was merged.
Change subject: Element: DWIM when repeatedly infusing the same node
......................................................................
Element: DWIM when repeatedly infusing the same node
Infusing a node causes it to be removed from the DOM and replaced with
the infused widget's node. If anyone is holding a reference to it when
this happens, they're left with a useless unattached node, that can
confusingly be infused again, generating a new Widget every time,
similarly unattached and useless.
Let's do something smart and intuitive and return the original infused
widget when a previously-infused node is infused again. We already
have code to handle no-op OO.ui.infuse() on infused widgets' nodes,
so this is a one-line change.
Bug: T105828
Change-Id: I11fd1c7f2434f904b9ddc94b0903f8278e06f3a1
---
M src/Element.js
1 file changed, 8 insertions(+), 4 deletions(-)
Approvals:
Trevor Parscal: Looks good to me, approved
jenkins-bot: Verified
diff --git a/src/Element.js b/src/Element.js
index a70e359..62c5328 100644
--- a/src/Element.js
+++ b/src/Element.js
@@ -131,16 +131,16 @@
$elem = $( idOrNode );
id = $elem.attr( 'id' );
}
- data = $elem.data( 'ooui-infused' );
+ if ( !$elem.length ) {
+ throw new Error( 'Widget not found: ' + id );
+ }
+ data = $elem.data( 'ooui-infused' ) || $elem[0].oouiInfused;
if ( data ) {
// cached!
if ( data === true ) {
throw new Error( 'Circular dependency! ' + id );
}
return data;
- }
- if ( !$elem.length ) {
- throw new Error( 'Widget not found: ' + id );
}
data = $elem.attr( 'data-ooui' );
if ( !data ) {
@@ -208,6 +208,10 @@
// now replace old DOM with this new DOM.
if ( top ) {
$elem.replaceWith( obj.$element );
+ // This element is now gone from the DOM, but if anyone is
holding a reference to it,
+ // let's allow them to OO.ui.infuse() it and do what they
expect (T105828).
+ // Do not use jQuery.data(), as using it on detached nodes
leaks memory in 1.x line by design.
+ $elem[0].oouiInfused = obj;
top.resolve();
}
obj.$element.data( 'ooui-infused', obj );
--
To view, visit https://gerrit.wikimedia.org/r/229668
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: I11fd1c7f2434f904b9ddc94b0903f8278e06f3a1
Gerrit-PatchSet: 5
Gerrit-Project: oojs/ui
Gerrit-Branch: master
Gerrit-Owner: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Bartosz Dziewoński <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Trevor Parscal <[email protected]>
Gerrit-Reviewer: jenkins-bot <>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits