From a151d4047cd4f8663255496c38b4696ebac3296a Mon Sep 17 00:00:00 2001 From: tellthemachines Date: Mon, 29 May 2023 11:41:09 +1000 Subject: [PATCH] Copy array for reorder --- .../sidebar-navigation-screen-pages/index.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js index 617180d69cbed..6a3e02c64825f 100644 --- a/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js +++ b/packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js @@ -67,20 +67,22 @@ export default function SidebarNavigationScreenPages() { const isHomePageBlog = frontPage === postsPage; - if ( ! isHomePageBlog && pages?.length ) { - const homePageIndex = pages.findIndex( + const reorderedPages = pages && [ ...pages ]; + + if ( ! isHomePageBlog && reorderedPages?.length ) { + const homePageIndex = reorderedPages.findIndex( ( item ) => item.id === frontPage ); - const homePage = pages.splice( homePageIndex, 1 ); - pages?.splice( 0, 0, ...homePage ); + const homePage = reorderedPages.splice( homePageIndex, 1 ); + reorderedPages?.splice( 0, 0, ...homePage ); - const postsPageIndex = pages.findIndex( + const postsPageIndex = reorderedPages.findIndex( ( item ) => item.id === postsPage ); - const blogPage = pages.splice( postsPageIndex, 1 ); + const blogPage = reorderedPages.splice( postsPageIndex, 1 ); - pages.splice( 1, 0, ...blogPage ); + reorderedPages.splice( 1, 0, ...blogPage ); } return ( @@ -114,7 +116,7 @@ export default function SidebarNavigationScreenPages() { ) } - { pages?.map( ( item ) => { + { reorderedPages?.map( ( item ) => { let itemIcon; switch ( item.id ) { case frontPage: