Skip to content

fix(mobile): start the send queue collapsed; keep the test environment's timers - #1617

Merged
huichen merged 3 commits into
mainfrom
pr/huichen
Nov 15, 2026
Merged

huichen merged 3 commits into
mainfrom
pr/huichen

Conversation

@huichen

@huichen huichen commented Nov 15, 2026

Copy link
Copy Markdown
Collaborator

Mobile chat: the queued-message panel above the composer now always starts as its header line, and the mobile test environment keeps its timers after a fake-timer round.

Two independent fixes that both came out of the queue-panel work: the panel used to expand itself when two or fewer messages were waiting, which is exactly the case where it covered the reply being waited on; and the mobile jest run was red on Node 26 for a reason that had nothing to do with what the tests assert.

Commits

  • fix(mobile): start the send queue collapsed above the composer — QUEUE_ROWS_SHOWN_BY_DEFAULT is gone; the panel is a header line (count, hint, parked warning) and draws rows only when tapped. A hand-made choice still outlives the queue changing under it.
  • fix(mobile): stop a fake-timer round from deleting the test environment's timers — jest-expo's native environment is now wrapped by mobile/jest.environment.js, which restores the clocked globals after jest.useRealTimers(). On Node 26 the global jest hands a test file is a proxy where setTimeout and friends are not own properties, so @sinonjs/fake-timers' uninstall() deletes them instead of restoring them, and any later VirtualizedList unmount dies with ReferenceError: clearTimeout is not defined.

Verification

Run in the main checkout at 4a1f819e7 (== origin/dev-huichen), Node 22.22.3 (/opt/homebrew/opt/node@22, the version CI uses):

  • npx tsc --noEmit in mobile/ → clean
  • npx eslint on all 6 changed TS/JS files → clean
  • npx jest (full mobile suite) → 171 suites / 3233 tests passed
  • the same npx jest under Node 26.3.0 → 171 suites / 3233 tests passed (this is the 13 suites / 298 tests the second commit un-breaks)
  • make check-docs → 421 docs checked, placement/pairing/links OK, provider matrix 13 rows

No Rust crate is touched, so no cargo lane was run locally.

User-visible changes

The phone's queued-message panel starts collapsed. Before: a queue of one or two messages opened by itself, covering part of the reply it was queued behind. After: the panel is always its header line (how many are waiting, the hint that they merge into one message when the current reply ends, a parked row's warning) and draws rows only when the reader taps it; a manual choice survives the queue changing underneath. Measured on the phone harness (?queue=2, 390×844): 50pt collapsed, 182pt with both rows open, and the composer does not move. Revert 420d4add9.

The jest environment change is test-only: no setting, default, migration or wire change. Revert 0194df9f3.

Notes

mobile/jest.environment.js is a no-op on Node 22 and Node 24; only Node 26 needs it.

…nt's timers

`MarkdownText.test.ts`'s "a file preview reflows the source's soft-wrapped
lines while a message keeps them" has been red for weeks on `dev-huichen` while
passing when the suite runs with a toolchain the repo pins. Neither side of it
was wrong: a file preview joins the source's soft breaks into spaces (CommonMark
reads an intra-paragraph newline as a space) and a chat bubble keeps the
newline its author typed, which is exactly what `joinSoftBreaks` in
`packages/markdown` does and what the test asserts. The test failed before it
reached the second half:

    ReferenceError: clearTimeout is not defined
      at VirtualizedList.componentWillUnmount

i.e. at `renderer.update(...)` switching the body from file-preview (a
`FlatList`) to a message, which unmounts the list.

The cause is one fake-timer round earlier in the same file. `jest.useRealTimers()`
reaches `@sinonjs/fake-timers`' `uninstall()`, which restores a clocked method
only when it was an own property of the global at install time and *deletes* it
otherwise. On Node 26 that global is a proxy where `setTimeout` and friends are
not own properties — `hasOwnProperty` and `in` both answer false while
`getOwnPropertyDescriptor` returns the real descriptor, and
`Object.defineProperty` cannot change the answer — so the timers react-native's
`setup-env` installed are deleted instead of restored, and every later unmount
in the file dies. Nothing in the component or its parser is involved.

Measured on `dev-huichen` (b31e6a4), mobile suite, before this commit:

  Node 22.22.3 (what 22 happens to do)   170 suites / 3233 tests, all green
  Node 24.22.3 (`.nvmrc`, CI)            170 suites / 3233 tests, all green
  Node 26.3.0 (this machine's default)   13 suites / 298 tests red

After it: 171 suites / 3234 tests green on Node 24.22.3 and on 26.3.0 (the 171st
suite is the canary below). Falsified by deleting the one `restore()` call:
`MarkdownText.test.ts` fails again with the `clearTimeout` ReferenceError and
the suite returns to 14 suites / 299 tests red on Node 26.

`jest` is one object per module, so no setup file can wrap `useRealTimers` for
the tests; every module's call goes through the per-file environment instance,
so the guard lives in a small subclass of jest-expo's native environment that
snapshots the timers just before the clock installs and puts back whatever the
uninstall removed. It is a no-op on Node 24, where nothing is ever removed.

`jestEnvironment.test.ts` pins that contract, so a future "cleanup" of the guard
cannot quietly hand the phantom reds back.
The phone's queue panel opened itself for any queue of two rows or fewer, so the
common case — one or two messages waiting behind a running reply — always covered
part of that reply. The header already says how many are waiting, what will happen
to them, and whether one is parked, so the panel can start as that line and draw
rows only when the reader asks: one tap opens it, another closes it, and a
hand-made choice outlives the queue changing underneath it.

The rule is gone rather than tuned: `QUEUE_ROWS_SHOWN_BY_DEFAULT` made the default
depend on a count nobody can see, and the two rows it let through were exactly
enough to hide the reply being waited on.

Measured on the phone harness (`?queue=2`, 390×844): the panel is 50pt as its
header and 182pt with both rows open; the composer does not move.
@huichen
huichen enabled auto-merge (squash) November 15, 2026 06:19
@huichen
huichen merged commit e5a1279 into main Nov 15, 2026
10 checks passed
@huichen
huichen deleted the pr/huichen branch November 15, 2026 06:36
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