fix(animated): WeakMap fallback for non-extensible component caching#2535
Open
AndreiCalazans wants to merge 3 commits into
Open
fix(animated): WeakMap fallback for non-extensible component caching#2535AndreiCalazans wants to merge 3 commits into
AndreiCalazans wants to merge 3 commits into
Conversation
On Hermes (React Native), host components like View, Text, and Image become non-extensible after their first JSX render. The existing cache mechanism writes directly to Component[cacheKey], which throws 'cannot add a new property' in strict mode for these objects. Fix: attempt the direct write first (fast path for extensible components), catch the TypeError, and fall back to a module-level WeakMap for non-extensible components. Reproduces with Metro inlineRequires:true + experimentalImportSupport:true when @react-spring/native is loaded lazily inside a component render.
🦋 Changeset detectedLatest commit: c211263 The changes in this PR will be included in the next version bump. This PR includes changesets to release 12 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
joshuaellis
requested changes
Jun 9, 2026
joshuaellis
left a comment
Member
There was a problem hiding this comment.
it'd be great to get a failing test for this & a changeset.
joshuaellis
previously approved these changes
Jun 9, 2026
Member
|
Looks like there's some TS errors that need to be solved. |
…tableComponent type
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.
Fixes #2533
Problem
createHostcaches animated wrappers viaComponent[cacheKey] = .... On Hermes, React Native host components (View,Text,Image) become non-extensible after their first JSX render — writing a new property throwsTypeError: cannot add a new propertyin strict mode.This crashes
@react-spring/native's module initialization when loaded lazily (e.g. with MetroinlineRequires: true), becausecreateHostruns at module scope iterating over those exact primitives.Fix
Try the direct write first (fast path, no change for extensible components). On failure, fall back to a module-level
WeakMap.Context
This was found while enabling Metro's
inlineRequires: true+experimentalImportSupport: truein a large React Native monorepo. A local Yarn patch on@react-spring/animated@10.0.3with this exact fix is already shipping in production while we wait for an upstream release: https://coinbase.ghe.com/consumer/react-native/pull/new/acalazans/metro-inline-requires-enable