Skip to content

fix(mobile): read the code block tap Y before the state update - #7372

Closed
iscekic wants to merge 1 commit into
mainfrom
fix/mobile-code-block-location-y
Closed

iscekic wants to merge 1 commit into
mainfrom
fix/mobile-code-block-location-y

Conversation

@iscekic

@iscekic iscekic commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

Problem

On Android 1.0.13 (build 393), a tap on a code block in the transcript can crash the app with TypeError: Cannot read property 'locationY' of null.

Sentry: KILO-APP-3R1 (culprit setCopyActionTop$argument_0, code-block.tsx:318).

handleToggleCopyAction read event.nativeEvent.locationY inside the setCopyActionTop updater. React runs that updater later, at render time, when the block already has a pending update. At that time, React has released the press event and nativeEvent is null.

Fix

Read locationY synchronously in the press handler, before the setCopyActionTop call. The updater uses the captured value. The fallback to the block top for a press without coordinates does not change.

Verification

  • New test keeps the tap Y when React releases the press event before the state update runs: it queues a layout update on the block (so React does not run the updater eagerly), presses, then sets nativeEvent to null.
    • Without the fix: fails with TypeError: Cannot read properties of null (reading 'locationY') (the Sentry error).
    • With the fix: passes, and the action has top: 321.
  • vitest run src/components/agents/code-block.test.ts: 48 passed.
  • oxlint (mobile config) and oxfmt --check on the changed files: clean.

@kilo-code-bot

kilo-code-bot Bot commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

The change moves the locationY read out of the setCopyActionTop updater into the synchronous press handler, correctly fixing the deferred-updater null nativeEvent crash; the added test reproduces the deferred path and the fallback behavior is unchanged.

Files Reviewed (2 files)
  • apps/mobile/src/components/agents/code-block.tsx
  • apps/mobile/src/components/agents/code-block.test.ts

Reviewed by deepseek-v4.1-flash · Input: 43.5K · Output: 3.9K · Cached: 287.5K

Review guidance: REVIEW.md from base branch main

@iscekic

iscekic commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator Author

Investigated as KILO-APP-3R1. On current main the crash path is already unreachable, so this defensive change would ship dead code. Closing.

Evidence:

  1. The Sentry stack for KILO-APP-3R1 runs through MarkdownSegment / MarkdownSegmentFresh (see the event componentStack). Those components existed only in the old markdown-text.tsx, which rendered the fence through CodeBlock and passed onCopyCode.
  2. 70da80b62f ("refactor(mobile): unify the sheet, dialog, list, image and video surfaces", refactor(mobile): unify the sheet, dialog, list, image and video surfaces #7110, merged 2026-10-08) deleted MarkdownSegment/MarkdownSegmentFresh and replaced the fence path with MarkdownEnriched. On main, markdown-text.tsx no longer imports or renders CodeBlock; it passes onCopyCode to MarkdownEnriched only.
  3. The new native copy path calls onCopyPress={({ code }) => onCopyCode(code)} (markdown-enriched.tsx) and never touches a GestureResponderEvent, so it cannot null-deref nativeEvent.
  4. The only remaining CodeBlock call sites on main (markdown-mermaid.tsx, tool-cards/read-tool-card.tsx, tool-cards/write-tool-card.tsx) pass no onCopyCode, so canCopyCode is always false and the tap-to-copy trigger that calls handleToggleCopyAction never mounts. The crash line is unreachable in production.

The 1.0.13 event (reported 2026-10-10T10:27Z) is from a build cut 2026-10-06/07, before #7110. No code fix is needed on main.

Separately (not this PR): the tap-to-copy block-copy affordance became dead code in #7110, because no caller passes onCopyCode to CodeBlock any more. That is a pre-existing feature-loss question for the refactor, not a fix for this crash.

@iscekic iscekic closed this Oct 10, 2026
@iscekic
iscekic deleted the fix/mobile-code-block-location-y branch October 10, 2026 21:44
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