-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Switch back to getAuthors #26554
Switch back to getAuthors #26554
Changes from 5 commits
d4c49cf
75c7372
3d4c6f0
2c0a96a
8b76134
5e97f14
6c832c9
cead69d
b6c9de7
f507edb
d1f0d03
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,17 +21,23 @@ function PostAuthor() { | |
|
||
const { authorId, isLoading, authors, postAuthor } = useSelect( | ||
( select ) => { | ||
const { getUser, getUsers, isResolving } = select( 'core' ); | ||
const { __unstableGetAuthor, getAuthors, isResolving } = select( | ||
'core' | ||
); | ||
const { getEditedPostAttribute } = select( 'core/editor' ); | ||
const author = getUser( getEditedPostAttribute( 'author' ) ); | ||
const author = | ||
postAuthor || | ||
__unstableGetAuthor( getEditedPostAttribute( 'author' ) )[ 0 ]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, why do we need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, but it is returned as an array with a single element. I can change this so |
||
const query = | ||
! fieldValue || '' === fieldValue ? {} : { search: fieldValue }; | ||
! fieldValue || '' === fieldValue || fieldValue === author.name | ||
? {} | ||
: { search: fieldValue }; | ||
return { | ||
authorId: getEditedPostAttribute( 'author' ), | ||
postAuthor: author, | ||
authors: getUsers( { who: 'authors', ...query } ), | ||
isLoading: isResolving( 'core', 'getUsers', [ | ||
{ search: fieldValue, who: 'authors' }, | ||
authors: getAuthors( query ), | ||
isLoading: isResolving( 'core', 'getAuthors', [ | ||
{ search: fieldValue }, | ||
] ), | ||
}; | ||
}, | ||
|
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.
should the first argument here be "authors" to match the same entity as "getAuthors"?
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.
Maybe? I think that results in the fetched author overwriting the authors? I can test.
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.
Tested changing this and confirmed using the same key results in the query interfering with the
getAuthors
query, causing errors or unexpected results as the results from the two queries overwrite each other.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.
Mmm, so if I'm reading this right
getAuthor(1)
andgetAuthor(2)
are using the same query key which means if I trigger both concurrently, they'll mess with each other's result.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.
@youknowriad - Oh, good point. I didn't think about concurrent requests. Should we build a dynamic key here that includes the requested id? Do we have an existing component that uses this approach/a helper to create the query key?
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.
Yes, I did add dynamic query keys for both getAuthor and getAuthors, I think it will solve both issues so I reverted the change you did with useMemo