Skip to content
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

Rerun Atom Effects when Atom is reset or refreshed #1685

Closed
SunilChiluvuri opened this issue Mar 19, 2022 · 3 comments
Closed

Rerun Atom Effects when Atom is reset or refreshed #1685

SunilChiluvuri opened this issue Mar 19, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@SunilChiluvuri
Copy link

when using Atom Effects, if the atom is reset using useResetRecoilState, the atom value is set to default but effects are not rerun.
Is there a way to "reinitialize" the atom which causes the Atom Effects to be rerun?. If not, is one in the works?
Thanks for Recoil its great to have minimal boilderplate

@drarmstr
Copy link
Contributor

I don't know that re-running them with a reset would be appropriate. It's debatable, but it would be a breaking change. Another option been considering is re-running them with the "refresh" API. The potential concern there would be potentially implicitly doing that for upstream atoms since refreshing a selector defaults to transitively refreshing upstream selectors.

For now, you can manually achieve this with the onSet() atom effect callback checking the isReset flag

@SunilChiluvuri
Copy link
Author

Thanks. I was able to use the suggested and change the atom value on reset but I see an error
releaseNodesNowOnCurrentTree should only be called at the end of a batch undefined at Batcher (http://localhost:3000/static/js/bundle.js:52027:5) at RecoilRoot_INTERNAL (http://localhost:3000/static/js/bundle.js:52117:5) at RecoilRoot (http://localhost:3000/static/js/bundle.js:52283:5) overrideMethod @ react_devtools_backend.js:3973 recoverableViolation @ recoil.js:519 releaseRetainablesNowOnCurrentTree @ recoil.js:2982 releaseScheduledRetainablesNow @ recoil.js:3226 endBatch @ recoil.js:4163 (anonymous) @ recoil.js:4198 enqueueExecution @ recoil.js:663 (anonymous) @ recoil.js:4197 invokePassiveEffectCreate @ react-dom.development.js:23487 callCallback @ react-dom.development.js:3945 invokeGuardedCallbackDev @ react-dom.development.js:3994 invokeGuardedCallback @ react-dom.development.js:4056 flushPassiveEffectsImpl @ react-dom.development.js:23574 unstable_runWithPriority @ scheduler.development.js:468 runWithPriority$1 @ react-dom.development.js:11276 flushPassiveEffects @ react-dom.development.js:23447 (anonymous) @ react-dom.development.js:23324 workLoop @ scheduler.development.js:417 flushWork @ scheduler.development.js:390 performWorkUntilDeadline @ scheduler.development.js:157

@drarmstr
Copy link
Contributor

@SunilChiluvuri - That's an invalid error message which can be ignored. It was fixed with #1589 / #1582 . Looks like that hasn't been included in the latest open-source release, but should be included with the upcoming 0.7 release.

@drarmstr drarmstr changed the title Rerun Atom Effects when Atom is reset Rerun Atom Effects when Atom is reset or refreshed Mar 22, 2022
@drarmstr drarmstr added the enhancement New feature or request label Mar 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants