Root loader not being called in CatchBoundary
See original GitHub issueWhat version of Remix are you using?
1.6.4
Steps to Reproduce
- 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
- 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:
- Created a year ago
- Reactions:1
- Comments:9 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Update: I managed to hack around this by adding a Splat Route throwing a 404 error status code.
app/routes/$.tsx
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.