From 73be0c6eb3d1f31528822e4d055d64d86f5967ad Mon Sep 17 00:00:00 2001 From: Feynman Date: Thu, 12 Dec 2024 11:32:06 +0800 Subject: [PATCH] refactor: Patch ElementUI tooltip memory leak --- package.json | 3 ++ patches/element-ui@2.15.7.patch | 67 +++++++++++++++++++++++++++++++++ pnpm-lock.yaml | 18 ++++++--- 3 files changed, 82 insertions(+), 6 deletions(-) create mode 100644 patches/element-ui@2.15.7.patch diff --git a/package.json b/package.json index 6793a4775..2fa8d2fb4 100644 --- a/package.json +++ b/package.json @@ -56,6 +56,9 @@ "vue-demi": "^0.12.1", "vue": "~2.6.14", "vue-template-compiler": "~2.6.11" + }, + "patchedDependencies": { + "element-ui@2.15.7": "patches/element-ui@2.15.7.patch" } } } diff --git a/patches/element-ui@2.15.7.patch b/patches/element-ui@2.15.7.patch new file mode 100644 index 000000000..88a666645 --- /dev/null +++ b/patches/element-ui@2.15.7.patch @@ -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(); + }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9918dcd9c..2a6b33a9c 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,6 +18,11 @@ overrides: vue: ~2.6.14 vue-template-compiler: ~2.6.11 +patchedDependencies: + element-ui@2.15.7: + hash: m2ri3yhfvvdlrnxhvab323lvje + path: patches/element-ui@2.15.7.patch + importers: .: @@ -27,7 +32,7 @@ importers: version: 1.7.2(vue@2.6.14) element-ui: specifier: 2.15.7 - version: 2.15.7(vue@2.6.14) + version: 2.15.7(patch_hash=m2ri3yhfvvdlrnxhvab323lvje)(vue@2.6.14) lodash: specifier: ^4.17.15 version: 4.17.21 @@ -151,7 +156,7 @@ importers: version: 2.0.14(element-ui@2.15.7)(vue@2.6.14) element-ui: specifier: 2.15.7 - version: 2.15.7(vue@2.6.14) + version: 2.15.7(patch_hash=m2ri3yhfvvdlrnxhvab323lvje)(vue@2.6.14) github-markdown-css: specifier: ^4.0.0 version: 4.0.0 @@ -362,7 +367,7 @@ importers: version: 5.5.0 element-ui: specifier: 2.15.7 - version: 2.15.7(vue@2.6.14) + version: 2.15.7(patch_hash=m2ri3yhfvvdlrnxhvab323lvje)(vue@2.6.14) github-markdown-css: specifier: ^4.0.0 version: 4.0.0 @@ -2187,7 +2192,7 @@ packages: '@formily/shared': 2.2.13 '@formily/vue': 2.2.13(@vue/composition-api@1.7.2)(typescript@4.5.5)(vue@2.6.14) '@vue/composition-api': 1.7.2(vue@2.6.14) - element-ui: 2.15.7(vue@2.6.14) + element-ui: 2.15.7(patch_hash=m2ri3yhfvvdlrnxhvab323lvje)(vue@2.6.14) portal-vue: 2.1.7(vue@2.6.14) vue: 2.6.14 vue-demi: 0.12.5(@vue/composition-api@1.7.2)(vue@2.6.14) @@ -5905,7 +5910,7 @@ packages: vue: ~2.6.14 dependencies: core-js: 3.37.1 - element-ui: 2.15.7(vue@2.6.14) + element-ui: 2.15.7(patch_hash=m2ri3yhfvvdlrnxhvab323lvje)(vue@2.6.14) style-inject: 0.3.0 vue: 2.6.14 vue-class-component: 7.2.6(vue@2.6.14) @@ -5922,7 +5927,7 @@ packages: engines: {node: '>=0.10.0'} dev: true - /element-ui@2.15.7(vue@2.6.14): + /element-ui@2.15.7(patch_hash=m2ri3yhfvvdlrnxhvab323lvje)(vue@2.6.14): resolution: {integrity: sha512-+J6rnXajxzLwV6w8Q6bf7Yqzk1FO1ewbIrCy/4B5alnd7tj8WEpfQoAvISirVaUGVGy77d9Ji3o2bF4f0AsJLQ==} peerDependencies: vue: ~2.6.14 @@ -5935,6 +5940,7 @@ packages: throttle-debounce: 1.1.0 vue: 2.6.14 dev: false + patched: true /elliptic@6.5.5: resolution: {integrity: sha512-7EjbcmUm17NQFu4Pmgmq2olYMj8nwMnpcddByChSUjArp8F5DQWcIcpriwO4ZToLNAJig0yiyjswfyGNje/ixw==}