Skip to content

fix: prevent inline links rendering in 2-column grid layout#767

Merged
tellaho merged 5 commits into
mainfrom
tho/inline-links-fix
May 28, 2026
Merged

fix: prevent inline links rendering in 2-column grid layout#767
tellaho merged 5 commits into
mainfrom
tho/inline-links-fix

Conversation

@tellaho
Copy link
Copy Markdown
Collaborator

@tellaho tellaho commented May 28, 2026

Category: fix
User Impact: Links in messages no longer incorrectly render in a 2-column image grid — they display inline as expected.

Problem: When a paragraph contained 2+ links with no surrounding text, the links rendered in a grid grid-cols-2 gallery layout instead of inline. This made link-heavy messages look broken — links appeared side-by-side in boxes rather than flowing naturally in the text.

Solution: The classifyChildren heuristic used typeof child.type !== "string" to detect image elements, but in react-markdown v10 all custom components (links, mentions, channel-links, etc.) have function types — not just images. We now mark actual media output with a data-block-media attribute and check for that instead, so only real images/videos trigger the gallery grid.

File changes

desktop/src/shared/ui/markdownUtils.ts
Added an isBlockMedia() helper that checks for the data-block-media prop. Replaced the old typeof child.type !== "string" heuristic in classifyChildren with this explicit check so only actual media elements are classified as "image children."

desktop/src/shared/ui/markdown.tsx
Wrapped the img component's image (lightbox) and video output in <span data-block-media=""> so the classification logic can reliably identify them as block media.

desktop/src/shared/ui/markdown.test.mjs
Updated all classifyChildren, isImageOnlyParagraph, and hasBlockMedia tests to use data-block-media props instead of function-type heuristics. Added a new test confirming that React component elements without data-block-media (like links) are correctly classified as non-image.

Reproduction Steps

  1. Send a message containing two or more markdown links with no surrounding text, e.g. [link1](https://example.com) [link2](https://example.com)
  2. On main, observe the links render in a 2-column grid layout
  3. On this branch, observe the links render inline as normal text

Screenshots

Before (main — links misclassified as media, rendering in 2-column grid):
image

After (fix — links render inline correctly):
image

tellaho added 4 commits May 27, 2026 22:32
…ten weight

- Destructure `node` from react-markdown props to prevent spreading hast
  AST object onto native <a> elements (React warning + weird attrs)
- underline-offset-4 → underline-offset-2: 4px was too far from text at 14px
- Remove font-medium: 500 weight made links visually heavier than surrounding
  text, looked out of place inline
The classifyChildren heuristic used `typeof child.type !== 'string'` to
detect image elements, but in react-markdown v10 ALL custom components
(links, mentions, channel-links, etc.) have function types — not just
images. This caused paragraphs with 2+ links to trigger the grid gallery.

Fix: mark img component output with `data-block-media` attribute and
check for that in classifyChildren instead of the type check. Only actual
image/video elements now trigger the grid layout.

Tests updated to match the new heuristic.
@tellaho tellaho marked this pull request as ready for review May 28, 2026 16:53
@tellaho tellaho requested a review from a team as a code owner May 28, 2026 16:53
@tellaho tellaho enabled auto-merge (squash) May 28, 2026 17:31
@tellaho tellaho merged commit 835a44a into main May 28, 2026
15 checks passed
@tellaho tellaho deleted the tho/inline-links-fix branch May 28, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants