Fix ChatTheme crashing previews when ChatClient is not initialized#6366
Conversation
…ent is not initialized Co-Authored-By: Claude <noreply@anthropic.com>
PR checklist ✅All required conditions are satisfied:
🎉 Great job! This PR is ready for review. |
ChatTheme crashing previews when ChatClient is not initialized
SDK Size Comparison 📏
|
|
WalkthroughThe changes refactor image loading to use lazy CDN resolution instead of eager initialization. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/images/internal/CDNImageInterceptorTest.kt (1)
146-157: Exercise the real preview path in this regression test.
CDNImageInterceptor { null }only validates the injected-null branch. The crash was in the defaultCDNImageInterceptor()supplier touchingChatClient, so an eager-access regression there would still pass here. Prefer leavingChatClientuninitialized and constructing the interceptor with its default args.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/images/internal/CDNImageInterceptorTest.kt` around lines 146 - 157, The test currently constructs the interceptor with CDNImageInterceptor { null } which only exercises the injected-null branch; change the test to construct the interceptor with its default constructor (use CDNImageInterceptor() instead of the lambda) so the real preview path that touches ChatClient is exercised, keep the rest of the setup (ImageRequest.Builder(...), FakeCoilChain(request)) and the final assertion that chain.directProceed is true; ensure no ChatClient is initialized in the test setup so the default supplier runs against an uninitialized ChatClient.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/images/internal/CDNImageInterceptorTest.kt`:
- Around line 146-157: The test currently constructs the interceptor with
CDNImageInterceptor { null } which only exercises the injected-null branch;
change the test to construct the interceptor with its default constructor (use
CDNImageInterceptor() instead of the lambda) so the real preview path that
touches ChatClient is exercised, keep the rest of the setup
(ImageRequest.Builder(...), FakeCoilChain(request)) and the final assertion that
chain.directProceed is true; ensure no ChatClient is initialized in the test
setup so the default supplier runs against an uninitialized ChatClient.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: 2106cd1b-2827-4f01-877a-1d4092b86469
📒 Files selected for processing (4)
stream-chat-android-compose/src/main/java/io/getstream/chat/android/compose/ui/theme/ChatTheme.ktstream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/images/internal/CDNImageInterceptor.ktstream-chat-android-ui-common/src/main/kotlin/io/getstream/chat/android/ui/common/images/internal/StreamCoil.ktstream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/images/internal/CDNImageInterceptorTest.kt
|
🚀 Available in v6.37.2 |


Goal
Fix
ChatThemecrashing withChatClient is not initializedin Compose previews and VRT tests. This was caused byChatClient.instance().cdnbeing called eagerly at composition time, which fails whenChatClienthasn't been built yet.Implementation
CDNImageInterceptorto resolve theCDNlazily via a() -> CDN?provider instead of taking a directCDNinstance. The default provider safely checksChatClient.isInitializedbefore accessing the instance.ChatThemenow always installs theCDNImageInterceptor(with the lazy default). WhenChatClientis not initialized, the interceptor is a no-op pass-through. When it is initialized later, the next image request picks up the CDN automatically.StreamCoil(XML view system path).imageLoaderFactoryparameter to document CDN + interceptor interaction.UI Changes
No UI changes.
Testing
CDNImageInterceptorTesttests updated and passing.intercept passes through when cdn returns nullcovers the preview/VRT scenario.StreamCoilImageLoaderFactorystill works correctly (interceptors silently dropped by default two-arg fallback, customer's loader returned as-is).Summary by CodeRabbit
Bug Fixes
Documentation