Handle POST response body of `""`
See original GitHub issueI have a situation where my hosting provider (fly) responds to an action request with a 502 that doesn’t even get to my server (I think) so the useActionData() value is '' 😱
Because Remix doesn’t have control over this, I think I need to just always handle the case where data is not an object… I guess I could test for '' and change it to undefined 🤔 Might be nice if Remix did this out of the box. The reason this is a problem is because I do data?.errors.generalError and that blows up because it’s trying to access generalError on errors on an empty string (and errors is is undefined).
In any case, I think that one of two things need to happen:
- The
useActionDatageneric should befunction useActionData<T = AppData>(): T | undefined | '';(yuck) - The
useActionDatafunction should check for an empty string and returnundefinedif it’s an empty string.
If we don’t go with option 2 then the types are wrong, so we’ll want to have option 1. But yikes, who wants that? Not me!
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (4 by maintainers)

Top Related StackOverflow Question
That’s a great idea @stevecaldwell77! Thanks for mentioning superstruct. I’ll probably give that a look 👍
I’m going to make an example of using an assertion function on
useLoaderDatawhich makes this unnecessary.