-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useSprings does not properly clear controllers when length changes in React.StrictMode #1532
Comments
This looks like it was brought about in this commit – 9176c5a Might have been when I used This fix shouldn't be too hard, if youre interested in giving it a go and contributing! ⭐ |
might have some time this week, thanks! |
oh hm, if im reading it correctly, these tests create a new useSpring hook instance every time |
No it doesn't because you don't destroy the spring when you update the props because of internal state etc.
|
It's |
Might be something to do with this – https://reactjs.org/docs/strict-mode.html#detecting-unexpected-side-effects specifically:
|
interesting re: removing strictmode fixing the bug in CSB. i can dig into that too however, my original point that i cannot repro in the cloned react-spring monorepo still stands — i had strictmode on there, too, and it works "fine". i added the CSB source code to ideally we could test for this so i'm just trying to get a local repro, bc i have no idea how i can fix this in the CSB environment as it's referencing an npm package |
I think I built the package and changed the web alias from |
sorry i dropped off, life happend! so to make sure i undersatnd — you built this repo locally and moved the dist JS files into the CSB (or a cloned CSB locally). i havent done much aliasing before — how does that work? do you just change the import statement to be |
in import path from 'path'
import { defineConfig } from 'vite'
import reactRefresh from '@vitejs/plugin-react-refresh'
export default defineConfig({
resolve: {
alias: {
'@react-spring/web': path.resolve('../targets/web/src/index.ts'),
'@react-spring/parallax': path.resolve(
'../packages/parallax/src/index.tsx'
),
'@react-spring/three': path.resolve('../targets/three/src/index.ts'),
},
},
plugins: [reactRefresh()],
}) This is where we alias the packages to the src code. Running |
Maybe make a PR? It's easier to review that way and our CI will start building some sandboxes for us at the same time so we can review a bit better. |
🐛 Bug Report
When changing the length provided to useSprings in combination with a propsFn, the internal SpringRef does not properly dispose of the old refs when the array changes.
To Reproduce
See CSB
Expected behavior
See CSB, while the springs are correctly oscillating between lengths of 8 and 9, the api.current controllers always increase.
![image](https://user-images.githubusercontent.com/1629901/120428435-4306bf80-c339-11eb-97b0-935112f1c67d.png)
Link to repro (highly encouraged)
https://codesandbox.io/s/elastic-hofstadter-m48zc?file=/src/UserTiles.jsx
Environment
react-spring
v9.2.1react
v17.0.2The text was updated successfully, but these errors were encountered: