digdir / designsystemet

Designsystemet
https://designsystemet.no
MIT License
85 stars 38 forks source link

Combobox: null, undefined and empty string as value causes react to crash #1663

Open Magnusrm opened 8 months ago

Magnusrm commented 8 months ago

Description of the bug

As mentioned in slack thread message: https://designsystemet.slack.com/archives/C05RF86A3K7/p1709550064585419?thread_ts=1709549317.707409&cid=C05RF86A3K7

The value of the generated Option object will be undefined if any of the mentioned values are used as a value. The object should be checked for undefined before it is attempted to retrieve the objects value property in order to mitigate a hard crash.

Steps To Reproduce

  1. Set up a simple react app in f.ex. codesandbox
  2. create a combobox with a controlled state that has initial value [""], [null] or [undefined]
  3. the react app will crash

Additional Information

No response

mimarz commented 8 months ago

Thanks for reporting this!

We'll have a look at what makes the most sense to do here as invalid values should give an error. Failing gracefully can also cause unwanted issues or illusion that things might be working when they aren't.

Is there a specific use-case you have that needs to support this?

Barsnes commented 8 months ago

Hi, like mentioned above, we will have to investigate what the best approach here is. While you wait, I suggest adding an error boundary closer to the Combobox, so it does not crash your whole app 😄