From 42ac82bc8c49cfb826383c1a7c928b83d4585137 Mon Sep 17 00:00:00 2001 From: kongxiaojun Date: Mon, 13 Feb 2023 05:05:18 -0800 Subject: [PATCH] Fix a crash when trying to remove a mock network call (#4403) Summary: Crash when trying to remove a mock network call Issue: https://github.com/facebook/flipper/issues/3799 ## Changelog Read mock routes type error.Transform it from array to object. Pull Request resolved: https://github.com/facebook/flipper/pull/4403 Test Plan: Test passed on my Mac. Reviewed By: antonk52 Differential Revision: D42918910 Pulled By: passy fbshipit-source-id: 919bb6d2a2887aed46fb4a348f3f93e7abb765e5 --- desktop/plugins/public/network/index.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/desktop/plugins/public/network/index.tsx b/desktop/plugins/public/network/index.tsx index 812dd91cb..b1239df2e 100644 --- a/desktop/plugins/public/network/index.tsx +++ b/desktop/plugins/public/network/index.tsx @@ -239,11 +239,15 @@ export function plugin(client: PluginClient) { function init() { supportsMocks(client.device) .then((result) => { - const newRoutes = JSON.parse( + const newRouteArray: [any] = JSON.parse( localStorage.getItem( LOCALSTORAGE_MOCK_ROUTE_LIST_KEY + client.appId, - ) || '{}', + ) || '[]', ); + const newRoutes: {[id: string]: any} = {}; + newRouteArray.forEach((value, index) => { + newRoutes[index.toString()] = value; + }); batch(() => { routes.set(newRoutes); isMockResponseSupported.set(result);