bjerkio/oidc-react

Silent renew not working when in Strict Mode

Episodex opened this issue · 1 comments

I had a problem, similar to #361 except the PR merged then didn't fix my problem. It turned out that AuthContext is being mounted twice when React is in Strict mode. This causes this line to run: isMountedRef.current = false; and nothing then sets it back to true. Which effectively disables updating user info:

isMountedRef.current && setUserData(user);
.

I fixed it by setting isMountedRef.current to true on every mount:

useEffect(() => {
    isMountedRef.current = true; // <-- my change
    return () => {
      isMountedRef.current = false;
    };
  }, []);

I'm not sure if it's the right way, but it seems to solve the problem for me. Maybe it's worth adding to the repo.