javascript icon indicating copy to clipboard operation
javascript copied to clipboard

getToken changes after each render

Open marjan-pluto opened this issue 3 years ago • 1 comments

  • [X] Review the documentation: https://docs.clerk.dev/
  • [X] Search for existing issues: https://github.com/clerkinc/javascript/issues
  • [X] Go through package changelog files.
  • [ ] Provide the Frontend API key from your application dashboard.

Package + Version

  • [ ] @clerk/clerk-js
  • [X] @clerk/clerk-react
  • [ ] @clerk/nextjs
  • [ ] @clerk/remix
  • [ ] @clerk/clerk-expo
  • [ ] @clerk/backend-core
  • [ ] @clerk/clerk-sdk-node
  • [ ] @clerk/edge
  • [ ] other:

Version:

^3.2.7

Browser/OS

Chrome latest

Description

We started migrating to v3 and noticed getToken from useAuth function identity is not stable and as a result changes after each re-render.

This causes the the app to go into infinite loop when getToken is used in the dependancy array of something like useEffect. Usage Snippet: image

A workaround is to remove it from the dependancy array, however that does not make eslint happy image

It would be ideal if getToken can be made stable as it was in v2.

marjan-pluto avatar Apr 18 '22 15:04 marjan-pluto

Hello @marjan-pluto ! Many thanks for reporting this one :)

getToken doesn't need to be in the dependency array, but I can see why this is problematic. Your comment about eslint makes perfect sense.

I'll be working on this during the next few days, and I'll ping you here when we push a fix. Thanks again!

nikosdouvlis avatar Apr 29 '22 07:04 nikosdouvlis

if getToken is not needed, update the docs folks until this is resolved...I was trying to setState following the example from the docs below and I was getting an infinite loop because of the getToken... https://clerk.dev/docs/integration/firebase#:~:text=29-,%7D%2C%20%5BgetToken%5D)%3B,-30

waldothedeveloper avatar Feb 22 '23 22:02 waldothedeveloper

@waldothedeveloper thank you for reporting it. We have updated our docs.

dimkl avatar Feb 28 '23 12:02 dimkl

The problem described by this issue hasn't been resolved, has it? If not, it seems to me like this issue should remain open.

rjdellecese avatar Feb 28 '23 17:02 rjdellecese

Hello everyone, the fix will be shipped with our next release.

nikosdouvlis avatar Mar 24 '23 21:03 nikosdouvlis