t3-oss / create-t3-turbo

Clean and simple starter repo using the T3 Stack along with Expo React Native
https://turbo.t3.gg
MIT License
4.51k stars 376 forks source link

bug: `useForm` helper not honoring transformed output of resolver #1097

Closed chris-allen closed 2 months ago

chris-allen commented 2 months ago

Provide environment information

System:
  OS: Linux 6.9 Arch Linux
  CPU: (4) x64 Intel(R) Core(TM) i7-7500U CPU @ 2.70GHz
  Memory: 6.79 GB / 15.39 GB
  Container: Yes
  Shell: 5.9 - /bin/zsh
Binaries:
  Node: 20.14.0 - ~/.nvm/versions/node/v20.14.0/bin/node
  npm: 10.7.0 - ~/.nvm/versions/node/v20.14.0/bin/npm
  pnpm: 9.2.0 - ~/.nvm/versions/node/v20.14.0/bin/pnpm

Describe the bug

When using the useForm wrapper, transforms applied to the schema output type are ignored. Essentially, the form submitHandler falsely advertises that the validated data is of the same format as the schema input.

Link to reproduction

N/A

To reproduce

const TestSchema = z
  .object({
    firstName: z.string(),
    lastName: z.string(),
  })
  .transform(({ firstName, lastName }) => ({
    fullName: `${firstName} ${lastName}`,
  }));

export function TestForm() {
  const form = useForm({
    schema: TestSchema,
    defaultValues: {
      firstName: "",
      lastName: "",
    },
  });

  return (
    <Form {...form}>
      <form
        onSubmit={form.handleSubmit((data) => {
          // @ts-expect-error This ignores the transformed output of the schema
          console.log(data.fullName);
        })}
      >
        ...
      </form>
    </Form>
  );
}

Additional information

No response

stunaz commented 2 months ago

best to post that on the reach-hook-form repo

juliusmarminge commented 2 months ago

Fixed in #1098

chris-allen commented 2 months ago

best to post that on the reach-hook-form repo

@stunaz Sorry if it wasn't obvious, but this is referring to the useForm helper function in create-t3-turbo that wraps the function from react-hook-form with the same name.

@juliusmarminge Thanks for merging!