Skip to content

fix: detect message links with linkifyjs instead of a backtracking regex - #750

Merged
oliverlaz merged 1 commit into
masterfrom
fix/message-text-link-detection
Nov 26, 2026
Merged

oliverlaz merged 1 commit into
masterfrom
fix/message-text-link-detection

Conversation

@oliverlaz

Copy link
Copy Markdown
Member

🎯 Goal

MessageTextComponent used a regular expression to find links in message text. On some inputs that regex took a very long time, blocking rendering of the message list. This replaces it with linkifyjs, which scans text in linear time. It is the same library stream-chat-react uses, and stream-chat already depends on it, so apps download nothing extra.

🛠 Implementation details

  • find(text, 'url', { defaultProtocol: 'https' }) is used both for the "does this message need parsing?" check and for wrapping links in anchors. The regex and its fallback for browsers without lookbehind support are removed.
  • A detected link is cut at < / >, so it never runs into the emoji wrapper markup that is added before link detection.
  • Only http, https, ftp and file links become anchors, so e-mail addresses and mailto: stay plain text, as before. Links without a scheme still get https://.
  • " in a link's href is escaped.
  • linkifyjs@^4.4.0 is added to the library's dependencies (and the ng-packagr allowlist). Versions before 4.4.0 are slow on some long inputs, and a spec covers that.

Behaviour changes

  • Hostnames on TLDs linkifyjs doesn't recognise (for example *.internal, *.corp, *.local) and file names such as main.ts are no longer linked.
  • Bare localhost:3000 and URLs containing @ (for example https://medium.com/@user) are now linked.
  • Trailing punctuation is no longer part of the link (example.com. links example.com).

🧪 Testing

  • New specs: long or unusual input renders within a time limit, e-mails and mailto: aren't linked, a link right before an emoji, common link shapes.
  • I checked that the timing spec fails when linkifyjs 4.3.3 is installed.
  • ng run stream-chat-angular:test: 867/867 passing. eslint, prettier --check and ng build stream-chat-angular are clean.

@oliverlaz
oliverlaz merged commit ed18cba into master Nov 26, 2026
4 checks passed
@oliverlaz
oliverlaz deleted the fix/message-text-link-detection branch November 26, 2026 08:36
github-actions Bot pushed a commit that referenced this pull request Nov 26, 2026
## [8.0.1](v8.0.0...v8.0.1) (2026-11-26)

### Bug Fixes

* detect message links with linkifyjs instead of a backtracking regex ([#750](#750)) ([ed18cba](ed18cba))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 8.0.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants