-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor: Reuse data query in the post author components #58760
Conversation
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the Core SVNCore Committers: Use this line as a base for the props when committing in SVN:
GitHub Merge commitsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Size Change: -50 B (0%) Total Size: 1.69 MB
ℹ️ View Unchanged
|
return { | ||
authorId: _authorId, | ||
authors: getUsers( query ), | ||
postAuthor: getUser( _authorId, BASE_QUERY ), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The query
argument must have a stable reference for getEntityRecord
to return the memoized value. The issue is more noticeable when passing the _fields
argument - the selector will return a new reference on each call.
cc @youknowriad
Unit Test
it( 'should return same reference for filtered item', () => {
const state = deepFreeze( {
entities: {
records: {
postType: {
post: {
queriedData: {
items: {
default: {
1: {
id: 1,
content: 'chicken',
author: 'bob',
},
},
},
itemIsComplete: {
default: {
1: true,
},
},
queries: {},
},
},
},
},
},
} );
expect(
getEntityRecord( state, 'postType', 'post', 1, {
_fields: 'author,content',
} )
).toBe(
getEntityRecord( state, 'postType', 'post', 1, {
_fields: 'author,content',
} )
);
} );
Flaky tests detected in a224673. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7809872420
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really cool factorization. Thanks
What?
PRs introduces a new
useAuthorsQuery
hook and reuses it across the components.Why?
Maintenance.
Testing Instructions
Testing Instructions for Keyboard
Same.
Screenshots or screencast