Skip to content

fix(upgrade): clear the query cache on every fixture render - #7448

Merged
Nick-Lucas merged 2 commits into
trpc:mainfrom
noahisdai:fix/upgrade-optimistic-update-hermetic
Jul 26, 2026
Merged

Nick-Lucas merged 2 commits into
trpc:mainfrom
noahisdai:fix/upgrade-optimistic-update-hermetic

Conversation

@noahisdai

@noahisdai noahisdai commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

Fixes a CI-only failure of transforms.test.ts > hooks optimistic-update.tsx: Expected "Posts: 1initial", Received "Posts: 2initialFoo" at the initial-render assertion β€” reproducible on unrelated PRs (the docs-only #7445, and #7447), always with retry x2 all failing the same way.

Two leaks between spec runs (the spec executes twice per test β€” input component and transformed snapshot β€” and again on CI retries), both via module-scoped state:

  1. In-flight mutation re-populates the server after reset. The fixture's update is optimistic, so a spec run finishes (or fails) with the create mutation still in flight. resetFixtureState() truncates posts, then the late mutation settles and pushes 'Foo' back β€” the next run's (or retry's) initial fetch returns 2initialFoo for its whole waitFor window. Under CI load the settle reliably lands in that gap; on a fast local machine (where retry is 0 anyway) it practically never does, which is why this only ever failed in CI. The spec's disposer is now async (makeAsyncResource + await using) and waits for queryClient.isMutating() === 0 before resetting.

  2. The shared QueryClient cache outlives a run. renderApp now clears it before mounting, so a retry can't render the previous attempt's cached data. This covers all nine fixtures using the harness; no spec renders more than once per run, so nothing relied on cache persistence.

βœ… Checklist

  • I have followed the steps listed in the Contributing guide.
  • If necessary, I have added documentation related to the changes made.
  • I have added or updated the tests related to the changes made.

Summary by CodeRabbit

  • Tests
    • Improved test isolation by resetting the app’s data cache before each render, preventing prior render or retry state from leaking into later tests.
    • Enhanced optimistic-update test cleanup by waiting for all in-flight mutations to fully complete before resetting fixture state and unmounting.

@noahisdai
noahisdai requested a review from a team as a code owner July 26, 2026 10:30
@vercel

vercel Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated (UTC)
next-prisma-starter Ready Ready Preview Jul 26, 2026 10:43am
og-image Ready Ready Preview, Comment Jul 26, 2026 10:43am

Request Review

@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

πŸ“ Walkthrough

Walkthrough

Upgrade tests now clear the shared React Query cache before rendering and asynchronously wait for active mutations to settle before resetting and unmounting the optimistic-update fixture.

Changes

Upgrade test state isolation

Layer / File(s) Summary
Reset query cache before rendering
packages/upgrade/test/__helpers.tsx
renderApp clears the shared query client before rendering each app instance.
Settle optimistic mutations during cleanup
packages/upgrade/test/__fixtures__/hooks/optimistic-update.spec.tsx
Fixture teardown uses makeAsyncResource and waits for isMutating() to reach zero before resetting state and unmounting.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

  • trpc/trpc#6808: Updates the optimistic-update fixture cleanup lifecycle to avoid teardown during an active mutation.
πŸš₯ Pre-merge checks | βœ… 5
βœ… Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage βœ… Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check βœ… Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check βœ… Passed Check skipped because no linked issues were found for this pull request.
Title check βœ… Passed The title is concise and accurately summarizes the main change: clearing the query cache on each fixture render.
Description check βœ… Passed The description covers the required changes and checklist, but it omits the template's Closes # issue reference.
✨ Finishing Touches
πŸ§ͺ Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Jul 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

npm i https://pkg.pr.new/@trpc/client@7448

@trpc/next

npm i https://pkg.pr.new/@trpc/next@7448

@trpc/openapi

npm i https://pkg.pr.new/@trpc/openapi@7448

@trpc/react-query

npm i https://pkg.pr.new/@trpc/react-query@7448

@trpc/server

npm i https://pkg.pr.new/@trpc/server@7448

@trpc/tanstack-react-query

npm i https://pkg.pr.new/@trpc/tanstack-react-query@7448

@trpc/upgrade

npm i https://pkg.pr.new/@trpc/upgrade@7448

commit: 6ccc43d

@Nick-Lucas
Nick-Lucas merged commit cdbc280 into trpc:main Jul 26, 2026
45 checks passed
@Nick-Lucas

Copy link
Copy Markdown
Contributor

Thank you, good catch!

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Jul 27, 2026

This branch was successfully deployed

5 active deployments
Preview – www β€” 6ccc43dc Deployed Jul 26, 2026 by vercel[bot]
Preview – examples-todomvc β€” 6ccc43dc Deployed Jul 26, 2026 by vercel[bot]
Preview – og-image β€” 6ccc43dc Deployed Jul 26, 2026 by vercel[bot]
Preview – next-prisma-starter β€” 6ccc43dc Deployed Jul 26, 2026 by vercel[bot]
Preview – trpc-next-app-dir β€” 6ccc43dc Deployed Jul 26, 2026 by vercel[bot]
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants