reddit / devvit

Reddit for Developers
https://developers.reddit.com
BSD 3-Clause "New" or "Revised" License
59 stars 13 forks source link

Number fields in app configurations silently default to `0` if no value is input by the user #82

Open shiruken opened 1 month ago

shiruken commented 1 month ago

Info

App configuration fields of type number only allow inputting numeric values. However, if the user clears the field and clicks submit, Devvit silently sets the value to 0 without any indication. The user would not see this change unless they refresh the settings page.

For the app developer, this is impossible to handle when 0 is a valid value for the field. This breaks using input validation to make a field required since event.value = 0.

Potential Fix

settings.get() and settings.getAll() suggest that undefined is a valid value for settings:

https://github.com/reddit/devvit/blob/8ca9b5e50acee0e950467ef8be98e4d996d977f8/packages/public-api/src/types/settings.ts#L58

https://github.com/reddit/devvit/blob/8ca9b5e50acee0e950467ef8be98e4d996d977f8/packages/public-api/src/types/settings.ts#L46

Devvit should set fields of type number equal to undefined when the submitted field was empty. This will allow for using input validation to require the field when 0 is a valid value for the field.