Skip to content

fix(mobile): render code blocks and tables in markdown - #281

Merged
nixuuu merged 1 commit into
devfrom
fix/mobile-markdown
Nov 6, 2026
Merged

nixuuu merged 1 commit into
devfrom
fix/mobile-markdown

Conversation

@nixuuu

@nixuuu nixuuu commented Nov 6, 2026

Copy link
Copy Markdown
Member

Root cause

Code blocks (and tables, diff fences) used a horizontal ScrollView, which keeps React Native's default flexGrow: 1. Inside a fit-content parent such as a bot chat bubble (alignItems: "flex-start"), the scroller takes a runaway height. The block then shows as a tall, empty box, and the text after it renders normally.

Evidence: measured with onLayout in a temporary fixture screen (not committed) on an iOS 26.0 simulator and an Android 16 emulator (Canopy_Fold):

Variant inside a bubble iOS height Android height
old code block (ScrollView horizontal, padding on style) 4851–5223 pt, changes per layout pass 4867 dp
same with flexGrow: 0 84 85
without row parent / maxWidth / with flexShrink: 0 runaway runaway
same scrollers outside a fit-content parent, in normal and inverted lists 34 (correct) —

So the font (monospace on iOS), the inverted list and fixed heights were not the cause. Before the fix, every sample with a horizontal scroller measured ~1729 pt in the real ChatBubble (code, empty code, long line, both tables, diff). After the fix they measure 90–412 pt. Android was affected too, not only iOS. Sideways scrollers in markdown and Diff now set flexGrow: 0 (docs/mobile.md notes the pitfall).

Changes

  • @canopy/domain/markdown (new): the lexer with $…$/$$…$$ math, safeHref, isToken and the inline-element sentinels, moved from apps/web/src/lib/shared/ui/markdown unchanged in behaviour. The web now imports them from there; mobile uses the same token tree and link rules.
  • apps/mobile/src/ui/markdown/ replaces the single-file renderer with small components: Markdown, Blocks, Inline, CodeFence, MarkdownList, MarkdownTable, scope, text-style.
  • Inter italic faces are loaded: iOS does not slant a custom family by fontStyle, so italics showed upright. Faced keeps weight and slant through nested text (bold italic, italic in a heading).
  • User messages (thread input, agent-bus messages) render as markdown with line breaks and mention badges inside the text, as on the web (UserMessageView).
  • Prose tools (Skill, ExitPlanMode) show their long arguments and result as markdown (web: MarkdownBody) instead of a monospace output block.

No new dependency: marked was already in mobile and web, and @canopy/domain now declares it.

Elements: web vs mobile (before → after)

Element Web Mobile before Mobile after
Headings semibold, 18/28, 16/28, 16/24 sizes ok; 3+ same as body same as web, ink colour, header role
Paragraphs, soft/hard breaks yes yes yes
Bold semibold, strongest ink yes yes
Italic yes upright (no Inter italic loaded) Inter italic faces, nested with bold
Strike (~~) <del> missing (plain text) line-through
Inline code mono 0.875em on zinc-950/5 "monospace" (not an iOS family) reader's mono font, web wash
Code block frame, language label, copy, scrolls sideways tall empty box on iOS/Android in bubbles frame with ring, language label, scrolls inside the block, Wrap code respected; empty block keeps one line
Copy button on code yes no no (needs expo-clipboard, a native dependency; text is selectable)
diff fence diff lines Diff, tall empty box in bubbles Diff, fixed
Lists: ordered, start, nested yes yes yes, muted markers
Task lists read-only checkbox plain bullets read-only checkbox (checkbox role, Done / Not done)
Loose list items blocks blocks blocks
Blockquote rule + muted text, nested accent rule, body text hairline rule, muted text, nested
Tables header, alignment, wrapping cells, scrolls sideways cells joined by " | " into one line header row, alignment, long cells wrap, wide tables scroll sideways, narrow tables fill
Links http(s)/mailto only, others as text http(s) only via regex shared safeHref (adds mailto), others as text
Images never loaded, link to the image [Image: …] text link to the image when safe, else alt text
Horizontal rule hairline hairline hairline
Math KaTeX (raw TeX when off) not parsed ($$ as text) parsed like the web, shown as TeX source (inline mono, display scrolls sideways)
Raw HTML shown as text text text
Escapes yes yes yes
Mention badges in text chips via sentinels, source text in code user messages plain text with badges, no markdown markdown + badges in place, source text in code

Where markdown renders on mobile

Agent messages (AgentMessageView), bot chat bubbles (ChatBubble), reasoning and compaction summaries, checklists, subagent prompts/results, agent-bus instructions and messages, turn inputs from other origins (TurnInput), Typography settings preview: all through Markdown. New: user messages and prose tool bodies. Goals and notices on mobile show plain text, also on the web.

