Skip to content

fix: remove duplicate placeholder rendering in phase-based content closure#363

Open
kirillsh wants to merge 1 commit intoSDWebImage:masterfrom
kirillsh:fix/double-placeholder-rendering
Open

fix: remove duplicate placeholder rendering in phase-based content closure#363
kirillsh wants to merge 1 commit intoSDWebImage:masterfrom
kirillsh:fix/double-placeholder-rendering

Conversation

@kirillsh
Copy link

@kirillsh kirillsh commented Feb 16, 2026

Problem

When using the phase-based content closure API, the placeholder content is rendered twice in the ZStack — once directly via content() and once via setupInitialState()setupPlaceholder().

This causes semi-transparent placeholder colors to appear darker than expected due to double-layering.

For example, a 5% black placeholder (Color.black.opacity(0.05)) renders at ~9.75% effective opacity instead of 5%.

Solution

Remove the redundant content() call from the else branch. setupInitialState() already returns the placeholder via setupPlaceholder(), which calls the same content() with the same phase and additionally applies .id(imageModel.url) for correct SwiftUI view identity tracking.

Summary by CodeRabbit

  • Bug Fixes
    • Improved placeholder display consistency by adjusting how placeholders are initialized and rendered during image loading and error conditions.

…osure

The else branch rendered the placeholder content twice: once directly
via content() and once via setupInitialState() -> setupPlaceholder().
This caused semi-transparent placeholder colors to appear darker than
expected due to double-layering in the ZStack.
@coderabbitai
Copy link

coderabbitai bot commented Feb 16, 2026

No actionable comments were generated in the recent review. 🎉


📝 Walkthrough

Walkthrough

A single-line modification to WebImage.swift that removes early placeholder rendering based on error state, delegating error and empty state handling to the setupInitialState() method during the initialization phase instead.

Changes

Cohort / File(s) Summary
Placeholder Rendering Logic
SDWebImageSwiftUI/Classes/WebImage.swift
Removed early error-state placeholder rendering; error/empty handling now deferred to setupInitialState() during initialization, altering placeholder visibility timing and behavior when errors occur.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A single line hops away,
Error states find a better way,
Setup paths now unified,
Placeholders reorganized! ✨

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: removing duplicate placeholder rendering in the phase-based content closure, which directly matches the PR's core objective of fixing double-layering of placeholder content.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

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

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

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

Comments