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

Bug: #32234

Closed
Nefcanto opened this issue Jan 27, 2025 · 5 comments
Closed

Bug: #32234

Nefcanto opened this issue Jan 27, 2025 · 5 comments

Comments

@Nefcanto
Copy link

React version: 19.0.0

My code is not shown in the error stack. How can I know what caused the error?

Image

Uncaught Error: Objects are not valid as a React child (found: object with keys {message, data, description}). If you meant to render a collection of children, use an array instead.
    React 11
        throwOnInvalidObjectType
        reconcileChildFibersImpl
        createChildReconciler
        reconcileChildren
        beginWork
        runWithFiberInDEV
        performUnitOfWork
        workLoopSync
        renderRootSync
        performWorkOnRoot
        performWorkOnRootViaSchedulerTask
    performWorkUntilDeadline scheduler.development.js:44
    js scheduler.development.js:219
    js scheduler.development.js:364
    __require chunk-DC5AMYBS.js:9
    js index.js:6
    __require chunk-DC5AMYBS.js:9
    React 2
        js
        js
    __require chunk-DC5AMYBS.js:9
    js React
    __require chunk-DC5AMYBS.js:9
    <anonymous> react-dom_client.js:17892
react-dom-client.development.js:4446:12
    React 11
        throwOnInvalidObjectType
        reconcileChildFibersImpl
        createChildReconciler
        reconcileChildren
        beginWork
        runWithFiberInDEV
        performUnitOfWork
        workLoopSync
        renderRootSync
        performWorkOnRoot
        performWorkOnRootViaSchedulerTask
    performWorkUntilDeadline scheduler.development.js:44
    (Async: EventHandlerNonNull)
    js scheduler.development.js:219
    js scheduler.development.js:364
    __require chunk-DC5AMYBS.js:9
    js index.js:6
    __require chunk-DC5AMYBS.js:9
    React 2
        js
        js
    __require chunk-DC5AMYBS.js:9
    js React
    __require chunk-DC5AMYBS.js:9
    <anonymous> react-dom_client.js:17892

I have more than 75 thousand lines of code in my React app. How can I find where is the problem in my code?

@Nefcanto Nefcanto added the Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug label Jan 27, 2025
@hossamalmaraghy
Copy link

hossamalmaraghy commented Feb 5, 2025

Debugging the "Objects are not valid as a React child" Error

Hey @Nefcanto,

This error happens when an object is passed as a React child, but React only accepts strings, numbers, JSX elements, or arrays of these.

Since your code is not shown in the error stack, here’s how you can efficiently find and fix the issue in your large codebase (75K+ lines):


Log Suspicious Data

Wrap your entire <App /> component inside an error boundary to capture and log the error source:

Fix: Add an Error Boundary

class ErrorBoundary extends React.Component {
  componentDidCatch(error, info) {
    console.error("Error in component:", error, info);
  }
  render() {
    return this.props.children;
  }
}

// Wrap your app:
ReactDOM.createRoot(document.getElementById("root")).render(
  <ErrorBoundary>
    <App />
  </ErrorBoundary>
);

@Nefcanto
Copy link
Author

Nefcanto commented Feb 6, 2025

@hossamalmaraghy, that worked. Thank you. I could find out the problem. But why does React not do it out of the box?

When it's available in the error boundary, I guess they can find out the stack in the user code. Then why not just show it in the first place without requiring an error boundary?

@hossamalmaraghy
Copy link

@Nefcanto, glad it worked for you!

You’d think React could just show the full stack trace automatically, But there are a few reasons why it doesn’t.

Why React Doesn’t Do This by Default

Performance & Stability

  • React is designed to keep things running smoothly even when an error occurs.
  • If it tried to capture full stack traces every time something went wrong, it could slow things down unnecessarily.

React’s rendering process

  • When an error happens inside a component, React stops rendering that part of the UI and unmounts it.
  • Without an error boundary, React doesn’t have a built-in way to recover from the error or show more details.

Stack trace limitations

  • React’s reconciliation engine (Fiber) optimizes rendering, but it doesn’t track full error stacks in real-time.
  • Error boundaries give developers control over how errors are handled instead of React making assumptions.

You can do instead

  • Use React DevTools to track component updates.
  • Add React.StrictMode in development for extra debugging warnings.
  • Use error monitoring tools like Sentry or LogRocket for full error reporting.

So, Why Not Just Show It Automatically?

It’s mainly about keeping React fast and efficient. If React tried to handle errors for every single component, it could lead to unexpected behaviors and performance overhead.

Instead, error boundaries put that control in the hands of developers, so you decide how errors should be handled instead of React forcing a default behavior.

Hope that makes sense!

@eps1lon
Copy link
Collaborator

eps1lon commented Feb 7, 2025

Support requests filed as GitHub issues often go unanswered. We want you to find the answer you're looking for, so we suggest the following alternatives:

Coding Questions
If you have a coding question related to React and React DOM, it might be better suited for Stack Overflow. It's a great place to browse through frequent questions about using React, as well as ask for help with specific questions.

https://stackoverflow.com/questions/tagged/react

Talk to other React developers
There are many online forums which are a great place for discussion about best practices and application architecture as well as the future of React.

https://react.dev/community

@eps1lon eps1lon closed this as completed Feb 7, 2025
@eps1lon eps1lon closed this as not planned Won't fix, can't repro, duplicate, stale Feb 7, 2025
@eps1lon eps1lon added Resolution: Support Redirect and removed Status: Unconfirmed A potential issue that we haven't yet confirmed as a bug labels Feb 7, 2025
@Nefcanto
Copy link
Author

Nefcanto commented Feb 8, 2025

@eps1lon well it's still a bug. Any other programming language or framework that I have worked with or I'm working with, reports the user code. React does not. It's technically not a support request. It's a bug.

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

3 participants