@@ -982,26 +982,8 @@ export default {
982
982
} else {
983
983
// First update the counts
984
984
await this .updateCounts ();
985
-
986
- // Reset the results array to force a re-render
987
- const oldResults = [... this .results ];
988
- this .results = [];
989
-
990
- // Force an immediate submit to update the display
985
+ // Submit without clearing current results to avoid flicker on mobile
991
986
this .submit ();
992
-
993
- // Use Vue's nextTick to ensure DOM updates after data changes
994
- this .$nextTick (() => {
995
- // If submit hasn't populated results yet, restore the old ones temporarily
996
- if (this .results .length === 0 && oldResults .length > 0 ) {
997
- this .results = [... oldResults];
998
-
999
- // Then force another update after a short delay
1000
- setTimeout (() => {
1001
- this .forceUpdate ();
1002
- }, 50 );
1003
- }
1004
- });
1005
987
}
1006
988
},
1007
989
deep: true ,
@@ -1257,16 +1239,15 @@ export default {
1257
1239
this .submitTimeout = null ;
1258
1240
}
1259
1241
this .submitTimeout = setTimeout (submit .bind (this ), 50 ); // Reduced timeout for faster response
1260
-
1242
+
1261
1243
function submit () {
1262
- // Force a complete reset of the results to trigger reactivity
1244
+ // Reset pagination values
1263
1245
this .page = 0 ;
1264
1246
this .loadedAll = false ;
1265
1247
this .total = 0 ; // Reset total as well
1266
- this .results = [];
1267
-
1268
- // Immediately force a fetch of new data
1269
- this .fetchPage ();
1248
+
1249
+ // Fetch new data and replace results when it arrives
1250
+ this .fetchPage (true );
1270
1251
1271
1252
// Restart infinite scroll monitoring
1272
1253
this .restartLoadMoreIfNeeded ();
@@ -1275,17 +1256,8 @@ export default {
1275
1256
this .filtersOpen = false ;
1276
1257
this .submitTimeout = null ;
1277
1258
1278
- // Force DOM update by directly manipulating the DOM after a short delay
1279
- setTimeout (() => {
1280
- if (typeof document !== ' undefined' ) {
1281
- // This is a browser-only technique to force a repaint
1282
- const plants = document .querySelectorAll (' .plant' );
1283
- if (plants .length === 0 ) {
1284
- // If no plants are visible yet, force a fetchPage again
1285
- this .fetchPage ();
1286
- }
1287
- }
1288
- }, 100 );
1259
+ // Allow any queued DOM updates to complete
1260
+ this .$nextTick (() => {});
1289
1261
}
1290
1262
},
1291
1263
async updateCounts () {
@@ -1328,12 +1300,14 @@ export default {
1328
1300
doUpdate ();
1329
1301
});
1330
1302
},
1331
- async fetchPage () {
1303
+ async fetchPage (replace = false ) {
1332
1304
this .loading = true ;
1333
1305
if (this .favorites && ! [... this .$store .state .favorites ].length ) {
1334
1306
// Avoid a query that would result in seeing all of the plants
1335
1307
// in the database as "favorites"
1336
- this .results = [];
1308
+ if (replace) {
1309
+ this .results = [];
1310
+ }
1337
1311
this .loadedAll = true ;
1338
1312
this .total = 0 ;
1339
1313
this .loading = false ;
@@ -1366,13 +1340,16 @@ export default {
1366
1340
if (! data .results .length || this .favorites || this .questions ) {
1367
1341
this .loadedAll = true ;
1368
1342
}
1369
- // Prevent duplicate plants by checking if they already exist in the results array
1370
- data .results .forEach ((datum ) => {
1371
- // Only add the plant if it's not already in the results array
1372
- if (! this .results .some (existing => existing ._id === datum ._id )) {
1373
- this .results .push (datum);
1374
- }
1375
- });
1343
+ if (replace) {
1344
+ this .results = data .results ;
1345
+ } else {
1346
+ // Prevent duplicate plants by checking if they already exist in the results array
1347
+ data .results .forEach ((datum ) => {
1348
+ if (! this .results .some ((existing ) => existing ._id === datum ._id )) {
1349
+ this .results .push (datum);
1350
+ }
1351
+ });
1352
+ }
1376
1353
this .total = data .total ;
1377
1354
this .loading = false ;
1378
1355
},
0 commit comments