Repository navigation
Commit 1ad45b9
authored
fix(ai-components): restart useHeardText for a new text and treat Infinity as fully heard (#3349)
### Goal
Bring the `useHeardText` fixes 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()` and `live`, so
the new text could appear already revealed. `chars: Infinity` revealed
nothing, contrary to the type doc. The docs also suggested returning
`undefined` for 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 `835c3eb66` from `feat/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.
- The reveal state now records the text it refers to. When `text` is
replaced by a different text, the reveal starts over: the length shown
and `skip()` are reset, and `live` is 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: Infinity` reveals the whole text; NaN, negative and
non-numeric counts still reveal nothing.
- Docs (type doc and `README.md`): `undefined` is 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 }`. `subscribe` is bound once
(remount with a `key` to switch sources) and is the only wake-up for a
settled hook. `heard` is called during render, so it must be free of
side effects.
- 6 new tests in `useHeardText.test.ts` cover the new-text reset,
truncation, `skip()` and `live` reset, and `Infinity`.
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`.1 parent 2380514 commit 1ad45b9
3 files changed
Lines changed: 192 additions & 43 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
588 | 588 | | |
589 | 589 | | |
590 | 590 | | |
591 | | - | |
| 591 | + | |
592 | 592 | | |
593 | 593 | | |
594 | 594 | | |
595 | | - | |
596 | | - | |
597 | | - | |
598 | | - | |
599 | | - | |
600 | | - | |
601 | | - | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
602 | 602 | | |
603 | 603 | | |
604 | 604 | | |
| |||
610 | 610 | | |
611 | 611 | | |
612 | 612 | | |
613 | | - | |
614 | | - | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
615 | 616 | | |
616 | | - | |
| 617 | + | |
617 | 618 | | |
618 | 619 | | |
619 | 620 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
83 | 100 | | |
84 | 101 | | |
85 | 102 | | |
| |||
290 | 307 | | |
291 | 308 | | |
292 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
293 | 377 | | |
294 | 378 | | |
295 | 379 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
21 | 26 | | |
22 | 27 | | |
23 | 28 | | |
| |||
39 | 44 | | |
40 | 45 | | |
41 | 46 | | |
42 | | - | |
| 47 | + | |
| 48 | + | |
43 | 49 | | |
44 | 50 | | |
45 | | - | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
46 | 57 | | |
47 | 58 | | |
48 | 59 | | |
| |||
56 | 67 | | |
57 | 68 | | |
58 | 69 | | |
59 | | - | |
| 70 | + | |
60 | 71 | | |
61 | 72 | | |
62 | 73 | | |
63 | 74 | | |
64 | 75 | | |
65 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
66 | 86 | | |
67 | 87 | | |
68 | 88 | | |
| |||
121 | 141 | | |
122 | 142 | | |
123 | 143 | | |
124 | | - | |
125 | | - | |
126 | | - | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
127 | 148 | | |
128 | 149 | | |
129 | 150 | | |
| |||
132 | 153 | | |
133 | 154 | | |
134 | 155 | | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
135 | 189 | | |
136 | 190 | | |
137 | 191 | | |
| |||
141 | 195 | | |
142 | 196 | | |
143 | 197 | | |
144 | | - | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
145 | 202 | | |
146 | 203 | | |
147 | 204 | | |
148 | 205 | | |
149 | 206 | | |
150 | | - | |
| 207 | + | |
151 | 208 | | |
152 | 209 | | |
153 | 210 | | |
154 | 211 | | |
155 | 212 | | |
156 | 213 | | |
157 | | - | |
| 214 | + | |
| 215 | + | |
158 | 216 | | |
159 | 217 | | |
160 | 218 | | |
| |||
186 | 244 | | |
187 | 245 | | |
188 | 246 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
199 | | - | |
| 247 | + | |
| 248 | + | |
200 | 249 | | |
201 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
202 | 260 | | |
203 | 261 | | |
| 262 | + | |
| 263 | + | |
204 | 264 | | |
205 | 265 | | |
206 | 266 | | |
| |||
209 | 269 | | |
210 | 270 | | |
211 | 271 | | |
212 | | - | |
| 272 | + | |
213 | 273 | | |
214 | 274 | | |
215 | 275 | | |
| |||
224 | 284 | | |
225 | 285 | | |
226 | 286 | | |
227 | | - | |
228 | | - | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
229 | 290 | | |
230 | 291 | | |
231 | 292 | | |
| |||
249 | 310 | | |
250 | 311 | | |
251 | 312 | | |
252 | | - | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
253 | 317 | | |
254 | 318 | | |
255 | | - | |
256 | | - | |
| 319 | + | |
| 320 | + | |
257 | 321 | | |
258 | | - | |
| 322 | + | |
259 | 323 | | |
260 | 324 | | |
261 | 325 | | |
0 commit comments