@@ -48,7 +48,11 @@ function Overflow<ItemType = any>(
48
48
const [ itemWidths , setItemWidths ] = createUseState (
49
49
new Map < React . Key , number > ( ) ,
50
50
) ;
51
+
52
+ const [ prevRestWidth , setPrevRestWidth ] = createUseState ( 0 ) ;
51
53
const [ restWidth , setRestWidth ] = createUseState ( 0 ) ;
54
+ // Always use the max width to avoid blink
55
+ const mergedRestWidth = Math . max ( prevRestWidth , restWidth ) ;
52
56
53
57
const [ displayCount , setDisplayCount ] = React . useState ( 0 ) ;
54
58
const [ restReady , setRestReady ] = React . useState ( false ) ;
@@ -123,11 +127,12 @@ function Overflow<ItemType = any>(
123
127
124
128
function registerOverflowSize ( _ : React . Key , width : number ) {
125
129
setRestWidth ( width ) ;
130
+ setPrevRestWidth ( restWidth ) ;
126
131
}
127
132
128
133
// ================================ Effect ================================
129
134
React . useLayoutEffect ( ( ) => {
130
- if ( containerWidth && restWidth && mergedData ) {
135
+ if ( containerWidth && mergedRestWidth && mergedData ) {
131
136
let totalWidth = 0 ;
132
137
133
138
const len = mergedData . length ;
@@ -144,7 +149,7 @@ function Overflow<ItemType = any>(
144
149
// Find best match
145
150
totalWidth += currentItemWidth ;
146
151
147
- if ( totalWidth + restWidth > containerWidth ) {
152
+ if ( totalWidth + mergedRestWidth > containerWidth ) {
148
153
updateDisplayCount ( i - 1 ) ;
149
154
break ;
150
155
} else if ( i === len - 1 ) {
@@ -153,7 +158,7 @@ function Overflow<ItemType = any>(
153
158
}
154
159
}
155
160
}
156
- } , [ containerWidth , itemWidths , restWidth , getKey , mergedData ] ) ;
161
+ } , [ containerWidth , itemWidths , mergedRestWidth , getKey , mergedData ] ) ;
157
162
158
163
// ================================ Render ================================
159
164
let overflowNode = (
0 commit comments