diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-08-28 17:54:59 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-28 17:54:59 -0700 |
commit | 5ee754e6f91f01f59b60de8cfa341a2455e42dbb (patch) | |
tree | 0240260bbd1ebc47b6b416afc11b2df6c9b344cf /src/state/models/feeds/posts.ts | |
parent | e2f0770b88b24f44d066493e5e39f689feb46915 (diff) | |
download | voidsky-5ee754e6f91f01f59b60de8cfa341a2455e42dbb.tar.zst |
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)
Diffstat (limited to 'src/state/models/feeds/posts.ts')
-rw-r--r-- | src/state/models/feeds/posts.ts | 13 |
1 files changed, 12 insertions, 1 deletions
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(() => { |