fix(webview): Support multiple WebView instances in Old Architecture#1062
fix(webview): Support multiple WebView instances in Old Architecture#1062Woody-FE wants to merge 1 commit intoDataDog:developfrom
Conversation
Remove _isWebViewTrackingEnabled flag that was preventing multiple WebView instances from receiving RUM session tracking. The flag was stored at the ViewManager level (singleton-like), causing all WebView instances to share it. Once the first WebView enabled tracking, subsequent WebViews hit the early return and never called WebViewTracking.enable(). Each WebView is an independent instance and should have its own tracking enabled. Also updated tests to remove assertions on the removed flag. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
2e40bfd to
51233fa
Compare
|
Hello @Woody-FE! 👋 Thank you so much for your contribution 🙏 We missed this use case because we don't currently have this specific scenario covered in our automated tests for old architecture. Sorry about the trouble this caused. We'll review the PR shortly and incorporate the fix into PR#1060, which contains some further WebView changes for old architecture. I'll keep you posted on the progress. Thanks again! |
If you end up incorporating my changes directly into PR #1060 instead of merging this PR as is, would it be possible to keep my contribution attributed (e.g., via a Co-authored-by trailer or similar)? Totally fine either way, just wanted to check what your usual practice is. |
What does this PR do?
Fixes a bug in the Android Old Architecture WebView implementation where only the first WebView instance receives RUM session tracking. Subsequent WebView instances are incorrectly skipped, causing their sessions to be disconnected from the native RUM session.
Motivation
The
_isWebViewTrackingEnabledflag is stored at the ViewManager level (singleton-like), causing all WebView instances to share this flag. Once the first WebView enables tracking and sets this flag totrue, all subsequent WebViews hit the early return and never callWebViewTracking.enable().Before (buggy):
After (fixed):
Each WebView is an independent instance and should have its own tracking enabled.
iOS vs Android Comparison
The iOS implementation correctly handles multiple WebViews by storing the
isTrackingEnabledflag at the WebView instance level, while Android Old Architecture incorrectly stores it at the Manager level (singleton).RCTDatadogWebView.isTrackingEnabled(per instance)DdSdkReactNativeWebViewManager._isWebViewTrackingEnabled(singleton)This fix aligns Android Old Architecture behavior with the iOS implementation.
Side Effect Analysis
Removing the flag is safe because:
setAllowedHostsis only called when the React prop changes, typically once per WebView lifecycle.WebViewTracking.enable()calls: Harmless. The native Datadog SDK handles re-registration gracefully.Additional Notes
DatadogWebViewTest.ktto remove assertions on the removedisWebViewTrackingEnabledflagReview checklist (to be filled by reviewers)