[Web] Pasted HTML (text + <img> without width/height) collapses images to 80px fallback

Abierto
#880 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 2 días

Nadie ha tomado este issue todavía.

Evaluación

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

Línea de trabajo

Read src/web/formats/EnrichedImageNodeView.tsx and src/web/EnrichedTextInput.tsx, focusing on how images without explicit dimensions are rendered and how pasted HTML reaches TipTap. Check the existing image node tests and add coverage for mixed text and image paste where the image has no width or height. Done means the image uses its natural dimensions after loading while the pasted text remains intact.

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

Descripción

bug
Description

On Web, when pasting mixed HTML content from an external webpage (text together with one or more <img> elements that rely on CSS sizing and omit explicit width/height HTML attributes), EnrichedImageNodeView renders those images at 80px width (IMAGE_FALLBACK_SIZE = 80).

Why app code cannot cleanly work around this
  • Standalone image paste (Copy Image / clipboard File): This can be handled at the app level using onPasteImages (for binary clipboard files) or intercepting a single-image paste event in capture phase and inserting via ref.setImage(src, width, height) after probing natural dimensions.
  • Mixed HTML paste (text + images): There is no clean way to handle this without modifying react-native-enriched-html or using brittle DOM hacks (preventDefault() + async dimension probing that blocks pasting the text + re-injecting via execCommand/synthetic events):
    • EnrichedTextInput keeps the TipTap editor instance and transformPastedHTML internal.
    • The imperative ref (EnrichedTextInputInstance) has no command to update an existing image node's attributes after paste — only setValue(fullHtml), which resets selection/cursor and undo history.

This also hurts cross-platform consistency, since native iOS (ImageAttachment) and Android (EnrichedImageSpan) rely on HTML width and height attributes to compute image bounds.

Relevant code in 1.2.0
  • src/web/formats/EnrichedImageNodeView.tsx:
    • When rawW == null && rawH == null, imgDims falls back to { width: IMAGE_FALLBACK_SIZE } (80).
  • src/web/EnrichedTextInput.tsx:
    • handleClipboardPasteImages handles binary File pastes (onPasteImages), whereas HTML pastes with <img> go straight through prepareHtmlForTiptap.
Steps to reproduce
  1. Copy a selection containing text and an <img> without width/height HTML attributes from a webpage (e.g. <p>Some text</p><img src="https://example.com/photo.jpg">).
  2. Paste into <EnrichedTextInput /> on Web.
  3. Notice the pasted text renders properly, while the image width is clamped to 80px (width="80") regardless of its naturalWidth.
Suggested improvement

In EnrichedImageNodeView.tsx, when node.attrs.width == null && node.attrs.height == null, listen to onLoad on the <img> element and call TipTap's updateAttributes({ width: img.naturalWidth, height: img.naturalHeight }) once decoded (or expose a clean prop/hook to transform/update pasted HTML and image nodes).

Environment
  • react-native-enriched-html: 1.2.0
  • Platform: Web (@tiptap/react)
Lenguaje dominante
C
Estrellas
1.4k
Forks
80
Merge medio
4 d 19 h
PR fusionados (30 d)
21

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

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 software-mansion/react-native-enriched-html

Todos los issues de software-mansion/react-native-enriched-html

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.