fix: reset color on view recycle so currentColor does not leak between recycled SVG views (iOS, Fabric) - #2991
Open
aaronhu-apex wants to merge 1 commit into
Conversation
…n recycled SVG views on iOS Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2566.
On the new architecture, iOS recycles component views by default.
RNSVGSvgViewhas two compounding issues that make the recycled view keep the previous instance'scolor:updateProps:only assignsself.colorwhen the incoming color is non-null — an SVG mounted without acolorprop never overwrites the recycled view's stale value:prepareForRecycleresets viewBox / bounding-box / transform state but not_color.Since
currentColorresolution walks up the tree and terminates at the root svg view'scolor(RNSVGRenderable getCurrentColor), any element rendered withstroke="currentColor"/fill="currentColor"and no explicit color up its chain paints with whatever color the recycled root happened to carry from its previous life. This is exactly the intermittent wrong-color symptom in #2566: it depends on recycle-pool order, typically shows up after navigation (screens/sheets unmounting), and a reload "fixes" it.This is very easy to hit with
lucide-react-native, where every icon isstroke="currentColor"by default: render one icon withcolor="white"on screen A (its svg root view getscolor = white, then gets recycled), then mount an icon with nocolorprop on screen B — it intermittently renders white.The fix: assign
self.colorunconditionally inupdateProps:(nil clears it, matching a prop that was unset or removed), and reset_color = nilinprepareForRecyclealongside the other fields.Impact:
apple/Elements/RNSVGSvgView.mmonly.Test Plan
Reproduced in a React Native app (Expo SDK 57 / RN 0.86, new architecture) where lucide icons intermittently rendered white after closing a bottom sheet containing
color="white"icons — a header back-arrow (<ArrowLeft size={24} />, no color prop) picked up the recycled white root. Applied this change via patch-package, rebuilt, and the wrong-color rendering no longer occurs.What's required for testing (prerequisites)?
iOS app on the new architecture with view recycling active (default).
What are the steps to reproduce (after prerequisites)?
currentColorwith an explicit root color, e.g.<SomeLucideIcon color="white" />(or any<Svg color="red">withstroke="currentColor"children).currentColorwithout acolorprop.Compatibility
Checklist
README.md__tests__folder🤖 Generated with Claude Code