question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: Loader data gets undefined when an error is thrown in a child route

See original GitHub issue

Which Remix packages are impacted?

  • remix (Remix core)

What version of Remix are you using?

1.0.3

Steps to Reproduce

I couldn’t reproduce the bug with the remix template on Codesandbox, but this happens 100% of the time with the Remix Jokes tutorial. You can watch the bug in action at this moment in @kentcdodds’s lifestream yesterday. He asked if someone could open up an issue for it, so here I am.

I have created a public repo on Github with the code you are supposed to have when you have been following along the Jokes tutorial, just before beginning the “SEO with Meta tags” part. Here’s how to see the bug in action:

  1. Clone this repo
  2. Run npm i
  3. Create a .env file and add DATABASE_URL="file:./dev.db" in it, along with SESSION_SECRET="whatever"
  4. Seed the DB: npx prisma db seed
  5. Run the app: npm run dev
  6. Click “Read jokes”, then “Add your own” (or go to http://localhost:3000/jokes/new)
  7. Submit the form
  8. Kaboum!

Expected Behavior

An error thrown in a route action should be caught by the route’s error boundary (or the closest one above). The parent’s loader data shouldn’t become undefined when this happens.

Actual Behavior

The error occurring in the /jokes/new route action function isn’t handled by the route’s error boundary, instead, the /jokes route loader data becomes undefined, triggering an error that is caught by the root error boundary:

TypeError: Cannot read property 'user' of undefined
    at `{data.user ? (` (./app/routes/jokes.tsx:50:16)
    [...]

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:12
  • Comments:22 (9 by maintainers)

github_iconTop GitHub Comments

11reactions
andmayorovcommented, Nov 24, 2021

I’ve added empty CatchBoundary to routes/jokes.tsx like this and it fixed it for me.

export function CatchBoundary() {}

Not sure why

7reactions
aviasdcommented, Jan 11, 2022

Hi, Is there a fix for it (not a temporary fix)? If not, in the meanwhile, can you add the temporary fix to the docs?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught (in promise) undefined - Vue-router - Stack Overflow
I think the issue is being caused by the re-reoute. If the user does not have page_access 1, it then routes to /holidays....
Read more >
Resolving the JavaScript Promise Error "TypeError: Cannot ...
TypeError - Cannot read property 'then' of undefined is thrown when the caller is expecting a Promise to be returned and instead receives ......
Read more >
How to Read React Errors (fix 'Cannot read property of ...
Throw in some console. log s or use the debugger to inspect the intermediate values and figure out why it's undefined. Success!
Read more >
Error handling, "try...catch" - The Modern JavaScript Tutorial
If there were no errors, then catch (err) is ignored: the execution ... (1) <-- lalala; // error, variable is not defined! alert('End...
Read more >
Tutorial v6.6.1 - React Router
Anytime your app throws an error while rendering, loading data, ... When the user navigates to routes that don't exist you'll get an...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found