Verification

  • iOS Simulator (iPhone 17 Pro, iOS 26.0) with an EAS development-simulator build. Android emulator Canopy_Fold (Android 16) with an EAS development APK. Both ran against my own Metro. The real ChatBubble, AgentMessageView and UserMessageView were rendered in the same inverted list setup as the bot chat, through a temporary fixture route (not committed). The fixture had one message per element and these edge cases: 200+ char code line, 10-column table, 4-level nested list, empty code block, long table cell, javascript: link, mentions inside code spans.
  • Light and dark on iOS (bot and thread modes) and Android.
  • On iOS a link tap opened Safari for https://example.com; tapping the javascript: link did nothing.
  • Gates: bun install, bun run gen:check, bun run typecheck, bun run lint, bun run format:check, bunx expo lint, bun run check:tmp (1499 pass, 0 fail, temp dir clean), web build.

Not verified: a seeded gateway end to end (the fixture used the production components, not a paired gateway). Physical iPhone. Android phone width (the Fold was unfolded; phone width was checked on iOS). Interface font set to system/serif.

Copy audit (docs/copy.md §8)

Text Before → after Reason
Code block a11y label — → "Code" / "Code, ‹lang›" names the block for screen readers
Task checkbox a11y label — → "Done" / "Not done" same words as the web
Prose tool sections — → humanized argument name, "Result" same labels as the web

All are short and in sentence case, with no glossary terms and no fact repeated. The checkbox state is not conveyed by colour alone: the check mark and the label carry it.

A horizontal ScrollView keeps React Native's default flexGrow: 1. Inside a
fit-content parent such as a chat bubble (alignItems: flex-start) it took a
runaway height on iOS and Android, so code blocks, tables and diff fences
showed as a tall empty box. Sideways scrollers now never grow.

The mobile renderer is rebuilt from small components and shares the
lexer (with math), safe-link rules and inline-element sentinels with the
web through @canopy/domain/markdown. It adds language labels, tables with
columns and alignment, task lists, strike, italics in Inter, link and
image rules from the web, raw HTML as text, math as TeX source, markdown
in user messages with mention badges, and markdown bodies for prose tools.

Related: #246, #276
@nixuuu
nixuuu merged commit a456b41 into dev Nov 6, 2026
9 checks passed
@nixuuu
nixuuu deleted the fix/mobile-markdown branch November 6, 2026 15:28
nixuuu added a commit that referenced this pull request Nov 12, 2026
Wide Markdown tables can lose horizontal drags to navigation on iOS,
while Android readers can be left with clipped columns. Tables,
unwrapped code, display math and diffs now share a native Gesture
Handler scroller with Android nested scrolling, a horizontal indicator
and an overflow shadow. Main-stack back navigation starts at the screen
edge; dragging inside a block keeps the conversation open.

### Diagnosis and change

- The main Expo Router stack left `fullScreenGestureEnabled` unset. The
installed `react-native-screens` 4.30.1 explicitly treats that state as
**enabled on iOS 26** (`RNSScreen.mm`,
`isFullScreenSwipeEffectivelyEnabled`), despite the router documentation
describing a false default. Set it to false in the main stack,
preserving the native edge recognizer and leaving `gestureEnabled`
intact. This covers threads, side threads and bot conversations.
- The timeline is an inverted Reanimated `FlatList`, with a native iOS
scroll view and `KeyboardChatScrollView` on Android. Embedded
tables/code/diffs used React Native horizontal `ScrollView`s without
Android nested scrolling. Replace them with one `HorizontalScroll` using
Gesture Handler's installed v3 `ScrollView`, `nestedScrollEnabled` and
iOS directional locking; also enable nesting on the timeline. Its local
gesture root supports blocks rendered inside Android modal viewers. No
competing pan was found on timeline rows. Native reproduction was
unavailable, so Android interception and the exact failing gesture
sequence remain device checks.
- The sidebar is a column toggled by a button, without a screen-wide
drawer pan. #549's archive PanResponder is attached only to sidebar
thread rows. #554's disclosure changes animate height and anchoring
without adding a pan recognizer. Neither introduced this conflict. #281
introduced the table/code scroll containers with the current screens
version and missing nesting/navigation restriction.
- Bound both header and body column widths to 72–224 dp plus padding;
long headings wrap too. Memoize width estimates and avoid spreading
every row into `Math.max`. Tall tables retain natural height so vertical
drags scroll the timeline. The 16 dp right-edge overflow shadow
disappears at the right end and when content fits. Scroll offsets and
shadow opacity stay on the UI thread through Reanimated; no per-frame JS
callback, pan loop, list reconfiguration or item-height estimate is
added.
- Gesture Handler 3.3.0 was already locked, installed and autolinked on
both platforms through the existing dependency graph. Declare that exact
version directly in mobile; the lock change only adds the workspace
dependency entry. No native package version, native source, app config
or EAS profile changes. Polish mobile documentation updated. Copy audit
(`docs/copy.md` §8): no UI strings changed. No UI tests or diagnostic
artifacts added.

