-
Notifications
You must be signed in to change notification settings - Fork 11
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
fix(ui): Prevent a React error for input fields #1946
base: main
Are you sure you want to change the base?
Conversation
Make sure that the input value is never null, this prevents the error: A component is changing an uncontrolled input to be controlled. Signed-off-by: Martin Nonnenmacher <martin.nonnenmacher@bosch.com>
I'm not sure I'd change the component itself like this, as There are also some dangerous data structures in the back-end, like for environment variables, where sending empty names and/or values is quite acceptable, but leads to Analyzer failure. All in all, I see value in your PR, but I think we'd better think of a good and concise way to always return meaningful values from forms. Luckily, we do validate each form with Zod, but I think those validations are a bit imperfect in our UI atm. Your PR would actually make sense, as long as we always prevent empty strings being sent from forms where this restriction is needed, and we can do this easily by validating an
or something similar. |
I think even the current implementation is not always behaving as intended, because as soon as you click on an input field the React error is triggered, meaning that React is changing the default The FAQ does not explain what is the consequence of the error, but it clearer states that the current implementation is wrong: Do you have some more examples for text fields that should make that distinction between |
I'll continue the discussion tomorrow, but meanwhile, here's some good reading about the issue: shadcn-ui/ui#690, shadcn-ui/ui#410 |
In PR #1947 you can get rid of the uncontrolled->controlled errors coming from
The
If you just set a default value of '' for it in the
If we are happy with that, then the problem is solved for now. In case we don't want to send optional fields with defaults (like empty strings) in the form payload, the issues for When it comes to this PR, rather than changing the |
I think that should be fine, but the fix is not urgent so how about discussing it in the community call next week? |
Fine by me. |
Make sure that the input value is never null, this prevents the error: