-
Notifications
You must be signed in to change notification settings - Fork 30.5k
[react] Explicitly allow async Form Actions #70197
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
[react] Explicitly allow async Form Actions #70197
Conversation
This was implicitly enabled by TypeScript allowing any return type if the return type of an expected function is `void`. But this is not generally behavior we want in React so we should not relly on it. It's also problematic since certain type-aware ESLint rules may issue violations since it looks like Form Actions can't be async. We now explicitly codify support of async Form Actions. This also means return anything else will now issue type errors
|
@eps1lon Thank you for submitting this PR! This is a live comment that I will keep updated. 1 package in this PRCode ReviewsBecause this is a widely-used package, a DT maintainer will need to review it before it can be merged. You can test the changes of this PR in the Playground. Status
All of the items on the list are green. To merge, you need to post a comment including the string "Ready to merge" to bring in your changes. Diagnostic Information: What the bot saw about this PR{
"type": "info",
"now": "-",
"pr_number": 70197,
"author": "eps1lon",
"headCommitOid": "415a5f0ab1791814ef5ca1c33e95ea7590a10396",
"mergeBaseOid": "e433a575b5289eaf881b332f9cfaed17ac358226",
"lastPushDate": "2024-08-02T13:45:57.000Z",
"lastActivityDate": "2024-09-24T13:51:15.000Z",
"mergeOfferDate": "2024-09-23T18:40:24.000Z",
"mergeRequestDate": "2024-09-24T13:51:15.000Z",
"mergeRequestUser": "eps1lon",
"hasMergeConflict": false,
"isFirstContribution": false,
"tooManyFiles": false,
"hugeChange": false,
"popularityLevel": "Critical",
"pkgInfo": [
{
"name": "react",
"kind": "edit",
"files": [
{
"path": "types/react/canary.d.ts",
"kind": "definition"
},
{
"path": "types/react/test/canary.tsx",
"kind": "test"
},
{
"path": "types/react/ts5.0/canary.d.ts",
"kind": "definition"
},
{
"path": "types/react/ts5.0/test/canary.tsx",
"kind": "test"
}
],
"owners": [
"johnnyreilly",
"bbenezech",
"pzavolinsky",
"ericanderson",
"DovydasNavickas",
"theruther4d",
"guilhermehubner",
"ferdaber",
"jrakotoharisoa",
"pascaloliv",
"hotell",
"franklixuefei",
"Jessidhia",
"saranshkataria",
"lukyth",
"eps1lon",
"zieka",
"dancerphil",
"dimitropoulos",
"disjukr",
"vhfmag",
"hellatan",
"priyanshurav",
"Semigradsky",
"mattpocock"
],
"addedOwners": [],
"deletedOwners": [],
"popularityLevel": "Critical"
}
],
"reviews": [
{
"type": "approved",
"reviewer": "jakebailey",
"date": "2024-09-23T18:39:47.000Z",
"isMaintainer": true
}
],
"mainBotCommentID": 2265440407,
"ciResult": "pass"
} |
|
🔔 @johnnyreilly @bbenezech @pzavolinsky @ericanderson @DovydasNavickas @theruther4d @guilhermehubner @ferdaber @jrakotoharisoa @pascaloliv @Hotell @franklixuefei @Jessidhia @saranshkataria @lukyth @zieka @dancerphil @dimitropoulos @disjukr @vhfmag @hellatan @priyanshurav @Semigradsky @mattpocock — please review this PR in the next few days. Be sure to explicitly select |
|
|
||
| interface DO_NOT_USE_OR_YOU_WILL_BE_FIRED_EXPERIMENTAL_FORM_ACTIONS { | ||
| functions: (formData: FormData) => void; | ||
| functions: (formData: FormData) => void | Promise<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think you want this to be Promise | undefined instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do you think that?
|
@eps1lon One or more reviewers has requested changes. Please address their comments. I'll be back once they sign off or you've pushed new commits. Thank you! |
|
@eps1lon I haven't seen any activity on this PR in more than three weeks, and it still has problems that prevent it from being merged. The PR will be closed on Sep 11th (in a week) if the issues aren't addressed. |
|
@eps1lon To keep things tidy, we have to close PRs that aren't mergeable and don't have activity in the last month. No worries, though — please open a new PR if you'd like to continue with this change. Thank you! |
|
It has been more than two weeks and this PR still has no reviews. I'll bump it to the DT maintainer queue. Thank you for your patience, @eps1lon. (Ping @johnnyreilly, @bbenezech, @pzavolinsky, @ericanderson, @DovydasNavickas, @theruther4d, @guilhermehubner, @ferdaber, @jrakotoharisoa, @pascaloliv, @Hotell, @franklixuefei, @Jessidhia, @saranshkataria, @lukyth, @zieka, @dancerphil, @dimitropoulos, @disjukr, @vhfmag, @hellatan, @priyanshurav, @Semigradsky, @mattpocock.) |
|
Ready to merge |
|
Hey @eps1lon, thanks for the fix. I run into an issue and I believe this is related. If the server action returns a value, for example to be used along with useActionState(), then there's a typescript error on the Form action attribute. As it expects a Promise response (most likely due to revalidatePath or redirect), there's an error if the action returns a value, like an error. Any idea how we can fix that? |
|
|
This was implicitly enabled by TypeScript allowing any return type if the return type of an expected function is
void. But this is not generally behavior we want in React so we should not relly on it.It's also problematic since certain type-aware ESLint rules may issue violations since it looks like Form Actions can't be async.
We now explicitly codify support of async Form Actions. This also means return anything else will now issue type errors
Closes #64451 (comment)