fix(animated): use WeakMap cache in createHost - #2558
Conversation
…pring umbrella (pmndrs#2526) Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Patrick Wehbe <patrick.wehbe.applications@gmail.com>
🦋 Changeset detectedLatest commit: 4ccc219 The changes in this PR will be included in the next version bump. This PR includes changesets to release 9 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 |
…mponents Isolate PR pmndrs#2558 onto next — single commit.
763ecd3 to
aaef064
Compare
|
WeakMap swap looks right. CI is failing on formatting only. The else block in createHost.ts is over-indented so oxfmt fails. Run pnpm format and push. Optional: the nested if/else can be one branch. } else {
let cached = animatedComponentCache.get(Component)
if (!cached) {
cached = withAnimated(Component, hostConfig)
animatedComponentCache.set(Component, cached)
}
Component = cached
} |
|
Done — formatted and pushed. The else branch now uses your suggested shape (let cached + single set), and the branch is a single commit on |
|
you targetted the wrong base branch, if you check |
joshuaellis
left a comment
There was a problem hiding this comment.
needs correct rebase target branch
Summary
On React Native (Hermes), host components (
View,Text,Image) become non-extensible after their first JSX render.createHostpreviously stashed the animated wrapper directly on the component:With Metro
inlineRequires+experimentalImportSupport,@react-spring/nativecan first be required during a render — by which point Hermes has locked the host component shapes — socreateHostthrewTypeError: cannot add a new property, and Metro'sguardedLoadModuleswallowed it returningundefined, cascading intoCannot read property 'useSpring' of undefined.Changes
Symbol.for('AnimatedComponent')property with a module-levelWeakMapcache increateHost.createHost.test.ts) that freezes a fake host component and assertsanimated()neither throws nor returns the same reference.Test plan
packages/animated/src/createHost.test.ts(new)@react-spring/animated: patchLinks