@@ -4,7 +4,6 @@ import { alignElement, alignPoint } from 'dom-align';
44import addEventListener from '../vc-util/Dom/addEventListener' ;
55import { isWindow , buffer , isSamePoint , restoreFocus , monitorResize } from './util' ;
66import { cloneElement } from '../_util/vnode' ;
7- import clonedeep from 'lodash-es/cloneDeep' ;
87import { getSlot , findDOMNode } from '../_util/props-util' ;
98import useBuffer from './hooks/useBuffer' ;
109import isVisible from '../vc-util/Dom/isVisible' ;
@@ -28,10 +27,15 @@ export default defineComponent({
2827 monitorWindowResize : PropTypes . looseBool . def ( false ) ,
2928 disabled : PropTypes . looseBool . def ( false ) ,
3029 } ,
30+ setup ( ) {
31+ return {
32+ aligned : false ,
33+ sourceResizeMonitor : { cancel : ( ) => { } } ,
34+ resizeMonitor : { cancel : ( ) => { } } ,
35+ cacheInfo : { } ,
36+ } ;
37+ } ,
3138 data ( ) {
32- this . aligned = false ;
33- this . sourceResizeMonitor = { cancel : ( ) => { } } ;
34- this . resizeMonitor = { cancel : ( ) => { } } ;
3539 this . prevProps = { ...this . $props } ;
3640 const [ forceAlign , cancelForceAlign ] = useBuffer ( this . goAlign , 0 ) ;
3741 return {
@@ -48,6 +52,7 @@ export default defineComponent({
4852 this . startMonitorWindowResize ( ) ;
4953 }
5054 this . startMonitorElementResize ( ) ;
55+ this . updateCache ( ) ;
5156 } ) ;
5257 } ,
5358 updated ( ) {
@@ -59,9 +64,8 @@ export default defineComponent({
5964 if ( prevProps . disabled ) {
6065 reAlign = true ;
6166 } else {
62- const lastElement = getElement ( prevProps . target ) ;
67+ const { element : lastElement , point : lastPoint } = this . cacheInfo ;
6368 const currentElement = getElement ( props . target ) ;
64- const lastPoint = getPoint ( prevProps . target ) ;
6569 const currentPoint = getPoint ( props . target ) ;
6670 if ( isWindow ( lastElement ) && isWindow ( currentElement ) ) {
6771 // Skip if is window
@@ -86,7 +90,8 @@ export default defineComponent({
8690 } else {
8791 this . stopMonitorWindowResize ( ) ;
8892 }
89- this . prevProps = { ...this . $props , align : clonedeep ( this . $props . align ) } ;
93+ this . prevProps = { ...this . $props } ;
94+ this . updateCache ( ) ;
9095 } ) ;
9196 } ,
9297 beforeUnmount ( ) {
@@ -96,12 +101,18 @@ export default defineComponent({
96101 this . cancelForceAlign ( ) ;
97102 } ,
98103 methods : {
104+ updateCache ( ) {
105+ const element = getElement ( this . $props . target ) ;
106+ const point = getPoint ( this . $props . target ) ;
107+ this . cacheInfo = {
108+ element,
109+ point,
110+ } ;
111+ } ,
99112 startMonitorElementResize ( ) {
100- const prevProps = this . prevProps ;
101113 const props = this . $props ;
102- const lastElement = getElement ( prevProps . target ) ;
114+ const { element : lastElement , point : lastPoint } = this . cacheInfo ;
103115 const currentElement = getElement ( props . target ) ;
104- const lastPoint = getPoint ( prevProps . target ) ;
105116 const currentPoint = getPoint ( props . target ) ;
106117 const source = findDOMNode ( this ) ;
107118 const { sourceResizeMonitor, resizeMonitor } = this ;
@@ -111,7 +122,7 @@ export default defineComponent({
111122 sourceResizeMonitor . cancel = monitorResize ( source , this . forceAlign ) ;
112123 }
113124 if ( lastElement !== currentElement || ! isSamePoint ( lastPoint , currentPoint ) ) {
114- // this.forceAlign();
125+ this . forceAlign ( ) ;
115126 // Add resize observer
116127 if ( resizeMonitor . element !== currentElement ) {
117128 resizeMonitor ?. cancel ( ) ;
0 commit comments