Skip to content

Commit

Permalink
DataViews: prevent unnecessary re-renders (#57452)
Browse files Browse the repository at this point in the history
  • Loading branch information
oandregal committed Dec 29, 2023
1 parent b85da47 commit af8c530
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
11 changes: 9 additions & 2 deletions packages/dataviews/src/filters.js
@@ -1,3 +1,8 @@
/**
* WordPress dependencies
*/
import { memo } from '@wordpress/element';

/**
* Internal dependencies
*/
Expand All @@ -21,7 +26,7 @@ const sanitizeOperators = ( field ) => {
);
};

export default function Filters( { fields, view, onChangeView } ) {
const Filters = memo( function Filters( { fields, view, onChangeView } ) {
const filters = [];
fields.forEach( ( field ) => {
if ( ! field.type ) {
Expand Down Expand Up @@ -88,4 +93,6 @@ export default function Filters( { fields, view, onChangeView } ) {
}

return filterComponents;
}
} );

export default Filters;
8 changes: 5 additions & 3 deletions packages/dataviews/src/search.js
Expand Up @@ -2,11 +2,11 @@
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { useEffect, useRef } from '@wordpress/element';
import { useEffect, useRef, memo } from '@wordpress/element';
import { SearchControl } from '@wordpress/components';
import { useDebouncedInput } from '@wordpress/compose';

export default function Search( { label, view, onChangeView } ) {
const Search = memo( function Search( { label, view, onChangeView } ) {
const [ search, setSearch, debouncedSearch ] = useDebouncedInput(
view.search
);
Expand Down Expand Up @@ -35,4 +35,6 @@ export default function Search( { label, view, onChangeView } ) {
size="compact"
/>
);
}
} );

export default Search;
7 changes: 5 additions & 2 deletions packages/dataviews/src/view-actions.js
Expand Up @@ -6,6 +6,7 @@ import {
privateApis as componentsPrivateApis,
} from '@wordpress/components';
import { __ } from '@wordpress/i18n';
import { memo } from '@wordpress/element';

/**
* Internal dependencies
Expand Down Expand Up @@ -239,7 +240,7 @@ function SortMenu( { fields, view, onChangeView } ) {
);
}

export default function ViewActions( {
const ViewActions = memo( function ViewActions( {
fields,
view,
onChangeView,
Expand Down Expand Up @@ -282,4 +283,6 @@ export default function ViewActions( {
</DropdownMenuGroup>
</DropdownMenu>
);
}
} );

export default ViewActions;

1 comment on commit af8c530

@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 af8c530.
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/7356774421
📝 Reported issues:

Please sign in to comment.