Skip to content

fix(avatar): resolve guest author avatars in editor#4460

Merged
rbcorrales merged 8 commits into
feat/avatar-in-profile-block-themefrom
fix/avatar-guest-cap-editor
Feb 9, 2026
Merged

fix(avatar): resolve guest author avatars in editor#4460
rbcorrales merged 8 commits into
feat/avatar-in-profile-block-themefrom
fix/avatar-guest-cap-editor

Conversation

@rbcorrales

Copy link
Copy Markdown
Member

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 useCoAuthors hook 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 by user_nicename prevents 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_link URL 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:

  1. Open a post with CoAuthors Plus enabled and a WP user as the sole author.
  2. In the Authors sidebar, add a guest author (e.g., "External Contributor"). The guest author's avatar should appear immediately in the avatar block, without saving or refreshing.
  3. Save the post and reload. The avatar should persist.
  4. Remove the guest author and re-add it. The avatar should appear instantly from cache.
  5. Create or edit a page with a Query Loop block that includes posts authored by guest contributors.
  6. Verify that guest author avatars render correctly in the Query Loop preview.
  7. Save and reload. Avatars should still display.
  8. Verify that regular WP user avatars continue to work in both single post and Query Loop contexts.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_nicename from author_link URL for REST API author data
  • Changed module-level cache key from post ID to user_nicename to 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.

Comment thread src/shared/hooks/use-coauthors.test.js
Comment thread src/shared/hooks/use-coauthors.test.js
Comment thread src/shared/hooks/use-coauthors.js Outdated
@rbcorrales rbcorrales added the [Status] Needs Review The issue or pull request needs to be reviewed label Feb 5, 2026

@laurelfulford laurelfulford left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🙂

@github-actions github-actions Bot added [Status] Approved The pull request has been reviewed and is ready to merge and removed [Status] Needs Review The issue or pull request needs to be reviewed labels Feb 6, 2026
@rbcorrales

rbcorrales commented Feb 9, 2026

Copy link
Copy Markdown
Member Author

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:

  • 5084de0: The "Stacked" > "Overlapped" block style rename we talked about.
  • bf60e72: This commit adds an in-flight request map so that when multiple Query Loop posts share the same guest author, only one fetch fires instead of N duplicates. This reduces it to one request per unique author nicename. So if a Query Loop shows 6 posts and the same 3 authors appear across them, it goes from 18 (6 × 3) down to 3. The savings depend on the amount of author overlap.

On a related note, I have local changes (not pushed yet) that take this a step further by registering an enriched newspack_author_info REST field directly in newspack-plugin. This embeds avatar_urls, user_nicename, and is_guest in the post REST response, so the JS side can skip the per-author fetches entirely for Query Loop posts. That eliminates the delay you noticed.

Right now, that field is registered by newspack-newsletters, but at a lower priority, so the enriched version will take precedence when both plugins are active. I'll merge this PR as is to avoid snowballing scope and follow up on the enriched field separately.

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.

@rbcorrales rbcorrales merged commit edc6a4f into feat/avatar-in-profile-block-theme Feb 9, 2026
7 checks passed
@rbcorrales rbcorrales deleted the fix/avatar-guest-cap-editor branch February 9, 2026 22:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Status] Approved The pull request has been reviewed and is ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants