From 5ee754e6f91f01f59b60de8cfa341a2455e42dbb Mon Sep 17 00:00:00 2001 From: Paul Frazee Date: Mon, 28 Aug 2023 17:54:59 -0700 Subject: Improvements to feed assembly to avoid possible state issues (#1318) * Avoid potential dropped posts due to pruning when checking for latest * Add a sanity check to ensure dup react keys never occur (close #1315) --- src/state/models/feeds/posts.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/state/models/feeds/posts.ts') diff --git a/src/state/models/feeds/posts.ts b/src/state/models/feeds/posts.ts index 15145a203..c88249c8f 100644 --- a/src/state/models/feeds/posts.ts +++ b/src/state/models/feeds/posts.ts @@ -277,7 +277,9 @@ export class PostsFeedModel { } const res = await this._getFeed({limit: 1}) if (res.data.feed[0]) { - const slices = this.tuner.tune(res.data.feed, this.feedTuners) + const slices = this.tuner.tune(res.data.feed, this.feedTuners, { + dryRun: true, + }) if (slices[0]) { const sliceModel = new PostsFeedSliceModel(this.rootStore, slices[0]) if (sliceModel.moderation.content.filter) { @@ -374,6 +376,15 @@ export class PostsFeedModel { const toAppend: PostsFeedSliceModel[] = [] for (const slice of slices) { const sliceModel = new PostsFeedSliceModel(this.rootStore, slice) + const dupTest = (item: PostsFeedSliceModel) => + item._reactKey === sliceModel._reactKey + // sanity check + // if a duplicate _reactKey passes through, the UI breaks hard + if (!replace) { + if (this.slices.find(dupTest) || toAppend.find(dupTest)) { + continue + } + } toAppend.push(sliceModel) } runInAction(() => { -- cgit 1.4.1