oidc-react icon indicating copy to clipboard operation
oidc-react copied to clipboard

Bug with reactStrictMode (<StrictMode/>)

Open AlexanderKositsyn opened this issue 3 years ago • 1 comments

React calls useEffect this one twice in strictMode. It results in error No matching state found in storage. I found a solution to fix this by disabling this mode. I work with nextjs so I just remove reactStrictMode: true from next.config.js. So I decided to create issue for people who will get this bug 😄

AlexanderKositsyn avatar Sep 05 '22 14:09 AlexanderKositsyn

I've noticed the same thing in my project

bdekok avatar Sep 23 '22 11:09 bdekok

Disabling strict mode is not recommended because, without it, you won't benefit from it's warning about side effects and more. Instead, it might be better to put the strict mode node after the authentication component. So at least, everything under the auth component will benefit from stric mode.

Ex : ... <Authentication <StrictMode <---- below the auth <other stuff/ </StrictMode </Authentication

The best would be that the second re-render is supported by the lib tho.

mathieu-fournier avatar Jan 17 '23 23:01 mathieu-fournier

I have a problem with that too. The second trigger interrupts sometimes (race condition) the first redirect what leads to an error in firefox.

Putting AuthProvider outside of StrictMode is a problem, because AuthProvider must be inside BrowserRouter to redirect after login, but idk, if it is an problem if BrowserRouter is outside of StrictMode

wutzebaer avatar Jan 26 '23 13:01 wutzebaer

@wutzebaer

StricMode is a development tool that warns us about possible unwanted side-effect and other common issues that happens in react. So to answer your question, it's up to you to decide if it's a problem of not. https://reactjs.org/docs/strict-mode.html

In my opinion, it;s not a problem if BrowserRouter is outside of strict mode. Since routing usually happens only once.

Hope it helps (:

mathieu-fournier avatar Jan 26 '23 14:01 mathieu-fournier

@mathieu-fournier thank you for clarification

cardano-tools-nft avatar Jan 26 '23 18:01 cardano-tools-nft

I have similar issue with StrictMode in Firefox (it's not an issue on chromium). Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource. or Uncaught (in promise) AbortError: The operation was aborted

It says error happens in the _signinStart function in oidc-react.js

async signinRedirect(args = {}) {
  this._logger.create("signinRedirect");
  const {
    redirectMethod,
    ...requestArgs
  } = args;
  const handle = await this._redirectNavigator.prepare({ redirectMethod });
  await this._signinStart({
    request_type: "si:r",
    ...requestArgs
  }, handle);
}

Limiting StrictMode to only be enabled after authentication is done isn't ideal.

Darhagonable avatar Feb 01 '23 15:02 Darhagonable

This should be fixed by #962

jamesdh avatar Mar 11 '23 14:03 jamesdh