Add context (and request?) to ErrorBoundary #6297
Replies: 2 comments 4 replies
-
One alternative is to include the necessary export function loader({ context }) {
try {
doSomethingDangerous()
} catch (e) {
throw new Error(JSON.stringify({ message: e.message, env: context.ENV }))
}
}
export function ErrorBoundary({ error }: { error: Error }) {
let env, message
try {
const parsed = JSON.parse(error.message)
env = parsed.env
message = parsed.message
} catch {
env = {}
message = error.message
}
doSomethingWith(env)
return <html>{message}</html>
} This requires wrapping every |
Beta Was this translation helpful? Give feedback.
-
ErrorBoundary runs both server and client side, so you can't pass the AppLoadContext because that's a server-only thing. Doing this will limit error boundaries to only work server-side and never hydrate your app. Another way this may be able to work is once RSC are stable and Remix supports them, error boundaries could be considered server components and have access to every AppLoadContext. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Problem
ErrorBoundary
has the following type:Since the props don't include
context
, any data or services that requirecontext
are unavailable in error boundaries.In many environments (including Cloudflare Pages),
process.env
doesn't exist; environment variables are instead attached to thecontext
.This makes it very difficult to use an error boundary to report errors to third-party trackers like Sentry, Rollbar, or LogRocket.
Proposal
Add
context: AppLoadContext
to theErrorBoundary
props. Better yet, if it's not prohibitive, add all ofDataFunctionArgs
({ request, context, params }
).Beta Was this translation helpful? Give feedback.
All reactions