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

React 18 - Internal React error if throwing on hook cleanup function. #22650

Open
andrew-w-ross opened this issue Oct 28, 2021 · 8 comments
Open

Comments

@andrew-w-ross
Copy link

Running the following test:

import React, { useEffect } from "react";
import { create } from "react-test-renderer";

const Boom = () => {
    useEffect(() => {
        return () => {
            throw new Error("Boom");
        };
    }, []);

    return null;
};

it("prints an error to the console on next is fine on latest", () => {
    const res = create(<Boom />);
    res.unmount();    
});

I'll get the following error message:

 console.error
    Warning: Internal React error: Attempted to capture a commit phase error inside a detached tree. This indicates a bug in React. Likely causes include deleting the same fiber more than once, committing an already-finished tree, or an inconsistent return pointer.

The test will pass but considering the nature of the message and that it differs from latest I thought reporting it might be a good idea. Repo if you need it /~https://github.com/andrew-w-ross/react-18-unmount-error

@nathell
Copy link

nathell commented Nov 30, 2021

I’m also experiencing this with other React versions on React Native, as well as with React 17.0.x production builds (but not dev builds) on web. See the above-linked RN issue.

@gaearon gaearon added Type: Bug and removed Type: Discussion React 18 Bug reports, questions, and general feedback about React 18 labels Nov 30, 2021
@josharsh
Copy link

josharsh commented Dec 8, 2021

@gaearon If anyone has not yet picked this yet, may I give it a shot?

@pistonsky
Copy link

This warning comes up a lot after I've upgraded to RN 0.67.1. In my case the causing Error has this message:

Error: You attempted to set the key `current` with the value `null` on an object that is meant to be immutable and has been frozen.

@eps1lon
Copy link
Collaborator

eps1lon commented Apr 29, 2022

@ugglr
Copy link

ugglr commented Nov 9, 2022

Getting in react native:

  • react native: 0.70.5
  • react: 18.1.0

Simulator Screen Shot - iPhone 12 - 2022-11-09 at 13 01 08

@shohelahamad
Copy link

Good day everyone, any update / solution on that ?

@geloski43
Copy link

@ugglr If you're still importing SafeAreaView from react-native, try importing it from react-native-safe-area-context.

@sujan-york-ie
Copy link

Getting the same issue, ERROR Warning: Internal React error: Attempted to capture a commit phase error inside a detached tree. This indicates a bug in React. Likely causes include deleting the same fiber more than once, committing an already-finished tree, or an inconsistent return pointer.

Does anyone have a solution for the same?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants