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

Can't perform a React state update on an unmounted component

Open phatntfe opened this issue 6 years ago • 12 comments

I am using react-facebook to embed in my website. But I get an error below. Tell me how I can fix it

This's warning message: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.

I'm using React v16.4.0

const FanpageFacebook = () => (
  <>
    <BoxTitle title="Fanpage" showViewMoreButtom={false} />
    <div className="bg-white flex p-2.5 mb-2px">
      <FacebookProvider
        appId="469469066915707
"
      >
        <Page
          href="https://www.facebook.com/khotailieumienphi.tk"
          tabs="timeline"
        />
      </FacebookProvider>
    </div>
  </>
);

phatntfe avatar Dec 27 '18 00:12 phatntfe

Same problem

artemiokost avatar Jan 11 '19 19:01 artemiokost

Same Propblem here

Maggistro avatar Feb 05 '19 11:02 Maggistro

Same Propblem here

I have fixed that issue with adding this._isMounted flag in componentDidMount (set true) and unmount(set false). Before widget invoke I check this state in component.

artemiokost avatar Feb 08 '19 15:02 artemiokost

Still getting this error when doing a specific flow.

I am opening a Facebook modal by clicking on my Login With Facebook button.

Navigating to a new page, and closing the modal. It's then trying to update state on the page where the modal was originally created.

benwolfram avatar Mar 13 '19 21:03 benwolfram

can you add your stacktrace?

seeden avatar Mar 13 '19 21:03 seeden

I have the same issue. After experimenting I have noticed it happens when I pass an onCompleted handler to the LoginButton, but not when I pass an onSuccess handler.

My limited stacktrace is below:

index.js:2178 Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method. in Process (created by ForwardRef) in ForwardRef (created by LoginButton) in LoginButton (created by ConnectedAccounts)

crueschenberg avatar Sep 30 '19 23:09 crueschenberg

Same problem, any updates for this issue ? @seeden Screen Shot 2019-12-10 at 10 27 41 PM Screen Shot 2019-12-10 at 10 28 35 PM

digzit avatar Dec 11 '19 03:12 digzit

This happens if I call another action in the callback Screen Shot 2019-12-12 at 5 45 47 PM

digzit avatar Dec 12 '19 22:12 digzit

I'm still getting this warning after updating to version 8.1.4. It appears #125 is supposed to fix this, but I still get the warning. Any suggestions? It only happens when I navigate to the route directly, rather than being routed to it from the homepage.

Here's my button:

const FacebookButton = ({ appId, version, scope, onSuccess, children }) => {  
  return (
    <FacebookProvider appId={appId} version={version}>
      <Login
        scope={scope}
        onCompleted={handleResponse}
        onSuccess={() => onSuccess(result)}
        onError={handleError}
      >
        {({ loading, handleClick, error, data }) => (
          <div onClick={handleClick}>
            {children ? children : <DefaultButton loading={loading} />}
          </div>
        )}
      </Login>
    </FacebookProvider>
  );
};

Here it is used on my login page:

class LoginPage extends Component {
  onSuccess = data => {
    this.props.actions.User.login(data);
  };

  render() {
    if (this.props.isLoggedIn) return <Redirect to="/dashboard" />;
    return (
      <div>
        <h1>Login Page</h1>
        <FacebookButton {...btnConfig} onSuccess={this.onSuccess} />
      </div>
    );
  }
}

Here's a screenshot of the console warning: image

halshing avatar Dec 22 '19 21:12 halshing

Anyone have a solution for this yet? @seeden

camburley avatar Mar 07 '20 20:03 camburley

Anyone have a solution for this yet? @seeden

cody-pope avatar Oct 24 '20 02:10 cody-pope

I solved it by rendering the component conditionally. I added a condition so that only if the object to which the component is used for (in my case a song) is returned from the server and is not empty the <FacebookProvider> component will be rendered. Not sure it's the best practice but it works.

yarivShamash avatar Jan 14 '21 16:01 yarivShamash

Probably fixed in version 9. Closing it

seeden avatar Dec 02 '22 20:12 seeden