Skip to content

Pfp loading fix#2042

Merged
simo6529 merged 4 commits intomainfrom
pfp-loading-fix
Mar 3, 2026
Merged

Pfp loading fix#2042
simo6529 merged 4 commits intomainfrom
pfp-loading-fix

Conversation

@simo6529
Copy link
Copy Markdown
Collaborator

@simo6529 simo6529 commented Mar 3, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Improved profile image loading with progressive modes, better error handling, and a graceful placeholder fallback.
  • New Features

    • Expanded image scaling so additional image sources are eligible for optimized delivery.

simo6529 added 3 commits March 3, 2026 11:25
Signed-off-by: Simo <simo@6529.io>
Signed-off-by: Simo <simo@6529.io>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

Adds client-side image loading state and fallback flow (optimized → unoptimized → placeholder) to WaveDropAuthorPfp, and includes a new CloudFront images prefix in image.helpers to enable scaling for that domain.

Changes

Cohort / File(s) Summary
Image loading state & avatar rendering
components/waves/drops/WaveDropAuthorPfp.tsx
Introduces Pfp load state (optimized
Scalable CloudFront prefix
helpers/image.helpers.ts
Adds https://d3lqz0a4bldqgf.cloudfront.net/images/ to SCALABLE_PREFIXES so getScaledImageUri can produce scaled URLs for that CloudFront domain.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • ragnep

Poem

🐰 I nibble bytes beneath the moonlight,
CloudFront carrots shining bright tonight.
If optimized hops start to stray,
I fall back, then I chew away.
Scaled and safe — a rabbit's delight.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Pfp loading fix' directly addresses the main change: implementing client-side image loading state management with fallback modes (optimized, unoptimized, placeholder) in the WaveDropAuthorPfp component.

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

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch pfp-loading-fix

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 and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
components/waves/drops/WaveDropAuthorPfp.tsx (1)

21-32: Consider extracting the mode type for DRY.

The union type "optimized" | "unoptimized" | "placeholder" is repeated three times. Extracting it would reduce repetition and make future changes easier.

♻️ Suggested refactor
+type LoadMode = "optimized" | "unoptimized" | "placeholder";
+
 const WaveDropAuthorPfp: React.FC<WaveDropAuthorPfpProps> = ({ drop }) => {
   const compact = useCompactMode();
   const resolvedPfp = drop.author.pfp
     ? resolveIpfsUrlSync(drop.author.pfp)
     : null;
   const [loadState, setLoadState] = useState<{
     src: string | null;
-    mode: "optimized" | "unoptimized" | "placeholder";
+    mode: LoadMode;
   }>({
     src: null,
     mode: "optimized",
   });
-  const loadMode: "optimized" | "unoptimized" | "placeholder" =
+  const loadMode: LoadMode =
     loadState.src === resolvedPfp ? loadState.mode : "optimized";
-  const setLoadMode = (mode: "optimized" | "unoptimized" | "placeholder") => {
+  const setLoadMode = (mode: LoadMode) => {
     setLoadState({ src: resolvedPfp, mode });
   };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/waves/drops/WaveDropAuthorPfp.tsx` around lines 21 - 32, Extract
the repeated union type into a single type alias (e.g., declare type LoadMode =
"optimized" | "unoptimized" | "placeholder") and update the useState generic,
the loadMode variable's type, and the setLoadMode parameter to use LoadMode
instead of repeating the literal union; ensure loadState state shape remains {
src: string | null; mode: LoadMode } and that functions/variables loadState,
loadMode, and setLoadMode reference the new LoadMode alias.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@components/waves/drops/WaveDropAuthorPfp.tsx`:
- Around line 21-32: Extract the repeated union type into a single type alias
(e.g., declare type LoadMode = "optimized" | "unoptimized" | "placeholder") and
update the useState generic, the loadMode variable's type, and the setLoadMode
parameter to use LoadMode instead of repeating the literal union; ensure
loadState state shape remains { src: string | null; mode: LoadMode } and that
functions/variables loadState, loadMode, and setLoadMode reference the new
LoadMode alias.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6178c9 and c75feff.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (2)
  • components/waves/drops/WaveDropAuthorPfp.tsx
  • helpers/image.helpers.ts

Signed-off-by: Simo <simo@6529.io>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Mar 3, 2026

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
components/waves/drops/WaveDropAuthorPfp.tsx (1)

57-66: Make unoptimized fallback use the original URL, not the scaled URL.

Right now both modes still request getScaledImageUri(...). If the scaled path itself is bad/unavailable, the unoptimized retry cannot recover. Consider switching src to resolvedPfp in unoptimized mode.

♻️ Proposed refactor
+  const optimizedPfp =
+    resolvedPfp ? getScaledImageUri(resolvedPfp, ImageScale.W_AUTO_H_50) : null;
+  const imageSrc =
+    loadMode === "optimized" ? optimizedPfp : resolvedPfp;
+
   const avatarContent =
     resolvedPfp === null || loadMode === "placeholder" ? (
       <div className="tw-h-full tw-w-full tw-rounded-lg tw-bg-iron-900 tw-ring-1 tw-ring-inset tw-ring-white/10" />
     ) : (
       <Image
-        key={`${resolvedPfp}-${loadMode}`}
-        src={getScaledImageUri(resolvedPfp, ImageScale.W_AUTO_H_50)}
+        key={`${imageSrc}-${loadMode}`}
+        src={imageSrc}
         alt={
           authorHandle ? `${authorHandle}'s profile picture` : "Profile picture"
         }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@components/waves/drops/WaveDropAuthorPfp.tsx` around lines 57 - 66, The Image
currently always uses getScaledImageUri(resolvedPfp, ImageScale.W_AUTO_H_50) so
when the scaled URL fails the unoptimized retry also requests the same bad URL;
update the src prop in WaveDropAuthorPfp (the Image element that references
getScaledImageUri, resolvedPfp and loadMode) to use the original resolvedPfp
when loadMode === "unoptimized" (i.e., choose getScaledImageUri(...) for
optimized mode and resolvedPfp for unoptimized mode) while keeping the
unoptimized prop and onError handler unchanged so the fallback truly retries the
original image URL.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@components/waves/drops/WaveDropAuthorPfp.tsx`:
- Around line 57-66: The Image currently always uses
getScaledImageUri(resolvedPfp, ImageScale.W_AUTO_H_50) so when the scaled URL
fails the unoptimized retry also requests the same bad URL; update the src prop
in WaveDropAuthorPfp (the Image element that references getScaledImageUri,
resolvedPfp and loadMode) to use the original resolvedPfp when loadMode ===
"unoptimized" (i.e., choose getScaledImageUri(...) for optimized mode and
resolvedPfp for unoptimized mode) while keeping the unoptimized prop and onError
handler unchanged so the fallback truly retries the original image URL.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c75feff and 31f544a.

📒 Files selected for processing (1)
  • components/waves/drops/WaveDropAuthorPfp.tsx

@simo6529 simo6529 merged commit 1761bfc into main Mar 3, 2026
7 checks passed
@simo6529 simo6529 deleted the pfp-loading-fix branch March 3, 2026 16:16
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.

2 participants