fix(speech): filter undefined voices from getVoicesAsync#1239
fix(speech): filter undefined voices from getVoicesAsync#1239sentry[bot] wants to merge 1 commit into
Conversation
Greptile SummaryThis PR fixes a
Confidence Score: 4/5Safe to merge — the change is a two-line defensive filter applied symmetrically to both code paths with no behavioral change for well-formed browsers. The fix is correct and minimal. The only gap is the absence of a regression test, which the project's own guidelines call for on bug fixes. Without it, the specific crash condition (undefined elements in getVoices()) has no automated guard against future regression. Files Needing Attention: apps/web/src/utils/speech.ts — functional fix is fine, but a regression test covering the undefined-element case is missing.
|
| Filename | Overview |
|---|---|
| apps/web/src/utils/speech.ts | Adds .filter(Boolean) to both getVoices() call sites to strip undefined elements before resolving; fix is correct and symmetric. No regression test included despite project guidelines requiring one for bug fixes. |
Sequence Diagram
sequenceDiagram
participant Caller
participant getVoicesAsync
participant speechSynthesis
Caller->>getVoicesAsync: call()
getVoicesAsync->>speechSynthesis: getVoices()
speechSynthesis-->>getVoicesAsync: voices[] (may contain undefined)
getVoicesAsync->>getVoicesAsync: .filter(Boolean) as SpeechSynthesisVoice[]
alt "voices.length > 0"
getVoicesAsync-->>Caller: resolve(filteredVoices)
else voices empty
getVoicesAsync->>speechSynthesis: addEventListener("voiceschanged", handler)
speechSynthesis-->>getVoicesAsync: voiceschanged event fires
getVoicesAsync->>speechSynthesis: getVoices()
speechSynthesis-->>getVoicesAsync: voices[] (may contain undefined)
getVoicesAsync->>getVoicesAsync: .filter(Boolean) as SpeechSynthesisVoice[]
getVoicesAsync->>speechSynthesis: removeEventListener("voiceschanged", handler)
getVoicesAsync-->>Caller: resolve(filteredVoices)
end
Comments Outside Diff (1)
-
apps/web/src/utils/speech.ts, line 1-14 (link)Missing regression test for the bug fix
The project's own guidelines (CLAUDE.md) state that bug fixes should include regression tests.
getVoicesAsyncis a pure utility function that is straightforward to unit-test with Vitest: mockwindow.speechSynthesis.getVoicesto return[undefined, voiceObj]and assert the resolved array contains only the valid voice. Without this, the crash can silently regress if the filter is ever removed or refactored.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Reviews (1): Last reviewed commit: "fix(speech): filter undefined voices fro..." | Re-trigger Greptile
The
TypeError: undefined is not an object (evaluating 'Object.getPrototypeOf(voice)')occurred when iterating over thevoicesarray returned bywindow.speechSynthesis.getVoices(). This was observed specifically on Brave browser on iOS 18.7, where the browser's implementation ofgetVoices()could return an array containingundefinedelements.This fix modifies the
getVoicesAsyncfunction inapps/web/src/utils/speech.tsto filter out any falsy (includingundefined) values from the array returned bywindow.speechSynthesis.getVoices()before resolving the promise. This ensures that only validSpeechSynthesisVoiceobjects are processed, preventing theTypeError.Fixes ECENCY-NEXT-1GJH