v1.19.0
Breaking Changes (Future APIs)
-
Removed deprecated exports from
@conform-to/react/future(#1183)FormOptionsProvidercomponentBaseMetadatatypeBaseErrorShapetypeCustomTypestypeCustomMetadatatypeCustomMetadataDefinitiontype
The deprecated
schemaoption in the futureuseFormhook is also removed. If you were validating with a schema, pass the schema as the first argument:useForm(schema, options)instead ofuseForm({ schema, ... }). -
Improved
ErrorShapehandling through out the future APIs.form.errorsandfield.errorsnow use yourErrorShapedirectly instead of always wrapping it in an array. (#1183)If you were using a custom
ErrorShape, either by specifying it in the generics or through theisErroroption fromconfigureForms, update it fromErrorShapetoErrorShape[]to keep the array structure you had before. For example, if you previously usedstring, change it tostring[]to keep the errors as arrays of strings:const forms = configureForms({ - isError: shape<string>(), + isError: shape<string[]>(), }); -
report()now accepts either schemaissuesor an explicit error payload, but not both in the sameerrorobject. If you were combining them before, append the extra message as another issue instead. (#1183)const result = schema.safeParse(submission.payload); const isEmailUnique = await checkEmailUnique(submission.payload.email); if (!result.success || !isEmailUnique) { const issues = !result.success ? [...result.error.issues] : []; + if (!isEmailUnique) { + issues.push({ + message: 'Email is already taken', + path: ['email'], + }); + } return { result: report(submission, { error: { issues, - fieldErrors: { - email: !isEmailUnique ? ['Email is already taken'] : [], - }, }, }), }; }
What's Changed
-
Added support for customizing serializer based on field name (#1184)
The
serializeoptions now let you customize serialization based onctx.name, both globally throughconfigureForms()and per form throughuseForm(), while delegating everything else back to Conform's default serializer withctx.defaultSerialize.This changes the serializer callback signature to:
serialize(value, ctx) { // Custom serialization for a specific field name if (ctx.name === 'metadata') { return typeof value === 'string' || value == null ? value : JSON.stringify(value); } return ctx.defaultSerialize(value); }
Full Changelog: v1.18.0...v1.19.0