[Cross-platform] Inconsistent image format support between Web and Mobile (SVG, AVIF, HEIC)

未关闭
#881 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
35/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
活跃
技术栈
android, ios, react-native, typescript, web-dev

调研方向

Start with SanitizationConfig in src/types.ts and the Web sanitization path described in the issue, then trace image decoding through ios/interfaces/ImageAttachment.mm, ios/extensions/ImageExtension.mm, and the Android image classes. First determine which proposed direction maintainers want: configurable Web image filtering, documented format guarantees, or native SVG support. Done means the chosen behavior is consistent and covered across the affected platforms.

由索引模型根据 Issue 内容生成。

描述

Description

A core use case for react-native-enriched-html is storing a single HTML document produced in <EnrichedTextInput /> on Web (or Mobile) and rendering/editing the exact same HTML across Web, iOS, and Android.

Currently, supported image formats differ silently across platforms, so HTML created or pasted on Web renders fine in the browser but shows broken placeholders on iOS and Android:

  1. Web (EnrichedImageNodeView.tsx):
    • Delegates directly to browser <img>, so it renders SVG (image/svg+xml / .svg), AVIF, etc., without restriction (e.g. when pasted from external websites).
  2. iOS (ios/interfaces/ImageAttachment.mm + ios/extensions/ImageExtension.mm):
    • Decodes via Apple ImageIO (CGImageSourceCreateWithData / UIImage).
    • SVG is unsupported -> UIImage fails and falls back to [UIImage systemImageNamed:@"photo"].
    • AVIF fails on older iOS versions.
  3. Android (android/.../AsyncDrawable.kt + EnrichedImageSpan.kt):
    • Decodes via ImageDecoder (API 28+) / BitmapFactory.
    • SVG is unsupported -> fails and falls back to R.drawable.broken_image.
    • AVIF (API 31+) and HEIC depend on Android API level / device codecs, whereas Web (Chrome/Firefox on desktop) does not support HEIC in <img>.
Why app code cannot enforce cross-platform compatibility on Web

When users paste HTML content from external websites into <EnrichedTextInput /> on Web, <img src="https://.../diagram.svg"> passes right through prepareHtmlForTiptap / sanitizeHtml and is persisted into the database:

  • SanitizationConfig (src/types.ts) only exposes linkRegex, which maps directly to DOMPurify's ALLOWED_URI_REGEXP. Because DOMPurify applies ALLOWED_URI_REGEXP to all URI attributes (<a href> and <img src>), rejecting .svg via linkRegex also breaks valid <a href="...svg"> hyperlinks.
  • EnrichedTextInput keeps TipTap's editor and transformPastedHTML internal, so app code cannot cleanly filter out non-cross-platform image URLs (.svg, .avif, .heic, etc.) during HTML paste without brittle DOM/clipboard hacks.
Suggested improvements
  1. Separate image URI filtering on Web (SanitizationConfig or prop): Allow configuring image URI filtering independently from links (e.g. imageRegex or shouldAllowImage / transformPastedImage), so apps sharing HTML between Web and Mobile can ensure only cross-platform formats (PNG, JPEG, WebP, GIF) enter the document.
  2. Document guaranteed cross-platform formats (or align SVG/decoding): Explicitly document the safe cross-platform image subset across Web/iOS/Android, and consider either supporting SVG natively on mobile or exposing consistent error handling across Web, iOS, and Android.
Environment
  • react-native-enriched-html: 1.2.0
  • Platforms: Web (@tiptap/react), iOS (ImageAttachment), Android (AsyncDrawable / EnrichedImageSpan)
主要语言
C
星标
1.4k
派生
80
平均合并
4 天 19 小时
30 天内合并 PR
21

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 有 Pull Request 模板
  • 没有贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

software-mansion/react-native-enriched-html 的其他 Issue

查看 software-mansion/react-native-enriched-html 的全部 Issue

相似的 Issue

更多 C Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。