Skip to content

fix(webapp): stop feed page tests flaking on a cold jest cache - #6532

Merged
idoshamun merged 1 commit into
mainfrom
claude/youthful-saha-7e3dd2
Aug 26, 2026
Merged

fix(webapp): stop feed page tests flaking on a cold jest cache#6532
idoshamun merged 1 commit into
mainfrom
claude/youthful-saha-7e3dd2

Conversation

@idoshamun

@idoshamun idoshamun commented Aug 26, 2026

Copy link
Copy Markdown
Member

Problem

packages/webapp/__tests__/MyFeedPage.tsxshould request user feed fails intermittently with Unable to find an element by: [data-testid="postItem"]. Seen on main (CircleCI build 161384) and on unrelated PRs (#6531, build 161573).

Root cause

MainFeedLayout only reaches the feed pages through next/dynamic, so its module graph is compiled by babel-jest inside the first findBy* wait. An event-loop heartbeat during the test shows it plainly:

[60ms]  render returned
[494ms] event loop blocked for 493ms   <- dynamic import() compiling MainFeedLayout
[525ms] feed request
[681ms] found 8 postItems

With a warm transform cache that is ~470ms of a 1000ms budget. With a cold one the same block runs 3s+, and the test fails deterministically:

NODE_ENV=test pnpm exec jest __tests__/MyFeedPage.tsx --cacheDirectory=/tmp/cold-cache
# ✕ should request user feed (3037 ms)

CI reproduces this by accident: test_webapp runs --runInBand with circleci tests run --split-by=timings and restores only the pnpm deps cache, never a jest transform cache. File order changes between runs, so whichever feed page test lands first in the container pays the compile and fails; when another feed test runs first, the cache is warm and it passes.

Fix

Preload the module in beforeAll so the compile no longer sits inside the wait window, raise the file timeout to cover that compile, and give the feed waits an explicit budget.

Scope

A cold-cache sweep over 14 candidate test files found exactly four affected, all of them pages whose getLayout is getMainFeedLayout (the only path that reaches MainFeedLayout through next/dynamic):

File Cold, before Cold, after
MyFeedPage ✕ 3037 ms ✓ 678 ms
PopularPage ✕ 3662 ms ✓ 494 ms
MostUpvotedPage ✕ 4145 ms ✓ 550 ms
MostDiscussedPage ✕ 2992 ms ✓ 566 ms

TagPage, KeywordPage, SquadFeedPage, SearchPage, SearchResultsPage, BookmarksPage, HistoryPage and the Profile* feed tests all pass cold — they reach the feed through static imports, so their compile happens at module load. That also clears waitForNock's hardcoded 1000ms in practice, so no shared helper or global jest config change is included here.

Two incidental cleanups in the files being touched: MostUpvotedPage's existing { timeout: 3000 } was below the observed 4145ms, and MostDiscussedPage had a nested waitFor(async () => findAllByTestId(...)) where a 1s inner wait sat inside a 1s outer one.

Verification

  • Cold cache (fresh --cacheDirectory), all four files: pass
  • 22 loop iterations over the four files: 22/22
  • 24 runs of MyFeedPage at 8x concurrency: 24/24
  • Full webapp suite (--ci --runInBand): 74 suites, 587 tests, all pass
  • eslint and node ./scripts/typecheck-strict-changed.js: clean

Preview domain

https://claude-youthful-saha-7e3dd2.preview.app.daily.dev

MainFeedLayout only reaches the feed pages through next/dynamic, so its
module graph is compiled inside the first findBy*/waitFor call. That
compile takes ~470ms with a warm jest transform cache but over 3 seconds
with a cold one, which blows RTL's 1000ms default timeout and fails with
"Unable to find an element by: [data-testid=postItem]".

CI restores no jest transform cache and reorders test files between runs
(--runInBand with --split-by=timings), so whichever feed page test lands
first pays the compile. That is why the failure showed up on main and on
unrelated PRs.

Preload the module in beforeAll so the compile no longer sits inside the
wait window, raise the file timeout to cover that compile, and give the
feed waits an explicit budget. A cold-cache sweep over the other feed
page tests found only these four affected, all of them pages whose
getLayout is getMainFeedLayout.

Cold-cache duration of the affected tests drops from 2992-4145ms
(failing) to 494-678ms (passing).
@vercel

vercel Bot commented Aug 26, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
daily-webapp Ready Ready Preview Aug 26, 2026 6:25am
1 Skipped Deployment
Project Deployment Actions Updated (UTC)
storybook Ignored Ignored Aug 26, 2026 6:25am

Request Review

@idoshamun
idoshamun merged commit c7652c8 into main Aug 26, 2026
11 of 12 checks passed
@idoshamun
idoshamun deleted the claude/youthful-saha-7e3dd2 branch August 26, 2026 06:26
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