Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/libs/Middleware/HandleUnusedOptimisticID.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ import * as PersistedRequests from '@userActions/PersistedRequests';
import ONYXKEYS from '@src/ONYXKEYS';
import type Report from '@src/types/onyx/Report';

/**
* This middleware checks for the presence of a field called preexistingReportID in the response.
* If present, that means that the client passed an optimistic reportID with the request that the server did not use.
* This can happen because there was already a report matching the parameters provided that the client didn't know about.
* (i.e: a DM chat report with the same set of participants)
*
* If that happens, this middleware checks for any serialized network requests that reference the unused optimistic ID.
* If it finds any, it replaces the unused optimistic ID with the "real ID" from the server.
* That way these serialized requests function as expected rather than returning a 404.
*/
const handleUnusedOptimisticID: Middleware = (requestResponse, request, isFromSequentialQueue) =>
requestResponse.then((response) => {
const responseOnyxData = response?.onyxData ?? [];
Expand Down