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

Open
#82 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
api

Research direction

Start with the settings type definitions in packages/public-api/src/types/settings.ts, especially the get() and getAll() declarations linked in the issue, then trace how submitted number fields are converted. Done means an empty number field remains undefined while an entered 0 remains 0, allowing required-field validation to distinguish the two cases.

Written by the indexing model from the issue text.

Description

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.

Dominant language
TypeScript
Stars
210
Forks
88
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from reddit/devvit

All issues in reddit/devvit

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.