Skip to content

Commit

Permalink
refactor: Patch ElementUI tooltip memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
cn-xufei committed Dec 12, 2024
1 parent 9055905 commit 73be0c6
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 6 deletions.
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"vue-demi": "^0.12.1",
"vue": "~2.6.14",
"vue-template-compiler": "~2.6.11"
},
"patchedDependencies": {
"[email protected]": "patches/[email protected]"
}
}
}
67 changes: 67 additions & 0 deletions patches/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
diff --git a/lib/element-ui.common.js b/lib/element-ui.common.js
index 01026cd93f233f08c0f77c1eeffc43b7953ea75e..3f5486798f53c03f57fdfc15b9d8547d97c7fa09 100644
--- a/lib/element-ui.common.js
+++ b/lib/element-ui.common.js
@@ -21781,18 +21781,7 @@ main.directive = directive;
this.$el.setAttribute('tabindex', this.tabindex);
Object(dom_["on"])(this.referenceElm, 'mouseenter', this.show);
Object(dom_["on"])(this.referenceElm, 'mouseleave', this.hide);
- Object(dom_["on"])(this.referenceElm, 'focus', function () {
- if (!_this3.$slots.default || !_this3.$slots.default.length) {
- _this3.handleFocus();
- return;
- }
- var instance = _this3.$slots.default[0].componentInstance;
- if (instance && instance.focus) {
- instance.focus();
- } else {
- _this3.handleFocus();
- }
- });
+ Object(dom_["on"])(this.referenceElm, 'focus', this.handleFocus);
Object(dom_["on"])(this.referenceElm, 'blur', this.handleBlur);
Object(dom_["on"])(this.referenceElm, 'click', this.removeFocusing);
}
diff --git a/packages/tooltip/src/main.js b/packages/tooltip/src/main.js
index 6b700bba8f38691d738927e75423d9a902fe245e..57a3e640c05b19c205817e5d3608bb8623a51a1c 100644
--- a/packages/tooltip/src/main.js
+++ b/packages/tooltip/src/main.js
@@ -113,18 +113,7 @@ export default {
this.$el.setAttribute('tabindex', this.tabindex);
on(this.referenceElm, 'mouseenter', this.show);
on(this.referenceElm, 'mouseleave', this.hide);
- on(this.referenceElm, 'focus', () => {
- if (!this.$slots.default || !this.$slots.default.length) {
- this.handleFocus();
- return;
- }
- const instance = this.$slots.default[0].componentInstance;
- if (instance && instance.focus) {
- instance.focus();
- } else {
- this.handleFocus();
- }
- });
+ on(this.referenceElm, 'focus', this.handleFocus);
on(this.referenceElm, 'blur', this.handleBlur);
on(this.referenceElm, 'click', this.removeFocusing);
}
@@ -157,6 +146,18 @@ export default {
this.debounceClose();
},
handleFocus() {
+ if (!this.$slots.default || !this.$slots.default.length) {
+ this.doFocus();
+ return;
+ }
+ const instance = this.$slots.default[0].componentInstance;
+ if (instance && instance.focus) {
+ instance.focus();
+ } else {
+ this.doFocus();
+ }
+ },
+ doFocus() {
this.focusing = true;
this.show();
},
18 changes: 12 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 73be0c6

Please sign in to comment.