-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
Support direct handlers in useSubmit/fetcher.submit/fetcher.load #10362
Conversation
🦋 Changeset detectedLatest commit: b99ed0f The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
a08fba1
to
269e4b0
Compare
ac34175
to
0834f38
Compare
0834f38
to
6cda1c5
Compare
packages/router/router.ts
Outdated
@@ -1,4 +1,4 @@ | |||
import type { History, Location, Path, To } from "./history"; | |||
import type { Action, History, Location, Path, To } from "./history"; |
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.
This type isn't used.
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.
Stupid VSCode auto-imports 🤦
7f1f91d
to
ea5fa1b
Compare
ea5fa1b
to
952379b
Compare
let submissionTrigger: HTMLButtonElement | HTMLInputElement = ( | ||
options as any | ||
).submissionTrigger; |
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.
This was no longer being used - ever since we started sending from the submitter
property on the event
if (options.action) { | ||
action = options.action; | ||
} else { |
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.
For all cases (action
/encType
/method
/etc.), options[field]
took precedence, and now that action
could be an ActionFunction
it made sense to pull that out - so all options[field]
overrides happen in the body of useSubmit now instead of in getFormSubmissionInfo
. This also better prepares us for pulling useSubmit
down into react-router
where it can skip the DOM stuff.
let path = | ||
typeof options.action === "function" ? null : options.action || action; | ||
let routerAction = | ||
typeof options.action === "function" ? options.action : null; |
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.
path
and action
being sent to the router are mutually exclusive
if ( | ||
to != null && | ||
opts && | ||
"action" in opts && | ||
typeof opts.action === "function" | ||
) { | ||
to = null; | ||
warning( | ||
false, | ||
"router.navigate() should not include a `to` location when a custom " + | ||
"`action` is passed, the `to` will be ignored in favor of the current " + | ||
"location." | ||
); | ||
} |
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.
@ryanflorence This feels like maybe the API isn't quite right, but I didn't like navigating to a "function"
// Current API - `to` is ignored when action is passed
// router.navigate(to: To, opts: RouterNavigationOptions)
router.navigate(null, {
formMethod: 'post',
formData: new FormData(),
action: customAction,
})
// Alternate API - custom action is passed as the `to` value
// router.navigate(to: To | ActionFunction, opts: RouterNavigationOptions)
router.navigate(customAction, {
formMethod: 'post',
formData: new FormData(),
});
🤖 Hello there, We just published version Thanks! |
Silly bot, these were reverted from |
Depends on #10342submit
/fetcher.submit
loader
passed tofetcher.load
See the changesets for examples.
Right now, the inferred typings aren't in this PR since we were running into some issues with them and may fork them to a new PR. WIP is in the
brophdawg11/direct-action-types
branch.