Potentially a bug: default value is cleared under strict mode #572
clovis1122
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I'm not sure whether this is a bug or something else, so I thought I'd ask here first. I'm using
useInputControl
to control a<Select />
component from shadcn. I noticed that, during development and with Strict mode, the default value is cleared automatically.Here's an example Remix project: https://stackblitz.com/~/github.com/clovis1122/poc-conform-default-value with this problem. Run the project, then go to
/select?field=a
. The expected behavior is that thefield
select will have a default value ofa
. Instead, it ends up with an empty value.The important bit is what happens during the initial rendering. This code will not call
change()
because initializedRef.current is set to false. However, during strict mode, hooks runs twice, and during the second call,initializedRef.current
is set to true and this will trigger a call tochange()
. This call is then caught by radix-ui's select implementation, which tries to get the value from the event's target. But this value is empty, hence the empty string.I made a second example using normal
<select />
component (which is in the default/
path). In this case, the default select'sonChange()
is not triggered by the event that was dispatched, therefore, this issue does not happen.A few things I tried to fix this:
useInputControl()
hook to reset initializedRef on unmount:From these options, no. 3 makes the most sense to me and as a bonus, it will also prevent the call to
change()
that results in extra code running. However, in the end, I'm not sure if this is all just a bug in radix-ui's<Select />
implementation... thoughts?Beta Was this translation helpful? Give feedback.
All reactions