Skip to content

feat(client): pass the abort signal to localLink createContext - #8027

Merged
KATT merged 3 commits into
mainfrom
ccr-71fc9bd5-r732ha
Nov 10, 2026
Merged

KATT merged 3 commits into
mainfrom
ccr-71fc9bd5-r732ha

Conversation

@KATT

@KATT KATT commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Why

  • Follow-up to fix(client): respect abort signals in ordinary localLink calls #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.
localLink({
  router,
  createContext: async (opts) => ({
    session: await getSession({ signal: opts.info.signal }),
  }),
});

Links

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.ai/code/session_019Un67dkX3ZhkgFt8euJr5b

@KATT
KATT requested review from a team as code owners November 10, 2026 12:55
@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-next-minimal-starter Ready Ready Preview Nov 10, 2026 1:51pm UTC
examples-todomvc Ready Ready Preview Nov 10, 2026 1:51pm UTC
next-prisma-starter Ready Ready Preview Nov 10, 2026 1:51pm UTC
next-prisma-websockets-starter Ready Ready Preview Nov 10, 2026 1:51pm UTC
tanstack-start-sse-chat Ready Ready Preview Nov 10, 2026 1:51pm UTC
trpc-next-app-dir Ready Ready Preview Nov 10, 2026 1:51pm UTC
www Ready Ready Preview Nov 10, 2026 1:51pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

LocalLink now passes an abort signal to createContext and checks cancellation before and after context creation. A shared abort helper replaces the local helper in HTTP utilities. Tests and documentation cover signal propagation and cancellation behavior.

Changes: LocalLink cancellation

Layer / File(s) Summary
Shared abort handling
packages/client/src/internals/signals.ts, packages/client/src/links/internals/httpUtils.ts
The shared signals module adds a fallback AbortError and throwIfAborted. HTTP utilities use the shared helper instead of a local implementation.
LocalLink signal contract and cancellation flow
packages/client/src/links/localLink.ts, packages/client/src/links/localLink.test.ts, www/v11/docs/client/links/localLink.md
createContext accepts an options object with an AbortSignal. LocalLink checks cancellation before and after context creation. Tests cover signal propagation, cancellation during context creation, already-aborted requests, and environments without the native throwIfAborted method. Documentation describes the signal and shows it passed to session lookup.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant LocalLink
  participant createContext
  participant Procedure
  Client->>LocalLink: Start query or mutation with signal
  LocalLink->>createContext: Pass signal
  createContext-->>LocalLink: Return context
  LocalLink->>Procedure: Run if signal is not aborted
  Client->>LocalLink: Abort request signal
  LocalLink-->>Procedure: Skip execution if cancellation occurs during context creation
Loading

Possibly related issues

  • trpc/trpc#4448 — The issue concerns consuming query abort signals. This change passes the signal to LocalLink context creation and checks cancellation there.

Possibly related PRs

  • trpc/trpc#8026 — This PR adds cancellation rejection behavior in LocalLink; this change passes the signal to context creation and prevents later procedure execution.
  • trpc/trpc#7606 — This PR changes raceAbortSignals, which LocalLink uses to create the signal passed to procedures and context creation.

Suggested reviewers: nick-lucas

Merge Risk: Minimal · up to b149a

No actionable merge-blocking risk was identified.

Pre-merge checks: Passed 5

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.
Title check Passed The title clearly describes the main change: passing the abort signal to localLink createContext.
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 4 files. (1 skipped: 1 unsupported.)

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Generate unit tests (beta)

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

Warning

CI annotation context is incomplete: annotation collection unavailable or limited

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

Commits

Reviewing files that changed from the base of the PR and between bccef36 and b149a59.

Files selected for processing: 3

  • packages/client/src/links/localLink.test.ts
  • packages/client/src/links/localLink.ts
  • www/v11/docs/client/links/localLink.md

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

- `createContext` now receives `{ signal }`, the same signal procedures
  get, so slow context work can stop when the call is cancelled.
- Don't create context or run the procedure for a call that was aborted
  before it started, and don't run the procedure if the call was aborted
  while context was being created. Before, a cancelled mutation still ran.
- Assert that the signal procedures receive aborts with the call.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019Un67dkX3ZhkgFt8euJr5b
@KATT
KATT force-pushed the ccr-71fc9bd5-r732ha branch from 9882643 to 64aa25f Compare November 10, 2026 12:56
@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@8027

@trpc/next

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

@trpc/openapi

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

@trpc/react-query

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

@trpc/server

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

@trpc/tanstack-react-query

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

@trpc/upgrade

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

commit: b149a59

Some runtimes the HTTP links already support, such as older Safari and
some React Native AbortController polyfills, have no
`AbortSignal.prototype.throwIfAborted`. Calling it directly made every
localLink call throw a TypeError there, cancelled or not.

Move the existing fallback from httpUtils into internals/signals and use
it in both places.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019Un67dkX3ZhkgFt8euJr5b
Mirror the adapters, whose createContext gets the request's signal as
`opts.info.signal`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_019Un67dkX3ZhkgFt8euJr5b

@trpc-bot trpc-bot left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed: localLink now skips context creation and the procedure for a cancelled call, passes info.signal to createContext like the adapters do, and uses the shared throwIfAborted fallback. CI is green and CodeRabbit has no findings.


Generated by Claude Code

@KATT
KATT added this pull request to the merge queue Nov 10, 2026
Merged via the queue into main with commit f685c49 Nov 10, 2026
57 checks passed
@KATT
KATT deleted the ccr-71fc9bd5-r732ha branch November 10, 2026 14:04
@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

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