fix(avatar): resolve guest author avatars in editor#4460
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes two issues with guest author avatar resolution in the editor's avatar block:
Changes:
- Modified avatar fetching strategy from per-post to per-author (by nicename) to enable immediate avatar rendering when adding guest authors
- Added Query Loop support by extracting
user_nicenamefromauthor_linkURL for REST API author data - Changed module-level cache key from post ID to
user_nicenameto support the new fetching strategy
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/shared/hooks/use-coauthors.js | Refactored avatar fetching to use per-author endpoint instead of per-post, added URL parsing logic to extract user_nicename from author_link for Query Loop support, updated caching strategy to key by user_nicename |
| src/shared/hooks/use-coauthors.test.js | Added comprehensive test coverage for guest author avatar fetching, Query Loop scenarios, URL parsing, encoding, error handling, and cache behavior |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
This looks super solid, @rbcorrales! The Guest Author avatars are snappy overall in the editor; they took a little longer in the Query block than solo, but that makes sense; they didn't take any longer than the regular authors to populate for me so it felt like it was working "right" (if that makes sense).
This is 100% not actionable because I can guarantee none of our publishers use this setting, but the only possible issue is that when Permalinks are set to Plain (like www.mysite.com?p=123 vs www.mysite.com/category/post) the nicename matching doesn't work for any author type in the editor. The avatars still work fine on the front-end.
The only thing we might want to do with that info is mention that in the docs/readme, but that's it -- it's totally a "testing stuff like a weirdo" issue 🙂
|
Thanks for the thorough testing, @laurelfulford! The slight delay you noticed for Query Loop avatars is expected. For those posts, the block has to fetch each guest author's avatar from the CoAuthors REST endpoint individually (the CAP store only works for the currently edited post). The last two pushed commits were:
On a related note, I have local changes (not pushed yet) that take this a step further by registering an enriched Right now, that field is registered by Regarding plain permalinks, the current code gracefully rejects those URLs (no crash), but Query Loop avatars still won't resolve in that case. The enriched REST field changes I mentioned would actually fix this, since the required user data will come directly from the REST response without needing to parse the URL. Update: Here's that commit with what I mentioned above e7652a0. |
edc6a4f
into
feat/avatar-in-profile-block-theme
All Submissions:
Changes proposed in this Pull Request:
This PR fixes two issues with guest author avatar resolution in the editor's avatar block:
1. Guest author avatars not appearing until save + refresh
When adding a CoAuthors Plus guest author to a post, their avatar didn't render until the post was saved and the page was reloaded. The root cause was that the
useCoAuthorshook fetched avatar data from the per-post CAP REST endpoint (/coauthors/v1/coauthors?post_id=X), which only returns saved coauthors. An unsaved guest author wouldn't be in the response.The fix switches to per-author fetching using
/coauthors/v1/coauthors/{user_nicename}, which resolves avatar data for any guest author regardless of save state. A module-level cache keyed byuser_nicenameprevents duplicate requests across re-mounts and Query Loop iterations.2. Guest author avatars not appearing in Query Loop context
In a Query Loop block, guest author avatars never appeared, even after saving and refreshing. The REST data available for Query Loop posts does not include the fields the avatar fetch logic relied on, so those authors were silently skipped.
The fix extracts the author slug from the
author_linkURL and broadens the fetch filters to include Query Loop authors alongside known guest authors.Closes NPPD-1197.
How to test the changes in this Pull Request:
Other information: