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

Bug (Manufacturer prequal): pre-filled text fields not always reliable #1517

Open
CarlosNZ opened this issue Jun 7, 2023 · 3 comments
Open
Assignees
Labels
bug Something is broken :( Customer: Fiji

Comments

@CarlosNZ
Copy link
Collaborator

CarlosNZ commented Jun 7, 2023

This is something I noticed, and it seems to be a bug in the "default" handling. Sometimes the pre-filled value is not actually getting saved with the response even though it shows up correctly in the application form.

So we end up with something like this, where the Name and Address fields are blank, even though the selected manufacturer clearly has them:

Image

What's weird is that the form passes validation, even though those fields are required. So the local state must think they have values, and they're just not getting saved to the database reliably.

Unfortunately this is inconsistent, and I can't yet figure out how how to reliably reproduce it.

@CarlosNZ CarlosNZ added bug Something is broken :( Customer: Fiji labels Jun 7, 2023
@CarlosNZ
Copy link
Collaborator Author

CarlosNZ commented Jun 7, 2023

Okay, so the problem is that when the "Select manufacturer" question is initially sending a null default to the name field. And when it changes, the Name element re-renders, initially with a null default before quickly updating again with the new selected name as the default. And because null is a valid value, both the "null" and actual name get written to the database. And because they're async, sometimes the null one actually finishes last even though it was started first, so you end up with null in the database even though the front-end state has the correct new value.

In this case, we can prevent the problem by adding the preventNullDefault parameter to the text inputs (and a couple of other safeguards), but it would be good if we could make this a bit more robust.

The problem is, the "name" field initially starts of hidden, so it is not rendered at all, so when it becomes visible it gets the original "null" default and the proper default almost simultaneously, hence the race condition.

Maybe using the "preventNullDefault" is enough? Or maybe we should set preventNullDefault to be true by default? Need to see which cases are more common, and which has the worst consequences if it's set incorrectly for the situation.

@CarlosNZ CarlosNZ self-assigned this Jun 20, 2023
@jagoje
Copy link

jagoje commented Sep 5, 2023

Ahh I see... this relates to the null issue I commented on in another issue

@CarlosNZ
Copy link
Collaborator Author

CarlosNZ commented Sep 5, 2023

Ahh I see... this relates to the null issue I commented on in another issue

No, I think it's different. This one I have no explanation for. Fortunately doesn't happen very often.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken :( Customer: Fiji
Projects
None yet
Development

No branches or pull requests

2 participants