-
Any reason why root loader data is not available in the root ErrorBoundary? I need global application data, that I usually supply through the root loader, to be available in both normal application rendering and in the root ErrorBoundary. For instance, if the path has not been found, the root loader still makes sense, doesn't it? But for some reason it is null. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 24 replies
-
The way it works now is: I read some data from a local config file, and return it as the root loader data. However, if a 404 Not Found error happens, I can't access that root loader data. For instance, I need to to read the application name - literally the name that is used in |
Beta Was this translation helpful? Give feedback.
-
Because the reason why the root error boundary was rendered could be that the root loader failed, in that case there’s no root loader data. You can use useRouteLoaderData to access it and handle the case when it’s undefined https://sergiodxa.com/tutorials/access-remix-s-loader-data-from-a-root-errorboundary |
Beta Was this translation helpful? Give feedback.
-
I've got a solution that lets you set global app data that can be used in any route, as well as the error boundary. Request-specific data (like host header) will need to be returned from loaders, though. However, I also have a solution for returning request data to your error boundary as well. I'll be posting an example repo later today. My example uses Vite, but I imagine it will work on the classic compiler. |
Beta Was this translation helpful? Give feedback.
-
I was also thinking about the layout export, e.g. to load the data from the file in there and expose it as a global context. But it is rendered on both server side and client side, so doesn't look like a solution either. |
Beta Was this translation helpful? Give feedback.
I finally got my example finished and deployed. Check it out here.
https://github.com/kiliman/remix-global-data
There's even a link to a deployed app.