Skip to content

fix(client): respect abort signals in ordinary localLink calls - #8026

Merged
KATT merged 1 commit into
trpc:mainfrom
peterolkhov:codex/fix-local-link-abort
Nov 10, 2026
Merged

KATT merged 1 commit into
trpc:mainfrom
peterolkhov:codex/fix-local-link-abort

Conversation

@peterolkhov

@peterolkhov peterolkhov commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Why

  • Aborting an ordinary local query or mutation leaves the call pending, then returns success when its resolver finishes.

What

  • Race query and mutation result acquisition against the existing abort promise, including context creation.
  • Preserve the existing error handling and iterator cancellation paths.

Links

  • None.

Alternatives considered

  • None.

Testing

  • Regression check: localLink.test.ts covers query and mutation cancellation during pending resolvers, pending context creation, and before a call starts. All six fail without the fix.

  • Full workspace checks remain blocked locally by missing dependencies; package-wide type checks have not passed.

AI model

  • GPT-6.1 Sol, high reasoning, via Codex: diagnosis, implementation and regression tests.

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

Summary by CodeRabbit

  • Bug Fixes
    • Queries and mutations now stop waiting for procedure execution when cancelled, including when cancellation occurs during context creation.
    • Requests made with an already-aborted signal now reject with an abort error.

@peterolkhov
peterolkhov requested a review from a team as a code owner November 10, 2026 00:07
@vercel

vercel Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
examples-todomvc Ready Ready Preview Nov 10, 2026 12:11am UTC
next-prisma-starter Ready Ready Preview Nov 10, 2026 12:11am UTC
trpc-next-app-dir Ready Ready Preview Nov 10, 2026 12:11am UTC
www Ready Ready Preview Nov 10, 2026 12:11am UTC

Request Review

@vercel

vercel Bot commented Nov 10, 2026

Copy link
Copy Markdown

@peterolkhov is attempting to deploy a commit to the trpc Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Local query and mutation execution now races procedure execution against the operation’s abort signal. Added tests check cancellation during procedure execution or context creation, and when a call starts with an already-aborted signal.

Changes: Local link cancellation

Layer / File(s) Summary
Race local operations against cancellation
packages/client/src/links/localLink.ts, packages/client/src/links/localLink.test.ts
Query and mutation execution races procedure execution against the abort signal. Tests cover cancellation during procedure execution and context creation, plus calls with an already-aborted signal.

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

Change: Bug fix

Suggested reviewers: katt

Merge Risk: Minimal · up to 74831

The change reports cancellation to local callers promptly, with no established issue that should block merging after normal checks.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title clearly summarizes the main change: ordinary localLink calls now respect abort signals.
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
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.
Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: trpc/trpc
  • Branch: main
  • File: .coderabbit.yaml
  • Commit: 90c866e
  • Layers: Repository YAML
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1068bf3c-f1b5-469f-a5d2-fdc1bac717ec
Commits

Reviewing files that changed from the base of the PR and between 90c866e and 7483144.

Files selected for processing: 2

  • packages/client/src/links/localLink.test.ts
  • packages/client/src/links/localLink.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

@pkg-pr-new

pkg-pr-new Bot commented Nov 10, 2026

Copy link
Copy Markdown

Open in StackBlitz

@trpc/client

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

@trpc/next

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

@trpc/openapi

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

@trpc/react-query

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

@trpc/server

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

@trpc/tanstack-react-query

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

@trpc/upgrade

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

commit: 7483144

@agammann agammann left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new Promise.race changes which result reaches the observer, but runProcedure(op.input) starts before the race. With an already-aborted signal, it still calls createContext() and, after that resolves, callProcedure() even though the caller has received AbortError. A resolver with side effects can therefore run after cancellation. Could the signal be checked before starting runProcedure and again after awaiting context? The new already-aborted test checks rejection only; asserting that the context and resolver were not invoked would cover this. I reviewed the current diff; I did not run tests locally. AI-assisted review.

@KATT
KATT added this pull request to the merge queue Nov 10, 2026
Merged via the queue into trpc:main with commit 424e878 Nov 10, 2026
52 of 56 checks passed
meefs pushed a commit to meefs/trpc that referenced this pull request Nov 10, 2026
…8027)

## Why

- Follow-up to trpc#8026, which stops the client waiting once a `localLink`
call is aborted. The work behind it kept going:
- A call aborted before it started still created context and ran the
procedure.
- A call aborted while `createContext` was pending still ran the
procedure once context resolved. A cancelled mutation would still write.
- `createContext` got no signal, unlike the adapters' `createContext`,
which gets `info.signal`.

## What

- `createContext` receives `{ info: { signal } }`, mirroring the
adapters. Procedures already get the same signal as `opts.signal`.
Existing `() => …` functions still type-check.
- Skip context creation and the procedure if the call was already
aborted, and skip the procedure if it was aborted during context
creation.
- Share the existing `throwIfAborted` fallback from `httpUtils`, so
runtimes without `AbortSignal.prototype.throwIfAborted` keep working.

```ts
localLink({
  router,
  createContext: async (opts) => ({
    session: await getSession({ signal: opts.info.signal }),
  }),
});
```

## Links

- [Local Link ›
createContext](https://www-git-ccr-71fc9bd5-r732ha-trpc.vercel.app/docs/client/links/localLink#createcontext):
documents `info.signal`.

## Alternatives considered

- A flat `{ signal }`: simpler, but differs from the adapters'
`info.signal`.

## Testing

- Regression check: in `localLink.test.ts`, `passes the signal to
createContext`, `does not run the procedure when aborted during context
creation` and `does not create context or run the procedure when already
aborted` fail without this change, for both query and mutation.

## AI model

- Claude Opus 5.5

🤖 Generated with [Claude Code](https://claude.com/claude-code)

https://claude.ai/code/session_019Un67dkX3ZhkgFt8euJr5b

---------

Co-authored-by: Claude <[email protected]>
@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 Nov 11, 2026

This branch was successfully deployed

4 active deployments
Preview – next-prisma-starter — 7483144b Deployed Nov 10, 2026 by vercel[bot]
Preview – examples-todomvc — 7483144b Deployed Nov 10, 2026 by vercel[bot]
Preview – trpc-next-app-dir — 7483144b Deployed Nov 10, 2026 by vercel[bot]
Preview – www — 7483144b Deployed Nov 10, 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.

3 participants