-
-
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
[Bug]: JsonObject
type reports issues in Remix's useSubmit
that are technically okay, making workarounds extense
#12045
Comments
Hm, are you submitting with an I think if using the latter, the code as it stands today will send a blank string across in However, for This is important in JSON submissions in RR because we So something like So for JSON submissions this feels like the correct typing but for |
Hi @brophdawg11 ! Thanks for the reply! We're using The type makes sense when you explain it, as it is defining how the resulting json appears, but the problem is that the react-router/packages/react-router-dom/index.tsx Line 1566 in fab7723
react-router/packages/react-router-dom/index.tsx Lines 1519 to 1529 in fab7723
react-router/packages/react-router-dom/dom.ts Lines 125 to 132 in f511c22
Maybe what I'm trying to get at is that Yes the functions serializes the value that is passed onto it but what we pass to the function should be any javascript object of any shape and with any value, regardless if it's required or optional in typescript. What do you think ? |
If we loosen that type on the "input" end, I worry that would open up footguns for this type of (I assume common) usage? type MyJsonType = {
value: string | undefined;
};
function Component() {
let data: MyJsonType = ...
let submit = useSubmit();
...
// If we allow "looser" json here...
submit(data, ...);
}
function action({ request }) {
// ...then we make this incorrect
let data = (await res.json()) as MyJsonType;
...
} Folks would need to remember to use something like |
What version of React Router are you using?
6.26.1
Steps to Reproduce
This is a common usage:
Giving a Prisma schema:
We want to submit a form that has compatible fields with that schema such as
We then later gather the data, usually a form library or whatever.
Finally we do a submit via Remix's useSubmit
Expected Behavior
undefined
should be a valid value on required properties for theJsonValue
type below:react-router/packages/react-router-dom/dom.ts
Lines 118 to 120 in fab7723
Actual Behavior
As described above, required values set as
undefined
do not pass.The text was updated successfully, but these errors were encountered: