Skip to content

Commit 5e0d55c

Browse files
committed
fix mobile flicker on plant tiles
1 parent 35a3e04 commit 5e0d55c

File tree

1 file changed

+22
-45
lines changed

1 file changed

+22
-45
lines changed

src/components/Explorer.vue

Lines changed: 22 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -982,26 +982,8 @@ export default {
982982
} else {
983983
// First update the counts
984984
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
991986
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-
});
1005987
}
1006988
},
1007989
deep: true,
@@ -1257,16 +1239,15 @@ export default {
12571239
this.submitTimeout = null;
12581240
}
12591241
this.submitTimeout = setTimeout(submit.bind(this), 50); // Reduced timeout for faster response
1260-
1242+
12611243
function submit() {
1262-
// Force a complete reset of the results to trigger reactivity
1244+
// Reset pagination values
12631245
this.page = 0;
12641246
this.loadedAll = false;
12651247
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);
12701251
12711252
// Restart infinite scroll monitoring
12721253
this.restartLoadMoreIfNeeded();
@@ -1275,17 +1256,8 @@ export default {
12751256
this.filtersOpen = false;
12761257
this.submitTimeout = null;
12771258
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(() => {});
12891261
}
12901262
},
12911263
async updateCounts() {
@@ -1328,12 +1300,14 @@ export default {
13281300
doUpdate();
13291301
});
13301302
},
1331-
async fetchPage() {
1303+
async fetchPage(replace = false) {
13321304
this.loading = true;
13331305
if (this.favorites && ![...this.$store.state.favorites].length) {
13341306
// Avoid a query that would result in seeing all of the plants
13351307
// in the database as "favorites"
1336-
this.results = [];
1308+
if (replace) {
1309+
this.results = [];
1310+
}
13371311
this.loadedAll = true;
13381312
this.total = 0;
13391313
this.loading = false;
@@ -1366,13 +1340,16 @@ export default {
13661340
if (!data.results.length || this.favorites || this.questions) {
13671341
this.loadedAll = true;
13681342
}
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+
}
13761353
this.total = data.total;
13771354
this.loading = false;
13781355
},

0 commit comments

Comments
 (0)