Skip to content

Commit a151d40

Browse files
Copy array for reorder
1 parent 2ba722b commit a151d40

File tree

1 file changed

+10
-8
lines changed
  • packages/edit-site/src/components/sidebar-navigation-screen-pages

1 file changed

+10
-8
lines changed

packages/edit-site/src/components/sidebar-navigation-screen-pages/index.js

+10-8
Original file line numberDiff line numberDiff line change
@@ -67,20 +67,22 @@ export default function SidebarNavigationScreenPages() {
6767

6868
const isHomePageBlog = frontPage === postsPage;
6969

70-
if ( ! isHomePageBlog && pages?.length ) {
71-
const homePageIndex = pages.findIndex(
70+
const reorderedPages = pages && [ ...pages ];
71+
72+
if ( ! isHomePageBlog && reorderedPages?.length ) {
73+
const homePageIndex = reorderedPages.findIndex(
7274
( item ) => item.id === frontPage
7375
);
74-
const homePage = pages.splice( homePageIndex, 1 );
75-
pages?.splice( 0, 0, ...homePage );
76+
const homePage = reorderedPages.splice( homePageIndex, 1 );
77+
reorderedPages?.splice( 0, 0, ...homePage );
7678

77-
const postsPageIndex = pages.findIndex(
79+
const postsPageIndex = reorderedPages.findIndex(
7880
( item ) => item.id === postsPage
7981
);
8082

81-
const blogPage = pages.splice( postsPageIndex, 1 );
83+
const blogPage = reorderedPages.splice( postsPageIndex, 1 );
8284

83-
pages.splice( 1, 0, ...blogPage );
85+
reorderedPages.splice( 1, 0, ...blogPage );
8486
}
8587

8688
return (
@@ -114,7 +116,7 @@ export default function SidebarNavigationScreenPages() {
114116
</Truncate>
115117
</PageItem>
116118
) }
117-
{ pages?.map( ( item ) => {
119+
{ reorderedPages?.map( ( item ) => {
118120
let itemIcon;
119121
switch ( item.id ) {
120122
case frontPage:

0 commit comments

Comments
 (0)