-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
useActionData
returning incorrect data
#10074
Comments
I think the problem is Check
However, After debugging, I found the problem here: let handlerPromise: Promise<DataStrategyResult> = (async () => {
try {
let val = await (handlerOverride
? handlerOverride((ctx: unknown) => actualHandler(ctx))
: actualHandler());
return { type: "data", result: val };
} catch (e) {
return { type: "error", result: e };
}
})();
return Promise.race([handlerPromise, abortPromise]); The On the contrary, loader return a // val of loader is a DefferedResult other than a Response
let val = await (handlerOverride
? handlerOverride((ctx: unknown) => actualHandler(ctx))
: actualHandler()); The difference is caused by For loader it is: remix/packages/remix-react/routes.tsx Line 333 in 5954ad1
For action it is: remix/packages/remix-react/routes.tsx Line 383 in 5954ad1
In conclusion, the action does not support Now that |
@laishere is correct in that actions do not support It's worth noting that with Single Fetch this limitation is removed and you can return promises from actions in plain javascript objects, no need for |
@brophdawg11 I believe it's because the action handler return a Action handler defined in remix/packages/remix-react/routes.tsx Line 383 in 5954ad1
|
Reproduction
/test
routetext
inputI originally encountered this using the Cloudflare template with
@remix-run/cloudflare
, but I replicated this in the reproduction using@remix-run/node
.System Info
Used Package Manager
npm
Expected Behavior
The
useActionData
hook should just return the serialised data from the most recent route action.Actual Behavior
The useActionData hook does return the correct data, but within another
data
property as part of an object with other properties such asabortPromise
,deferredKeys
,pendingKeysSet
, etc.This doesn't match the types from
useActionData<typeof action>()
, so trying to access thedata
property throws the following type error.Property 'data' does not exist on type '({} & { text: string | JsonifyObject<File> | null; } & {}) | undefined'.
The only related issue I could find is remix-run/blues-stack#151.
The text was updated successfully, but these errors were encountered: