react icon indicating copy to clipboard operation
react copied to clipboard

Remove references to legacy class-based component architecture in error messages

Open ADTC opened this issue 1 year ago • 3 comments
trafficstars

We've moved to function-based components using hooks a very long time ago, yet we still see error messages such as these:

Maximum update depth exceeded. This can happen when a component repeatedly calls 
setState inside componentWillUpdate or componentDidUpdate. React limits the 
number of nested updates to prevent infinite loops.

I don't even know how to debug and resolve an error like this, because we're not using class-based components. It's really very annoying, because we don't have a single instance of setState, componentWillUpdate or componentDidUpdate in our code. These are remnants of the legacy class-based component architecture.

Copilot AI suggested something like this:

Maximum update depth exceeded. This can happen when a component repeatedly updates 
state using the useState hook inside the useEffect hook. React limits the 
number of nested updates to prevent infinite loops.

or

Maximum update depth exceeded. This can happen when a component repeatedly updates 
state using the useState hook directly inside the component body. React limits the 
number of nested updates to prevent infinite loops.

I'm not sure if either one is correct, but it's definitely a start.

Related:

  • #12811

ADTC avatar Jul 24 '24 12:07 ADTC

@ADTC That can happen if you somehow update your state on every render, to prevent such a behavior you can use useCallback combined with memo(), wrap your component inside memo like this export default memo(YourComponent), and also wrap all your functions defined inside that component into useCallback, see the docs here

I think it also can happen when you call some component or a react function recursively, check for such parts in your code.

Try out and let me know if it helped or not.

Thank you !

surenpoghosian avatar Aug 04 '24 16:08 surenpoghosian

@surenpoghosian I think this issue is about the error message in itself and not his code.

I agree that error messages shouldn't assume we are on a class-based architecture anymore. The first suggestion is what applied to most of my encounter with that error, so I find it good

requinDr avatar Aug 06 '24 08:08 requinDr

Hi @surenpoghosian:

As @requinDr has correctly observed, yes my issue is about the error message which is still using severely outdated terms which are very unhelpful in new projects that no longer use those terms.

And yes, such a generic error (even with correct terms) often isn't enough to pinpoint the exact location where it happens. The developer is left to find the needle in a haystack all by oneself.

ADTC avatar Aug 11 '24 10:08 ADTC

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Nov 09 '24 11:11 github-actions[bot]

bump

ADTC avatar Nov 09 '24 11:11 ADTC

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Feb 07 '25 12:02 github-actions[bot]

bump

ADTC avatar Feb 07 '25 12:02 ADTC

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Jun 09 '25 21:06 github-actions[bot]

bump

ADTC avatar Jun 09 '25 21:06 ADTC

This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize it yet. If you have any new additional information, please include it with your comment!

github-actions[bot] avatar Sep 07 '25 23:09 github-actions[bot]

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

github-actions[bot] avatar Sep 14 '25 23:09 github-actions[bot]