@@ -4,7 +4,6 @@ import { alignElement, alignPoint } from 'dom-align';
4
4
import addEventListener from '../vc-util/Dom/addEventListener' ;
5
5
import { isWindow , buffer , isSamePoint , restoreFocus , monitorResize } from './util' ;
6
6
import { cloneElement } from '../_util/vnode' ;
7
- import clonedeep from 'lodash-es/cloneDeep' ;
8
7
import { getSlot , findDOMNode } from '../_util/props-util' ;
9
8
import useBuffer from './hooks/useBuffer' ;
10
9
import isVisible from '../vc-util/Dom/isVisible' ;
@@ -28,10 +27,15 @@ export default defineComponent({
28
27
monitorWindowResize : PropTypes . looseBool . def ( false ) ,
29
28
disabled : PropTypes . looseBool . def ( false ) ,
30
29
} ,
30
+ setup ( ) {
31
+ return {
32
+ aligned : false ,
33
+ sourceResizeMonitor : { cancel : ( ) => { } } ,
34
+ resizeMonitor : { cancel : ( ) => { } } ,
35
+ cacheInfo : { } ,
36
+ } ;
37
+ } ,
31
38
data ( ) {
32
- this . aligned = false ;
33
- this . sourceResizeMonitor = { cancel : ( ) => { } } ;
34
- this . resizeMonitor = { cancel : ( ) => { } } ;
35
39
this . prevProps = { ...this . $props } ;
36
40
const [ forceAlign , cancelForceAlign ] = useBuffer ( this . goAlign , 0 ) ;
37
41
return {
@@ -48,6 +52,7 @@ export default defineComponent({
48
52
this . startMonitorWindowResize ( ) ;
49
53
}
50
54
this . startMonitorElementResize ( ) ;
55
+ this . updateCache ( ) ;
51
56
} ) ;
52
57
} ,
53
58
updated ( ) {
@@ -59,9 +64,8 @@ export default defineComponent({
59
64
if ( prevProps . disabled ) {
60
65
reAlign = true ;
61
66
} else {
62
- const lastElement = getElement ( prevProps . target ) ;
67
+ const { element : lastElement , point : lastPoint } = this . cacheInfo ;
63
68
const currentElement = getElement ( props . target ) ;
64
- const lastPoint = getPoint ( prevProps . target ) ;
65
69
const currentPoint = getPoint ( props . target ) ;
66
70
if ( isWindow ( lastElement ) && isWindow ( currentElement ) ) {
67
71
// Skip if is window
@@ -86,7 +90,8 @@ export default defineComponent({
86
90
} else {
87
91
this . stopMonitorWindowResize ( ) ;
88
92
}
89
- this . prevProps = { ...this . $props , align : clonedeep ( this . $props . align ) } ;
93
+ this . prevProps = { ...this . $props } ;
94
+ this . updateCache ( ) ;
90
95
} ) ;
91
96
} ,
92
97
beforeUnmount ( ) {
@@ -96,12 +101,18 @@ export default defineComponent({
96
101
this . cancelForceAlign ( ) ;
97
102
} ,
98
103
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
+ } ,
99
112
startMonitorElementResize ( ) {
100
- const prevProps = this . prevProps ;
101
113
const props = this . $props ;
102
- const lastElement = getElement ( prevProps . target ) ;
114
+ const { element : lastElement , point : lastPoint } = this . cacheInfo ;
103
115
const currentElement = getElement ( props . target ) ;
104
- const lastPoint = getPoint ( prevProps . target ) ;
105
116
const currentPoint = getPoint ( props . target ) ;
106
117
const source = findDOMNode ( this ) ;
107
118
const { sourceResizeMonitor, resizeMonitor } = this ;
@@ -111,7 +122,7 @@ export default defineComponent({
111
122
sourceResizeMonitor . cancel = monitorResize ( source , this . forceAlign ) ;
112
123
}
113
124
if ( lastElement !== currentElement || ! isSamePoint ( lastPoint , currentPoint ) ) {
114
- // this.forceAlign();
125
+ this . forceAlign ( ) ;
115
126
// Add resize observer
116
127
if ( resizeMonitor . element !== currentElement ) {
117
128
resizeMonitor ?. cancel ( ) ;
0 commit comments