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

fix: do not update during render #467

Merged
merged 2 commits into from
Mar 31, 2024

Conversation

SantoJambit
Copy link
Contributor

@SantoJambit SantoJambit commented Mar 21, 2024

I've noticed that, probably due to concurrent rendering in react 18, setState within useCookies is being called from within a render of another component:

  • Component A calls useCookies()
  • Component B calls useCookies([keyX])
  • React complains, that component B sets the state of component A during render (as cookies.getAll() triggers listeners)

Our fix was to always pass the keys to useCookies, but since that might not always be an option, I think this should be the correct solution to the issue.

@eXon
Copy link
Collaborator

eXon commented Mar 22, 2024

@SantoJambit Thank you for opening a PR on this issue! This change seems very reasonable. I can see how it will avoid side-effects like this. We can include this in the next release. Would you mind fixing the formatting? You can just run npx prettier . --write and commit the result, it should be good.

@eXon eXon merged commit 2d45788 into bendotcodes:main Mar 31, 2024
1 check passed
@SantoJambit SantoJambit deleted the fix/no-update-during-render branch April 2, 2024 08:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants