-
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
Deferred values seem broken in single fetch #10467
Comments
You have to throw an error. In this example a string is thrown, not an error |
@brookslybrand I also tried a Response, and that doesn't work either |
@brookslybrand the docs also say |
here's a similar repro of this working without single fetch: https://stackblitz.com/edit/remix-run-remix-msywtrm6?file=app%2Froutes%2F_index.tsx,vite.config.ts (just turn on single fetch to see it behave inconsistently) 1 caveat which personally makes this API a little rough to use is not being able to have it already consume error responses or primitive values |
This seems to be a duplicate issue of I'm not sure whether it was intended or not to throw arbitrary non-error values from deferred promises before single fetch. As for sending a Response, I don't know if that's a great value to return, since the response for the data/document has already been sent. This is further data that's streaming in |
@lifeiscontent the error is in line 49: Change that line to |
@seanify-24 if I do that, I see: "Error: An unknown error occurred" instead of "goodbye" |
Perhaps I'm confused as to what the problem is then. If you follow @brookslybrand 's suggestion to throw an Error object instead of a string, it seem to behave correctly. Here's what I changed: const greet = async () => {
if (Math.random() >= 0.5) {
throw new Error('goodbye');
}
return 'hello';
};
...
// cannot see goodbye
function ErrorComponent() {
const error = useAsyncError();
console.log('ErrorComponent', error);
console.dir(error);
return <p key="error">{error.message}</p>;
} Results in |
The issue is the docs say useAsyncError returns a "value" which to me means ANYTHING. E.g. if I don't want to return an error, but rather some other value that I want to have access to, it should work. also, when it comes to error boundaries the error that is returned is capable of grabbing the "data" of the loader in the error state, and the inconsistency here is not great because you have to write extra code to more or less, solve the same problem, (async IO) |
Reproduction
https://stackblitz.com/edit/remix-run-remix-obxpgddh?file=app%2Froutes%2F_index.tsx
System Info
Used Package Manager
npm
Expected Behavior
expect to be able to use the value from useAsyncError
Actual Behavior
never consistently returns the error value.
The text was updated successfully, but these errors were encountered: