From 630b8c543b46f11dd65ae11c7a722686bf4ce795 Mon Sep 17 00:00:00 2001 From: rory Date: Tue, 28 May 2024 17:06:48 -0700 Subject: [PATCH] Add a comment explaining handleUnusedOptimisticID --- src/libs/Middleware/HandleUnusedOptimisticID.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 ?? [];