Skip to content

Fix avatar fallback not working for optimistically rendered new comments #38

@amoscicki

Description

@amoscicki

Summary

When adding a comment, if the user's profile picture URL has expired (R2 presigned URL), the avatar shows a broken image instead of the DiceBear initials fallback.

Root Cause

In src/routes/learn/$slug/-components/comment-list.tsx (lines 194-197):

src={
  comment.profile.image ??
  `https://api.dicebear.com/9.x/initials/svg?seed=...`
}

The ?? operator only triggers fallback for null or undefined. An expired presigned URL is still a truthy string, so:

  1. Expired URL is used as img src
  2. Image fails to load (403)
  3. No onError handler exists to catch this and show fallback
  4. Result: broken image

Steps to Reproduce

  1. Upload a profile picture
  2. Wait for R2 presigned URL to expire (~1 hour)
  3. Add a comment on any video segment
  4. Observe avatar shows broken image icon

Current Behavior

Broken image displayed when profile picture URL has expired.

Expected Behavior

DiceBear initials fallback should display when image fails to load.

Proposed Solution

Add onError handler to fall back gracefully:

<img
  src={comment.profile.image ?? fallbackUrl}
  onError={(e) => { e.currentTarget.src = fallbackUrl }}
  alt="User avatar"
/>

Or fix the root cause (issue #34) by not storing presigned URLs in the database.

Related Issues

Affected Areas

  • /src/routes/learn/$slug/-components/comment-list.tsx (lines 191-199, 355-363)
  • /src/routes/learn/$slug/-components/comment-form.tsx (lines 125-132)

Acceptance Criteria

  • Avatar shows DiceBear fallback when image URL fails to load
  • No broken image icons visible in comments

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions