Repository navigation
fix(mobile): start the send queue collapsed; keep the test environment's timers - #1617
Merged
Merged
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_DEFAULTis 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 bymobile/jest.environment.js, which restores the clocked globals afterjest.useRealTimers(). On Node 26 the global jest hands a test file is a proxy wheresetTimeoutand friends are not own properties, so@sinonjs/fake-timers'uninstall()deletes them instead of restoring them, and any laterVirtualizedListunmount dies withReferenceError: 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 --noEmitinmobile/→ cleannpx eslinton all 6 changed TS/JS files → cleannpx jest(full mobile suite) → 171 suites / 3233 tests passednpx jestunder 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 rowsNo 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. Revert420d4add9.The jest environment change is test-only: no setting, default, migration or wire change. Revert
0194df9f3.Notes
mobile/jest.environment.jsis a no-op on Node 22 and Node 24; only Node 26 needs it.