### Verification

- `bun install --frozen-lockfile` passed, followed by `bunx expo install
[email protected] --bun` using the already installed
version.
- Mobile `bun run typecheck`, root `bun run lint apps/mobile`, `bun run
format:check apps/mobile docs/mobile.md`, and `git diff --check` pass.
Expo ESLint passes for all six changed TSX files, including the new
scroller.
- Mobile `bun run lint` (Expo ESLint) reports 63 errors and 10 warnings
in existing source files. An independent archive of untouched `dev` with
the same installed tooling reports the same 63 source errors and 10
warnings (direct `eslint .` additionally checks `metro.config.cjs` and
reports its existing `__dirname` diagnostic). All six changed TSX files
have zero ESLint errors/warnings. Repository oxlint is clean. No lint
rules were disabled.
- Production fingerprints generated before and after in the same
checkout/environment with `bunx [email protected] fingerprint:generate
--platform <ios|android> --build-profile production --json
--non-interactive` are byte-for-byte identical: iOS
`6ddec9ef559ee0095ac33e94ff9418a942053b17`; Android
`5f6eae3ab278f1cd543e9ed763f923a319b65ec9`. These match the prior
production-compatible baseline; this remains JS-only.
- No device session, native frame-time/memory measurement, UI test, full
`check:tmp`, web build, CNG prebuild or bundle export was run. Device
behavior/performance is **unverified**, not inferred from static checks.
CI owns the full repository checks, as requested.

### Maintainer device checklist

Use the same installed native build and same thread for baseline versus
this branch's JS. Record OS/device, app version/runtime/update ID and
channel. Include an iPhone on iOS 26 and an Android phone; check an
older supported iOS version if available. Test light/dark,
portrait/landscape and a wide layout with the sidebar open/closed.

1. **Horizontal ownership:** open a three-column table like `Zgłoszenie
| Nowy status | Dlaczego…`, with enough text to overflow. Start 20
alternating horizontal drags on header text, body text and blank cell
padding, away from the left screen edge. Drag left to reveal the last
column, right from halfway to recover the first, then right again at
offset zero. Every interior drag should stay in the conversation; every
column must be reachable. Repeat in an assistant answer, a human
message, a bot bubble and expanded tool/summary content. Include short
cells, a very long heading, long unbroken text, and a table that fits
entirely.
2. **Back/sidebar:** from a thread with a previous screen, swipe right
starting within the leftmost 16 dp of the display; native back must
still work. Cancel one edge swipe and complete another. Interior swipes
must never navigate, including when already at the table's left end.
Repeat in a side thread and bot conversation. Toggle the wide sidebar,
scroll its list vertically, and confirm its archive swipe still works
only on sidebar rows.
3. **Tall tables and vertical feed:** use a table at least two
screen-heights tall. Drag vertically starting over header/body/padding
and diagonally with mostly vertical movement, including while
horizontally offset. The outer inverted timeline should move through the
full table without trapping the gesture, clipping the settled content or
folding the composer from a horizontal-only drag. Repeat with keyboard
open/closed, during a streaming response, after loading older history,
and after closing/reopening a work disclosure. Confirm jump-to-latest
still works.
4. **Other blocks and affordance:** repeat interior horizontal drags on
a long code line, display math, stacked and split diffs, and a full-diff
modal viewer. Toggle Wrap code/Wrap diffs and confirm wrapped content
still scrolls vertically. The horizontal indicator should appear during
scrolling; the subtle right shadow should show only while content
remains to the right, disappear at the end, and update after
rotation/font-size changes. Check both themes and Reduce Motion; no
content or controls should move when the shadow changes. Check
VoiceOver/TalkBack can reach all content and ignores the decorative
edge.
5. **Long-thread performance:** on the same device/build mode, compare
baseline and changed JS on the same 1,000-turn thread with multiple
tables/code/diffs. After warmup, record three 30-second vertical flings
and 20 horizontal table drags in the native profiler. Compare dropped
frames/UI frame time, JS activity and settled memory after
opening/closing many summaries. Expect no new React render or JS
callback per horizontal-scroll frame and no repeatable
frame-pacing/memory regression; record the measured result before
merging. Restore normal settings afterward.

Fixes: #281
Related: #549
Related: #554
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.

1 participant