Skip to content

fix(activity-feed-v2): resolve avatar URLs via getAvatarUrl callback#4644

Open
jackiejou wants to merge 2 commits into
box:masterfrom
jackiejou:fix/activity-feed-v2-avatar-url
Open

fix(activity-feed-v2): resolve avatar URLs via getAvatarUrl callback#4644
jackiejou wants to merge 2 commits into
box:masterfrom
jackiejou:fix/activity-feed-v2-avatar-url

Conversation

@jackiejou

@jackiejou jackiejou commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Add useAvatarUrls hook that walks the activity feed, collects unique author/assignee/version-actor ids, and resolves their avatar URLs via the existing getAvatarUrl callback (same path v1 uses for tokenized avatar URLs).
  • Thread the resolved map through every feed-item transformer so comment/annotation/task/version rows render with real avatars instead of the initials placeholder.
  • Drop the user.avatar_url payload fallback. The Box API embeds users as User--Mini on Comment/Annotation/Task/Version created_by, which does not include avatar_url, so the fallback was always undefined in practice.
  • Hoist GetAvatarUrl and AvatarUrlMap to the shared types.ts so the prop, the hook, and the transformers all share one signature.

Hook behavior

  • In-flight ids are tracked separately from resolved ids. A transient fetch failure or a mid-fetch unmount no longer permanently blacklists a user id; the next render that surfaces the id retries.
  • Per-user de-duplication happens upstream; the underlying Users.getAvatarUrlWithAccessToken cache is still in effect.

Test plan

  • yarn test --watchAll=false --testPathPattern="activity-feed-v2" -> 252/252 passing
  • yarn test --watchAll=false --testPathPattern="SidebarFileProperties" -> 4/4 passing
  • Visually confirm avatars render in the v2 activity feed sidebar

Summary by CodeRabbit

Release Notes

  • New Features

    • Improved avatar URL resolution for activity feed items. Avatars are now efficiently resolved via a dedicated mechanism, deduplicated across authors/assignees/replies, and reused across renders.
  • Bug Fixes

    • Updated activity feed item transformations to consistently use the resolved avatar URL mapping, including cases where an avatar URL can’t be found.
  • Tests

    • Added and updated unit tests to cover avatar URL fetching behavior and transformation outputs for comments, annotations, tasks, and version history.

@jackiejou jackiejou requested review from a team as code owners June 23, 2026 00:01
@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 0aa1b7de-5e17-4ee8-978d-e82a549c96af

📥 Commits

Reviewing files that changed from the base of the PR and between 64be76d and 334d397.

📒 Files selected for processing (2)
  • src/elements/content-sidebar/activity-feed-v2/__tests__/useAvatarUrls.test.tsx
  • src/elements/content-sidebar/activity-feed-v2/useAvatarUrls.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/elements/content-sidebar/activity-feed-v2/tests/useAvatarUrls.test.tsx
  • src/elements/content-sidebar/activity-feed-v2/useAvatarUrls.ts

Walkthrough

New AvatarUrlMap and GetAvatarUrl types are added. A useAvatarUrls hook collects unique user IDs from feed items, asynchronously resolves avatar URLs via getAvatarUrl, and caches results to avoid duplicate fetches. Transformer functions (transformCommentToMessages, transformAnnotationToMessages, transformTaskToProps, transformVersionToProps, transformFeedItem) gain an optional avatarUrls parameter to resolve author and assignee avatar URLs from the map. ActivityFeedV2 wires the hook and passes the resolved map into transformations.

Changes

Avatar URL resolution in ActivityFeedV2

