Skip to content
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

Array fields do not update when adding fields and errors are not available when validating form #874

Open
jansedlon opened this issue Mar 6, 2025 · 4 comments

Comments

@jansedlon
Copy link
Contributor

jansedlon commented Mar 6, 2025

Description

I've identified two significant issues when i rewrote all of our forms to Conform V1 when working with complex nested forms. Importantly, these bugs only manifest in production builds and not during development.

Issue 1: Form Insertion Not Working

When using complex forms with multiple nested arrays of objects, formMeta.insert() sometimes fails to add new items to the form.
It successfully inserts the first item, but not any other.
The UI doesn't update to reflect any changes
Components using useField() don't receive updated values

Issue 2: Validation Errors Not Propagating Correctly

When validating forms with nested structures:

parseWithZod correctly identifies and returns validation errors
However, these errors don't appear in meta.errors
The form correctly focuses the fields with errors
But the actual error messages/states are missing from meta.errors

Conform version

v1.1.5

Steps to Reproduce the Bug or Issue

Only occurs in production builds (not in development mode)
Happens with forms containing nested arrays of objects
Complex nesting structure (arrays within objects within arrays).

I have tried to make a minimal reproduction but failed to do so. It seems like a deeper issue.

Bizarre fix

Take out the logic of rendering nested array from a component one level higher up in the tree.

What browsers are you seeing the problem on?

Chrome

Screenshots or Videos

I will post a video here

Additional context

No response

@edmundhung
Copy link
Owner

It successfully inserts the first item, but not any other.

Do you mean it works clicking the button first time or you are calling insert multiple times and the first time works?


I don't have much ideas right now by looking at your description. But i can take a look of the codebase if you want. Let me know.

@jansedlon
Copy link
Contributor Author

jansedlon commented Mar 6, 2025

@edmundhung Here's the issue on video and explanation. It's a bit long but hard to explain, sorry video

PS: I think i forgot to mention what fixed it.. The fix was to take out the content of CustomFields component and place it into the LandingPageStep 🫠 Then the issue disappeared and adding new fields worked.

@jansedlon
Copy link
Contributor Author

jansedlon commented Mar 6, 2025

I got new information regarding the errors not propagating down to the meta.errors.

In the form shown in the video, when i:

  1. Don't fill out name
  2. Don't fill out email
  3. Submit the form which should show errors and populate meta.errors

This for of loop

for (const subscriber of subscribers) {

in development build (local pnpm build with NODE_ENV=development)

The subject is an object with some fields.
Also is it okay that it has duplicate fields in errors, initialValues and key?

Image

In production build (local pnpm build with NODE_ENV=production)

The subject is an empty object and therefore the shouldNotify always returns false

Image

@edmundhung
Copy link
Owner

I am wondering if you have cache the JSX in some way so that you are not accessing the metedata after the initial render. Conform will reset the subject on every render and resubscribe to what being accessed during that particular render. 🤔

Maybe ping me on discord and we can have a call tonight or tomorrow to go through it together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants