Repository navigation
fix(ai-components): restart useHeardText for a new text and treat Infinity as fully heard - #3349
Conversation
…inity as fully heard - Start the reveal over when `text` is replaced by a different text (the next reply rendered by the same component): the length shown and skip() reset, and `live` is read again. Growing or truncating the text keeps the reveal, capped at the new length. - `chars: Infinity` reveals the whole text, as the type doc says. - Document that `undefined` is only for text that is not spoken, that `subscribe` is bound once (remount to switch sources) and is the only wake-up for a settled hook, and that `heard` runs during render.
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the
|
|
Size Change: +828 B (+0.07%) Total Size: 1.18 MB 📦 View Changed
ℹ️ View Unchanged
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## release-v14 #3349 +/- ##
===============================================
- Coverage 86.84% 86.44% -0.41%
===============================================
Files 526 541 +15
Lines 16699 17603 +904
Branches 5251 5424 +173
===============================================
+ Hits 14503 15217 +714
- Misses 2196 2386 +190 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Goal
Bring the
useHeardTextfixes from the v15 port (#3348) to the v14 line, which shipped the hook in 14.14.1 (#3343, #3344) and shares the same issues. When the same mounted component rendered a new reply, the hook kept the previous reply's reveal length,skip()andlive, so the new text could appear already revealed.chars: Infinityrevealed nothing, contrary to the type doc. The docs also suggested returningundefinedfor text the voice source does not know yet, which shows the full text before it is heard and defeats pacing.Implementation details
Cherry-pick of
835c3eb66fromfeat/ai-components-use-heard-text. The hook and its tests were byte-identical between the two lines before that commit, and the README hunks applied without conflict.textis replaced by a different text, the reveal starts over: the length shown andskip()are reset, andliveis read again. Growing or truncating the text keeps the reveal, capped at the new length. The reset happens during render, so the new text never renders with the previous reveal.chars: Infinityreveals the whole text; NaN, negative and non-numeric counts still reveal nothing.README.md):undefinedis only for a text that is not spoken at all, and a text that will be spoken but is not known yet must return{ chars: 0, done: false }.subscribeis bound once (remount with akeyto switch sources) and is the only wake-up for a settled hook.heardis called during render, so it must be free of side effects.useHeardText.test.tscover the new-text reset, truncation,skip()andlivereset, andInfinity.No public API change: the exported types and signature are unchanged.
UI Changes
None. The hook's reveal behaviour changes only for a component that renders a different text, and for
chars: Infinity.