Layer / File(s) Summary
Avatar type contracts
src/elements/content-sidebar/activity-feed-v2/types.ts
Adds AvatarUrlMap (readonly userId→url map) and GetAvatarUrl (async lookup) type aliases; updates ActivityFeedV2Props.getAvatarUrl to reference GetAvatarUrl.
Transformer avatar map wiring
src/elements/content-sidebar/activity-feed-v2/transformers.ts
Adds resolveAvatarUrl helper; updates toUserAuthor, commentToTextMessage, transformCommentToMessages, transformAnnotationToMessages, transformTaskToProps, transformVersionToProps, and transformFeedItem to accept and thread AvatarUrlMap; exports getVersionUser.
useAvatarUrls hook
src/elements/content-sidebar/activity-feed-v2/useAvatarUrls.ts
Implements ID collection across all feed item types, deduplication via Set, async Promise.all resolution, in-flight/resolved ref caches to skip duplicate fetches, retry on failure, and cleanup-flag guard against stale state updates.
ActivityFeedV2 integration
src/elements/content-sidebar/activity-feed-v2/ActivityFeedV2.tsx
Calls useAvatarUrls(feedItems, getAvatarUrl), passes resulting avatarUrls into transformFeedItem, and adds it to the transformedItems memo dependency array.
Transformer and hook tests
src/elements/content-sidebar/activity-feed-v2/__tests__/transformers.test.ts, src/elements/content-sidebar/activity-feed-v2/__tests__/useAvatarUrls.test.tsx
Updates existing transformer expectations to undefined without a map; adds describe('avatarUrls') covering map resolution for all feed item types and missing-ID fallback; adds full useAvatarUrls suite covering deduplication, caching, failure retry, in-flight retries, and null/undefined inputs.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • box/box-ui-elements#4533: Modifies the same transformers.ts entry points (transformCommentToMessages, transformAnnotationToMessages, transformFeedItem) that this PR extends with avatar map threading.
  • box/box-ui-elements#4582: Modifies transformTaskToProps signature and returned TaskItemProps, directly adjacent to the avatarUrls parameter added to the same function here.

Suggested labels

ready-to-merge

Suggested reviewers

  • ahorowitz123
  • kduncanhsu
  • zhirongwang

Poem

🐇 Hop, hop, a map of faces appears,
Each user ID matched to a portrait so clear.
No more stale URLs from the user's own stash —
The hook fetches avatars in one async dash.
Retries on failure, deduped with care,
A feed full of faces — the rabbit's proud flair! 🖼️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is comprehensive and well-structured, covering the summary of changes, hook behavior details, and test results. However, it does not follow the repository's PR description template. While the description content is excellent and informative, consider aligning with the repository template structure for consistency with team conventions.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarizes the main change: resolving avatar URLs via the getAvatarUrl callback mechanism for the activity-feed-v2 component.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/elements/content-sidebar/activity-feed-v2/useAvatarUrls.ts`:
- Around line 88-104: The cleanup function in the useEffect (the arrow function
at lines 102-104) currently only sets cancelled to true, but fails to clear the
in-flight IDs that were being tracked in inFlightIdsRef.current. When
dependencies change and the cleanup runs, the pendingIds remain in
inFlightIdsRef, causing them to be skipped in the next effect run and never
retried. Modify the cleanup function to iterate through pendingIds and delete
each ID from inFlightIdsRef.current in addition to setting cancelled to true,
ensuring these IDs can be fetched again when the effect re-runs with new
dependencies.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f9809241-bfe4-404d-8477-97f9bd946a43

📥 Commits

Reviewing files that changed from the base of the PR and between 92f54fe and 64be76d.

📒 Files selected for processing (6)
  • src/elements/content-sidebar/activity-feed-v2/ActivityFeedV2.tsx
  • src/elements/content-sidebar/activity-feed-v2/__tests__/transformers.test.ts
  • src/elements/content-sidebar/activity-feed-v2/__tests__/useAvatarUrls.test.tsx
  • src/elements/content-sidebar/activity-feed-v2/transformers.ts
  • src/elements/content-sidebar/activity-feed-v2/types.ts
  • src/elements/content-sidebar/activity-feed-v2/useAvatarUrls.ts

Comment thread src/elements/content-sidebar/activity-feed-v2/useAvatarUrls.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant