-
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
Merged
Merged
Switch back to getAuthors #26554
Changes from 8 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d4c49cf
Switch back to getAuthors
adamsilverstein 75c7372
Use __unstableGetAuthor.
adamsilverstein 3d4c6f0
Remove deprecated call.
adamsilverstein 2c0a96a
Avoid repeated calls to __unstableGetAuthor.
adamsilverstein 8b76134
Improfe request in __unstableGetAuthor.
adamsilverstein 5e97f14
Merge branch 'master' into fix/26476
adamsilverstein 6c832c9
Move array extraction into `__unstableGetAuthor` selector.
adamsilverstein cead69d
Avoid showing author selector when only one user.
adamsilverstein b6c9de7
fix getAuthor and getAuthors resolvers
youknowriad f507edb
simplification
youknowriad d1f0d03
Fix small selector issues
youknowriad File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,12 +56,21 @@ export const isRequestingEmbedPreview = createRegistrySelector( | |
* @return {Array} Authors list. | ||
*/ | ||
export function getAuthors( state ) { | ||
deprecated( "select( 'core' ).getAuthors()", { | ||
alternative: "select( 'core' ).getUsers({ who: 'authors' })", | ||
} ); | ||
return getUserQueryResults( state, 'authors' ); | ||
} | ||
|
||
/** | ||
* Returns all available authors. | ||
* | ||
* @param {Object} state Data state. | ||
* | ||
* @return {Array} Authors list. | ||
*/ | ||
export function __unstableGetAuthor( state ) { | ||
const authors = getUserQueryResults( state, 'author' ); | ||
return authors ? authors[ 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. It should probably return 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. Good point, will change. |
||
} | ||
|
||
/** | ||
* Returns the current user. | ||
* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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