From a9983db971ea637333d0ff23f1b604a9c04aa7f9 Mon Sep 17 00:00:00 2001 From: Miguel Fonseca <150562+mcsf@users.noreply.github.com> Date: Thu, 12 Oct 2023 16:18:57 +0100 Subject: [PATCH] PagePages: Fix unintended object mutation inside component - Don't reuse references when updating postStatuses - Don't accidentally mutate EMPTY_OBJECT --- .../edit-site/src/components/page-pages/index.js | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/edit-site/src/components/page-pages/index.js b/packages/edit-site/src/components/page-pages/index.js index a616ea617feb91..3d0623eb96d05f 100644 --- a/packages/edit-site/src/components/page-pages/index.js +++ b/packages/edit-site/src/components/page-pages/index.js @@ -39,13 +39,15 @@ export default function PagePages() { } ); // Request post statuses to get the proper labels. const { records: statuses } = useEntityRecords( 'root', 'status' ); - const postStatuses = - statuses === null - ? EMPTY_OBJECT - : statuses.reduce( ( acc, status ) => { - acc[ status.slug ] = status.name; - return acc; - }, EMPTY_OBJECT ); + const postStatuses = useMemo( + () => + statuses === null + ? EMPTY_OBJECT + : Object.fromEntries( + statuses.map( ( { slug, name } ) => [ slug, name ] ) + ), + [ statuses ] + ); const queryArgs = useMemo( () => ( {