-
Notifications
You must be signed in to change notification settings - Fork 7
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
useAtomSelector
doesn't work with useAtomContext
instances
#83
Comments
Thank you @Aleksion for reporting! It looks like this is due to StrictMode changes in React 18. You can see this in the sandbox by either removing StrictMode in Removing StrictMode is an easy fix. But obviously, Zedux is supposed to be compatible with it. This is a confirmed bug. Initial findings: It looks like React no longer calls the I'll spend some time today switching all the tests to use StrictMode. We should be doing that anyway. Looks like 3 tests fail in StrictMode that would have caught this. As for the real fix, I can probably get something quick and dirty in pretty quickly. But I actually already have a branch where I switched |
Thank you for the quick response! |
any updates on this @bowheart? |
Hey @Aleksion sorry I spent some time at Disney World a couple weeks ago and was busy getting back to work last week. I've basically decided on a hybrid approach. Instead of switching off of This is a pretty involved change. I'm actively working on it. Will probably take a couple days to get a new version published. |
Hi, Just wanted to check on this 🙈 Don't mean to apply pressure, but I'm moving into production and I like getting reactStrictMode back on 😂 (I also know that it's open source so it is what it is. Just wanted to understand if it's still on track). Thank you for the amazing work you've done here! |
Hey @Aleksion pressure away! It's good for me. TL;DR this change has suffered some feature creep. But it's really a good thing, fixing a few outstanding issues. Longer explanation: I actually got all the tests passing about when I thought I would (a few days after my last message), but it's a big enough change that I wanted to add more tests and play with it in a test project for a bit. And it's a good thing I did because I discovered a new problem in strict mode that requires another rework to inline selectors passed to The core of the change is that both This fault is only possible (or at least only possibly problematic) in dev strict mode as far as I can tell. But I'd still call it a must fix. So for the fix: I'm making Other outstanding issues that this fixes:
Additionally, these changes do completely get rid of For time frame, I'm shooting to have all of this done and tested this week. If performance looks good, I'll publish a release candidate by the end of this week. |
@Aleksion a preemptive heads up this time. I'm almost there. I'll try to snag a couple hours to finish this and get a release out tomorrow |
@Aleksion The fix for this has been released in version I've verified that it fixes your codesandbox here: https://codesandbox.io/s/useatomselector-react-context-t5dcps If you get a minute, could you try out the release candidate version and verify that it fixes the issue in your app? I'm going to do some heavy testing with the release candidate version and if all goes well will probably release version |
Hi @bowheart, Just did a test, and it seems like useAtomSelector with dynamic selectors causes infinite loops: |
Version |
ohhh... I think this might have done the trick. |
@bowheart I think I might have found another bug:
![]() ![]() |
@Aleksion I haven't been able to reproduce this. Are you perhaps seeing the double-renders from StrictMode? const idAtom = atom('id', () => ({ _id: '123' }))
const selector = (
{ get }: AtomGetters,
instance: AtomInstanceType<typeof idAtom>
) => get(instance)._id
function Test() {
const [state, setState] = useState(1)
const instance = useAtomInstance(idAtom)
const val = useAtomSelector(selector, instance)
console.log('rendered component', state)
return (
<div>
Selector val: {val}, state: {state}{' '}
<button onClick={() => setState(s => s + 1)}>Increment</button>
<button onClick={() => instance.setState(s => ({ _id: s._id + 1 }))}>
Update Atom
</button>
</div>
)
} This (perhaps over-simplified?) example renders the component once for each click of each button outside StrictMode, and twice for each click of each button when wrapped in StrictMode, as expected. If you could modify this code snippet to make it trigger excess renders beyond that, that would be a great help |
Zedux Version
"@zedux/react": "1.1.1",
Description
useAtomSelector
doesn't trigger a re-render when used withuseAtomContext
.But, any other re-render in the component will cause the selector to register and work as intended.
Try making a change in the code in the code sandbox, and you'll see it start to synchronize.
Reproduction
https://codesandbox.io/s/epic-snow-pxyvym?file=/src/App.js:0-1823
The text was updated successfully, but these errors were encountered: