@@ -16,6 +16,7 @@ export class InfiniteScroll implements ComponentInterface {
16
16
private thrPx = 0 ;
17
17
private thrPc = 0 ;
18
18
private scrollEl ?: HTMLElement ;
19
+ private minHeightLocked = false ;
19
20
20
21
/**
21
22
* didFire exists so that ionInfinite
@@ -141,13 +142,14 @@ export class InfiniteScroll implements ComponentInterface {
141
142
142
143
if ( distanceFromInfinite < 0 ) {
143
144
if ( ! this . didFire ) {
145
+ if ( this . preserveRerenderScrollPosition ) {
146
+ // Lock the min height of the siblings of the infinite scroll
147
+ // if we are preserving the rerender scroll position
148
+ this . lockSiblingMinHeight ( true ) ;
149
+ }
150
+
144
151
this . isLoading = true ;
145
152
this . didFire = true ;
146
-
147
- // Lock the min height of the siblings of the infinite scroll
148
- // if we are preserving the rerender scroll position
149
- this . lockSiblingMinHeight ( true ) ;
150
-
151
153
this . ionInfinite . emit ( ) ;
152
154
return 3 ;
153
155
}
@@ -166,19 +168,20 @@ export class InfiniteScroll implements ComponentInterface {
166
168
* has been previously set by the user when we restore after complete is called.
167
169
*/
168
170
private lockSiblingMinHeight ( lock : boolean ) {
169
- if ( ! this . preserveRerenderScrollPosition ) {
170
- return ;
171
- }
172
-
173
- // Loop through all the siblings of the infinite scroll, but ignore the infinite scroll itself
174
171
const siblings = this . el . parentElement ?. children || [ ] ;
175
172
for ( const sibling of siblings ) {
173
+ // Loop through all the siblings of the infinite scroll, but ignore ourself
176
174
if ( sibling !== this . el && sibling instanceof HTMLElement ) {
177
175
if ( lock ) {
178
176
const elementHeight = sibling . getBoundingClientRect ( ) . height ;
179
- const previousMinHeight = sibling . style . minHeight ;
180
- if ( previousMinHeight ) {
181
- sibling . style . setProperty ( '--ion-previous-min-height' , previousMinHeight ) ;
177
+ if ( this . minHeightLocked ) {
178
+ // The previous min height is from us locking it before, so we can disregard it
179
+ // We still need to lock the min height if we're already locked, though, because
180
+ // the user could have triggered a new load before we've finished the previous one.
181
+ const previousMinHeight = sibling . style . minHeight ;
182
+ if ( previousMinHeight ) {
183
+ sibling . style . setProperty ( '--ion-previous-min-height' , previousMinHeight ) ;
184
+ }
182
185
}
183
186
sibling . style . minHeight = `${ elementHeight } px` ;
184
187
} else {
@@ -188,6 +191,8 @@ export class InfiniteScroll implements ComponentInterface {
188
191
}
189
192
}
190
193
}
194
+
195
+ this . minHeightLocked = lock ;
191
196
}
192
197
193
198
/**
@@ -257,9 +262,11 @@ export class InfiniteScroll implements ComponentInterface {
257
262
258
263
// Unlock the min height of the siblings of the infinite scroll
259
264
// if we are preserving the rerender scroll position
260
- setTimeout ( ( ) => {
261
- this . lockSiblingMinHeight ( false ) ;
262
- } , 100 ) ;
265
+ if ( this . preserveRerenderScrollPosition ) {
266
+ setTimeout ( ( ) => {
267
+ this . lockSiblingMinHeight ( false ) ;
268
+ } , 10 ) ;
269
+ }
263
270
}
264
271
265
272
private canStart ( ) : boolean {
0 commit comments