Skip to content

(backport from v7) Register the OkHttp network fetcher explicitly in the default image loader#6386

Merged
andremion merged 2 commits intov6from
chore/coil-image-loader-v6
Apr 27, 2026
Merged

(backport from v7) Register the OkHttp network fetcher explicitly in the default image loader#6386
andremion merged 2 commits intov6from
chore/coil-image-loader-v6

Conversation

@andremion
Copy link
Copy Markdown
Contributor

@andremion andremion commented Apr 27, 2026

Goal

Since the Coil 2 → Coil 3 migration in 6.13.0, customers have reported blank/placeholder images in release builds (support ticket). Coil 3 registers OkHttpNetworkFetcherFactory via ServiceLoader, which R8 full-mode can strip, leaving the ImageLoader without a fetcher for HTTP URLs. Registering it explicitly removes the ServiceLoader dependency.

Implementation

StreamImageLoaderFactory — add OkHttpNetworkFetcherFactory() to the components block. Integrators delegating to StreamImageLoaderFactory (Compose StreamCoilImageLoaderFactory.defaultFactory() and the XML StreamCoil singleton) pick up the fix for free. No public API changes.

Not included — consumer R8 keep rules for Coil 3 ServiceLoader descriptors. With the fetcher registered in code, those only matter for integrators building a fully custom ImageLoader, which is already covered by the docs.

Testing

  1. ./gradlew :stream-chat-android-ui-common:testDebugUnitTest --tests "StreamImageLoaderFactoryTest" — includes a new assertion that fetcherFactories contains a NetworkFetcher.Factory.
  2. Build a minified release of stream-chat-android-compose-sample on a device that previously reproduced the blank-image symptom, open a channel with image attachments, confirm images load without any integrator-side fetcher registration.
  3. Run the Compose sample in debug — images, GIFs, and video thumbnails render as before.

No UI changes.

Summary by CodeRabbit

  • Chores
    • Enhanced image loading reliability through improved network configuration.

Coil 3 auto-registers OkHttpNetworkFetcherFactory via ServiceLoader, which R8 can strip in release builds, leaving HTTP image loading without a fetcher and rendering only placeholders. Adding it directly to the component registry removes the ServiceLoader dependency for the default SDK path.

(cherry picked from commit 183e0f6)
@andremion andremion requested a review from a team as a code owner April 27, 2026 09:33
@andremion andremion added the pr:improvement Improvement label Apr 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 27, 2026

PR checklist ✅

All required conditions are satisfied:

  • Title length is OK (or ignored by label).
  • At least one pr: label exists.
  • Sections ### Goal, ### Implementation, and ### Testing are filled.

🎉 Great job! This PR is ready for review.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 27, 2026

Walkthrough

The changes explicitly register OkHttpNetworkFetcherFactory in the Coil image loader configuration within StreamImageLoaderFactory and add a unit test verifying that the network fetcher factory is registered even when ServiceLoader-based discovery is disabled.

Changes

Cohort / File(s) Summary
Coil Network Fetcher Configuration
stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/images/StreamImageLoaderFactory.kt
Added import and registration of OkHttpNetworkFetcherFactory() to the image loader component registry prior to decoder components.
Unit Test for Network Fetcher Registration
stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/images/StreamImageLoaderFactoryTest.kt
New test verifying that NetworkFetcher.Factory is registered in image loader components even when ServiceLoader is disabled via serviceLoaderEnabled(false).

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • PR #6384: Makes the identical code-level change—explicitly registering OkHttpNetworkFetcherFactory in StreamImageLoaderFactory with corresponding unit test assertion.

Suggested reviewers

  • gpunto

Poem

🐰 A fetcher hop-hops into place,
OkHttp's factory joins the race,
No ServiceLoader needed here,
The network path is crystal clear!
Tests affirm what we all know,
Coil's components steal the show! 🎨

🚥 Pre-merge checks | ✅ 4 | ❌ 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 (4 passed)
Check name Status Explanation
Description check ✅ Passed The description covers Goal and Implementation thoroughly, includes Testing details, and explains why UI changes are not applicable. While some optional sections (UI Changes, GIF, Contributor Checklist) are incomplete, the critical information is present and complete.
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.
Title check ✅ Passed The title accurately and concisely describes the main change: explicitly registering the OkHttp network fetcher in the default image loader, which directly addresses the ServiceLoader stripping issue in R8 full-mode.

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

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/coil-image-loader-v6

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/images/StreamImageLoaderFactory.kt (1)

38-48: ⚠️ Potential issue | 🟡 Minor

Minor: KDoc claim about "cache control and optimized network dispatcher" no longer matches the code.

The class KDoc still advertises "OkHttp with cache control and optimized network dispatcher", but OkHttpNetworkFetcherFactory() is now constructed with no OkHttpClient/cache configuration, so Coil will use its defaults. Consider either passing a configured OkHttpClient (with the cache/dispatcher you intend) or trimming the KDoc to reflect what's actually configured here.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/images/StreamImageLoaderFactory.kt`
around lines 38 - 48, The KDoc for StreamImageLoaderFactory is out of date: it
claims "OkHttp with cache control and optimized network dispatcher" but the
implementation constructs OkHttpNetworkFetcherFactory() without a configured
OkHttpClient; either supply a preconfigured OkHttpClient (with cache and custom
Dispatcher) into OkHttpNetworkFetcherFactory when building the ImageLoader, or
remove/adjust that phrase in the KDoc to accurately reflect that Coil's default
OkHttp client is used; locate the StreamImageLoaderFactory class and the
OkHttpNetworkFetcherFactory() usage to apply the fix.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In
`@stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/images/StreamImageLoaderFactory.kt`:
- Around line 38-48: The KDoc for StreamImageLoaderFactory is out of date: it
claims "OkHttp with cache control and optimized network dispatcher" but the
implementation constructs OkHttpNetworkFetcherFactory() without a configured
OkHttpClient; either supply a preconfigured OkHttpClient (with cache and custom
Dispatcher) into OkHttpNetworkFetcherFactory when building the ImageLoader, or
remove/adjust that phrase in the KDoc to accurately reflect that Coil's default
OkHttp client is used; locate the StreamImageLoaderFactory class and the
OkHttpNetworkFetcherFactory() usage to apply the fix.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 934302c1-4a95-4462-a426-88abba85239b

📥 Commits

Reviewing files that changed from the base of the PR and between 80adbff and 8f59192.

📒 Files selected for processing (2)
  • stream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/images/StreamImageLoaderFactory.kt
  • stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/images/StreamImageLoaderFactoryTest.kt

@github-actions
Copy link
Copy Markdown
Contributor

SDK Size Comparison 📏

SDK Before After Difference Status
stream-chat-android-client 5.26 MB 5.26 MB 0.00 MB 🟢
stream-chat-android-offline 5.49 MB 5.49 MB 0.00 MB 🟢
stream-chat-android-ui-components 10.64 MB 10.65 MB 0.00 MB 🟢
stream-chat-android-compose 12.87 MB 12.87 MB 0.00 MB 🟢

@andremion andremion changed the title (Port to v6) Register the OkHttp network fetcher explicitly in the default image loader (backport from v7) Register the OkHttp network fetcher explicitly in the default image loader Apr 27, 2026
@sonarqubecloud
Copy link
Copy Markdown

@andremion andremion enabled auto-merge (squash) April 27, 2026 10:01
@andremion andremion merged commit 00be390 into v6 Apr 27, 2026
23 of 25 checks passed
@andremion andremion deleted the chore/coil-image-loader-v6 branch April 27, 2026 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:improvement Improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants