fix: [IOCOM-1091] Fix for duplicate message in messages list #5509
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Short description
This PR fixes a condition where a new message could appear twice in the messages list.
List of changes proposed in this pull request
In the Message List component:
useFocusEffect
with proper dependenciesLatter is what was causing the bug: two subsequent asynchronous requests (one for all messages and one for just the new one - the previous page) where the first retrieved all messages while the second just the new ones, using the current-but-soon-to-be-outdated starting index (
minimum_id
).So, the reload-all request ends, filling the redux state with all new and old messages. If the previous-page request ends after that, its data has some duplicates in it (the new messages - since its starting
minimum_id
was the old one, not the current one received from the last reload-all) but the reducer puts them in front of the previously receveid ones from the reload-all, duplicating some of them.How to test
You can use the io-dev-api-server code on this PR to create a new message.
Do the following in less than 60 seconds (the refresh time): select a message, create a new one (
POST message
endpoint) and go back to the message list. Now wait for the 60 seconds to expire and use the pull-down-to-refresh. On themain
branch, two duplicated messages should appear on top of the list. On this branch, there is no duplicate.