From e473476e40502b67724fa1fbc2b1228650116873 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Wed, 4 Oct 2023 18:28:42 +0530 Subject: [PATCH] fix persisted requests --- src/libs/actions/PersistedRequests.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/PersistedRequests.ts b/src/libs/actions/PersistedRequests.ts index 92a3b817959d..e4b0fecdd73a 100644 --- a/src/libs/actions/PersistedRequests.ts +++ b/src/libs/actions/PersistedRequests.ts @@ -31,17 +31,21 @@ function remove(requestToRemove: Request) { * We only remove the first matching request because the order of requests matters. * If we were to remove all matching requests, we can end up with a final state that is different than what the user intended. */ - const index = persistedRequests.findIndex((persistedRequest) => isEqual(persistedRequest, requestToRemove)); + const requests = [...persistedRequests]; + const index = requests.findIndex((persistedRequest) => isEqual(persistedRequest, requestToRemove)); if (index === -1) { return; } - persistedRequests.splice(index, 1); - Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, persistedRequests); + requests.splice(index, 1); + persistedRequests = requests; + Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, requests); } function update(oldRequestIndex: number, newRequest: Request) { - persistedRequests.splice(oldRequestIndex, 1, newRequest); - Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, persistedRequests); + const requests = [...persistedRequests]; + requests.splice(oldRequestIndex, 1, newRequest); + persistedRequests = requests; + Onyx.set(ONYXKEYS.PERSISTED_REQUESTS, requests); } function getAll(): Request[] {