fix(Android): make fragment restoration R8-safe - #4539
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (6)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthroughThe Android restoration logic adds an ChangesFragment restoration identification
Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The PR makes Android fragment restoration resilient to R8 class repackaging, with no actionable merge-blocking risk remaining after normal checks and review. Suggested reviewers: Sequence Diagram(s)sequenceDiagram
participant RNScreensFragmentFactory
participant RNScreensFragment
participant AutoRemovingFragment
participant FragmentFactory
RNScreensFragmentFactory->>RNScreensFragmentFactory: Load className
RNScreensFragmentFactory->>RNScreensFragment: Check assignability
alt Class implements RNScreensFragment
RNScreensFragmentFactory->>AutoRemovingFragment: Instantiate replacement fragment
else Class does not implement RNScreensFragment
RNScreensFragmentFactory->>FragmentFactory: Delegate instantiate
end
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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 |
|
Superseded by #4540, which uses the contributor branch |
Description
Closes #4505.
RNScreensFragmentFactorycurrently identifies screen fragments by checking whether the restored class name starts with the library package. R8 can repackage those classes when optimized resource shrinking is enabled, so the check falls through to normal fragment restoration and the screen fragment constructor throws.This change makes restoration independent of class and package names.
Changes
RNScreensFragmentmarker for fragments owned by the library.RNScreensFragmentFactoryto load the fragment class and check the marker withisAssignableFrombefore substitutingAutoRemovingFragment.Test plan
Used the maintainer-confirmed reproducer from https://github.com/t0maboro/RNS4505 with React Native 0.86.2,
android.r8.optimizedResourceShrinking=true, minification, and resource shrinking enabled.Control (
react-native-screens4.25.0):ScreenFragmentandScreenStackFragmenttov3.Dandv3.N.Unable to instantiate fragment v3.NandScreen fragments should never be restored.Patched build from this branch:
com.swmansion.rnscreens.Additional checks:
yarn lint-androidyarn check-typesFabricExample/android/gradlew :app:assembleDebug --console=plain -PreactNativeArchitectures=arm64-v8aandroid/gradlew :app:assembleRelease --console=plain -PreactNativeArchitectures=arm64-v8aChecklist
Summary by CodeRabbit