Skip to content

Commit

Permalink
PagePages: Fix unintended object mutation inside component (#55314)
Browse files Browse the repository at this point in the history
- Don't reuse references when updating postStatuses
- Don't accidentally mutate EMPTY_OBJECT
  • Loading branch information
mcsf authored Oct 13, 2023
1 parent a54da2d commit c47905f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions packages/edit-site/src/components/page-pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
() => ( {
Expand Down

1 comment on commit c47905f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in c47905f.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/6509512393
📝 Reported issues:

Please sign in to comment.