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

Abierto
#3,468 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
62/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
react, typescript
Área
frontend

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
TypeScript
Estrellas
845
Forks
295
Merge medio
1 d 8 h
PR fusionados (30 d)
106

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de GetStream/stream-chat-react

Todos los issues de GetStream/stream-chat-react

Issues similares

Más issues de TypeScript

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.