-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Meta function can't access loader
data when it throws
#3903
Comments
If you throw a response, it's not valid data from your loader, hence loader data is not present in your If you want to update the title from your export function CatchBoundary() {
const caught = useCatch()
useEffect(() => {
if (caught?.data?.title) {
document.title = caught.data.title
}
})
return (
<>
<h1>CatchBoundary</h1>
<p>Title should be {caught.data.title}</p>
<p>
{caught.status}: {caught.data.slug}
</p>
</>
)
} https://codesandbox.io/s/remix-catchboundary-title-h2nske?file=/app/routes/index.tsx |
@kiliman Thank you for this!
Hmm, I don't get that. Why would we assume that? Wouldn't it make more sense to add some conditionals into the
This definitely solves the issue, but seems like a hacky solution considering the Remix convention is to do it with |
When you throw from a function, you don't get the same result as if the function returned data. The I'm not saying this can't be changed. Just explaining how it currently works today. I guess my only concern is that if this was changed, would it be a breaking change? Since @ryanflorence I read in the decision doc for remix router/react-router that there may be no distinction between Error and Catch boundaries in the future. Have you considered adding the error and catch data to the |
@janhesters I ran across this issue as well, and settled on another admittedly hacky solution, albeit one that renders on the server-side. Here's a simplified version of my root component using a module-level closure to determine its meta title.
|
@chaance is this handled by the new Meta API? 🙏🏼 |
No. We're aware of this limitation. I'll make sure something is on our roadmap if it isn't already. |
🤖 Hello there, We just published version Thanks! |
🤖 Hello there, We just published version Thanks! |
Context
Why is this important? Screen reader users often rely on
title
's to infer the content of a page. And theloader
is used to dynamically set thetitle
property inmeta
functions.The inability to set title's dynamically on errors severely hinders this functionality.
What version of Remix are you using?
1.6.7
Steps to Reproduce
You need a
loader
that throws.Expected Behavior
The
meta
function should have access to the data ofjson
that wasthrown
.Actual Behavior
The
meta
function doesn't see theloader
's data.Possible Alternative
In case of errors you can set the title in the higher routes that didn't throw, but that would require all routes always getting all titles, which is bad for performance 😕
Or maybe there is another way to set the
title
inCatchBoundary
s?The text was updated successfully, but these errors were encountered: