bug: Composer textarea doesn't resize when the SDK sets its text (paste, draft, clear after send)

Aperta
#3,468 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
62/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
react, typescript
Ambito
frontend

Direzione di ricerca

Start in TextareaComposer.tsx, where a useLayoutEffect writes textarea.value from the composer's text without notifying the autosize component. Reproduce by changing the text programmatically to a multi-line value and checking the textarea height, then compare with typing. Done means the height follows the text after paste, draft restore and clear-after-send, and a test covers one of these cases.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Describe the bug

TextareaComposer writes the composer's text into the textarea itself, in a useLayoutEffect:

if (textarea.value !== text) {
  textarea.value = text;
}

react-textarea-autosize measures the textarea in its own layout effect, which runs first because it's a child, and again on onChange and window resize. A value written from outside doesn't trigger any of those. So when the text changes without the user typing, the textarea keeps its old height:

  • Multi-line paste that goes through the composer's paste handling: it doesn't grow.
  • A restored draft on opening a channel: it stays one row high.
  • Clearing after sending a multi-line message: it stays tall.

It corrects itself on some later render, often a second or two later.

To Reproduce

  1. Type a message that wraps to four or five lines, and send it. The empty textarea stays four or five lines tall.
  2. Or: type a multi-line draft, switch to another channel and back. The restored draft shows in a one-row textarea.

Expected behavior

The textarea fits its text as soon as the text changes, however it changed.

Suggested fix

After writing textarea.value, trigger react-textarea-autosize's measurement. For example, re-render once after the write, or measure through a ref-exposed resize. We can open a PR with a test.

Our workaround

We wrap TextareaComposer and render it once more in a useLayoutEffect keyed on the composer's text. A parent's layout effect runs after the child's, so by then the SDK has written the value and the extra render re-measures it. We also had to opt this component out of the React Compiler ("use no memo"), or the compiler skips that render.

Package version

  • stream-chat-react: 15.0.0. TextareaComposer.tsx is unchanged in 15.0.2.
  • stream-chat-js: 10.0.1

Desktop

  • Chrome on macOS

Additional context

App id: 67855

Lingua principale
TypeScript
Stelle
845
Fork
295
Merge medio
1g 8h
PR unite (30g)
106

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di GetStream/stream-chat-react

Tutte le issue di GetStream/stream-chat-react

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.