fix(edit-modal): Listening Length throws "trim is not a function" on every keystroke#709
Open
kevinheneveld wants to merge 1 commit into
Open
Conversation
…every keystroke The Listening Length field is `<input type="number" v-model="formData.runtime">`. Vue's v-model coerces a `type="number"` input to a JS number (vModelText casts whenever `el.type === 'number'`, even without the `.number` modifier), so `formData.runtime` holds a number at runtime despite its declared string type. `normalizeNumericInput` then ran `(value || '').trim()` on that number, and `Number.prototype` has no `trim()`, throwing a `TypeError` on every keystroke. Vue's global errorHandler caught each one (surfacing an "Unexpected Error" toast per keystroke) and the accumulating failure tore the edit modal down. An empty field is `''` (a real string), so it only manifested once a digit was typed. Harden `normalizeNumericInput`/`parseRuntimeInput` to accept `string | number` and `String()`-coerce before trimming. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Editing Listening Length (minutes) in the audiobook edit modal throws on every keystroke. Each digit produces an "Unexpected Error — Something went wrong. Please refresh the page." toast, and after a few keystrokes the modal tears down.
Root cause
The field is
<input type="number" v-model="formData.runtime">. Vue'sv-modelcoerces atype="number"input to a JS number —vModelTextcasts wheneverel.type === 'number', even without the.numbermodifier. SoformData.runtimeholds a number at runtime, despite being typedstring.normalizeNumericInputthen runs:Number.prototypehas no.trim(), so this throwsTypeError: (value || "").trim is not a function. It's invoked from the dirty-check (hasChanges) which re-evaluates on every keystroke. Vue's globalerrorHandlercatches it (hence the toast rather than a console error), and the repeated failure unmounts the modal.An empty field is
''(a genuine string), which is why it only surfaces once a digit is typed.Fix
Harden
normalizeNumericInput/parseRuntimeInputto acceptstring | numberandString()-coerce before trimming:Verification
Reproduced in a real browser by hooking the running app's
errorHandlerto capture the swallowed stack (TypeError: (e || "").trim is not a function), confirmed every keystroke threw and the 3rd closed the modal. After the fix: typing452leaves the modal open with zero error toasts and the field value intact.vue-tscpasses.🤖 Generated with Claude Code