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.

Root loader not being called in CatchBoundary

See original GitHub issue

What version of Remix are you using?

1.6.4

Steps to Reproduce

  1. Export something from your root loader, and try to read the data returned by that loader in the CatchBoundary.
import { json, LoaderFunction } from "@remix-run/node"
import { useMatches } from "@remix-run/react"

import { getBaseURL } from "~/utils/seo"

export const loader: LoaderFunction = ({ request }) => {
  return json({ baseUrl: getBaseURL(request) })
}

const Root: React.FC = () => {
  console.log(JSON.stringify(useMatches(), null, 2))
  return <div>Root</div>
}

export const CatchBoundary = () => {
  console.log(JSON.stringify(useMatches(), null, 2))
  return <div>Catch</div>
}

export default Root
  1. Navigate to a non-existing route.

Expected Behavior

This should be logged to the console (taken from an existing route).

[
  {
    "id": "root",
    "pathname": "/",
    "params": {},
    "data": {
      "baseUrl": "http://localhost:3000"
    }
  }
]

Actual Behavior

This was logged to the console (taken from a non-existing route).

[
  {
    "id": "root",
    "pathname": "",
    "params": {}
  }
]

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
kevinwolfcrcommented, Jul 31, 2022

Update: I managed to hack around this by adding a Splat Route throwing a 404 error status code.

app/routes/$.tsx

import { notFound } from "remix-utils"

export function loader() {
  throw notFound(null)
}

export default function NotFound() {
  return null
}
1reaction
reveltcommented, Jul 18, 2022

This bug/feature has been since the beginning; in practice, for example, it means our 404 pages can’t show the correct theme. It would be nice if loaders were called in catch boundaries.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Loading - Remix
Loaders are only called on the server, via fetch from the browser, so your data is serialized with JSON.stringify and sent over the...
Read more >
How to redirect to a custom 404 page in remix.run?
In your loader, check the params and throw new Response('Not found', ... https://remix.run/docs/en/v1/guides/not-found#root-catch-boundary.
Read more >
remix-utils - npm
The promiseHash function is not directly related to Remix but it's a useful function when working with loaders and actions.
Read more >
Remix Authentication - Clerk.dev
After following this guide, you should have a working Remix app complete with: ... Clerk uses Remix's catch boundary in root.tsx to refresh...
Read more >
Let's Learn Remix! - Learn With Jason
RYAN: It's honestly why I like working from home. It's not because I don't like interruptions. It's that I interrupt everybody. All right....
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