Skip to content

fix: flaky CI from early press timers and Yarn network crash - #1972

Merged
mdjastrzebski merged 3 commits into
mainfrom
fix/ci-flakes
Dec 3, 2026
Merged

mdjastrzebski merged 3 commits into
mainfrom
fix/ci-flakes

Conversation

@mdjastrzebski

Copy link
Copy Markdown
Member

Summary

Fixes two causes of random CI failures. Each fix is its own commit.

1. userEvent.press could return before pressOut with real timers

Nightly runs failed in press.real-timers.test.tsx ("calls press when pressable has pointer events box-only") with the event sequence pressIn, press and no pressOut.

Pressability measures press duration with Date.now(). If it sees less than 130ms (DEFAULT_MIN_PRESS_DURATION), it delays onPressOut with a setTimeout. emitPressabilityPressEvents waited setTimeout(130) and only waited for the delayed pressOut when duration < 130. Node timers can fire up to ~1ms early compared to Date.now() (libuv schedules from cached loop time). In about 1% of runs, RN measured 129ms, delayed pressOut, and press() resolved before it fired.

The fix records Date.now() after responderGrant and before responderRelease, then waits out whatever is left of the 130ms based on that measured time. With modern fake timers Date.now() is faked, so behavior there doesn't change.

2. Yarn crashes on registry timeouts (upgrade 4.11.0 → 4.19.0)

Nightly jobs failed while switching RN versions with Error: The onCancel handler was attached after the promise settled. In the got v11 client bundled in Yarn, a retry scheduled after a timeout could fire after the request promise had already settled. The re-registered cancel handler then throws, which kills the process.

Yarn 4.18.1+ guards the retry with a settled flag. I checked bundles 4.11.0 through 4.18.0: none has the guard, and 4.18.1 and 4.19.0 do. This PR upgrades to 4.19.0 (yarn set version). The lockfile change is metadata only: __metadata.version 8 → 10 and new hashes for Yarn's builtin resolve patch.

yarn set version also tried to add enableScripts: true and approvedGitRepositories: "**" to .yarnrc.yml to keep the 4.11 defaults. I left them out:

  • There are no git dependencies.
  • With scripts disabled, only esbuild and unrs-resolver skip their build scripts. Both ship prebuilt binaries through optional dependencies.

The example apps (examples/basic, examples/cookbook) still pin yarn@4.11.0. They have their own lockfiles and are left for a follow-up.

Test plan

  • Clean yarn install with Yarn 4.19.0, then yarn validate: 90 suites and 963 tests pass, plus typecheck, lint and format.
  • yarn build passes.
  • press.real-timers.test.tsx passed 25 times in a row locally. The flake is rare (about 1%) and wasn't reproduced locally before the fix, so this is a sanity check, not proof.
  • A Node script confirmed that setTimeout(130) sometimes measures under 130ms with Date.now() (2/200 locally).
  • Not yet validated: CI on Yarn 4.19.0, including the nightly RN-matrix jobs. Trigger the nightly workflow via workflow_dispatch after merge, or on this branch.

🤖 Generated with Claude Code

mdjastrzebski and others added 2 commits December 3, 2026 14:45
Pressability measures press duration with Date.now() and defers onPressOut
when it sees less than 130ms. Node timers can fire ~1ms early relative to
Date.now(), so waiting setTimeout(130) occasionally left pressOut deferred
and press() resolved before it fired. Wait out the remaining min press
duration based on measured time instead of the requested duration.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Yarn 4.11.0 bundles a got v11 client that can crash with "The `onCancel`
handler was attached after the promise settled" when a registry request
times out and its retry fires after the request already settled. Yarn
4.18.1+ guards that retry. This crashed nightly CI jobs while switching
React Native versions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Dec 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.60%. Comparing base (07df7ea) to head (df7da37).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1972   +/-   ##
=======================================
  Coverage   98.60%   98.60%           
=======================================
  Files          88       88           
  Lines        1786     1789    +3     
  Branches      485      471   -14     
=======================================
+ Hits         1761     1764    +3     
  Misses         24       24           
  Partials        1        1           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

The root yarnPath applies to website, examples and experiments-app, which
have their own lockfiles. CI restores cached node_modules and skips
install, so Yarn 4.19.0 rejected the stale v8 website lockfile.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mdjastrzebski
mdjastrzebski merged commit 60cd48a into main Dec 3, 2026
42 checks passed
@mdjastrzebski
mdjastrzebski deleted the fix/ci-flakes branch December 3, 2026 16:12
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