diff --git a/src/libs/Middleware/HandleUnusedOptimisticID.ts b/src/libs/Middleware/HandleUnusedOptimisticID.ts index eb419401d84d..db726855d075 100644 --- a/src/libs/Middleware/HandleUnusedOptimisticID.ts +++ b/src/libs/Middleware/HandleUnusedOptimisticID.ts @@ -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 ?? [];