From 0855f807fcc35dd9db55cb1218cc34cbe0c1a2fe Mon Sep 17 00:00:00 2001 From: Ray Date: Sun, 12 Oct 2025 08:50:58 -0400 Subject: [PATCH] feat(nextjs): add abortsignal support for react 19.2 cachesignal --- src/browser/http_client.ts | 5 ++++- src/nextjs/index.ts | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/browser/http_client.ts b/src/browser/http_client.ts index 937c4bc..b247e20 100644 --- a/src/browser/http_client.ts +++ b/src/browser/http_client.ts @@ -576,4 +576,7 @@ function forwardErrorData(errorData: JSONValue, error: ConvexError) { /** * @internal */ -type FetchOptions = { cache: "force-cache" | "no-store" }; +type FetchOptions = { + cache: "force-cache" | "no-store"; + signal?: AbortSignal; +}; diff --git a/src/nextjs/index.ts b/src/nextjs/index.ts index 6d3b7d1..013a58e 100644 --- a/src/nextjs/index.ts +++ b/src/nextjs/index.ts @@ -84,6 +84,12 @@ export type NextjsOptions = { * The default value is `false` */ skipConvexDeploymentUrlCheck?: boolean; + /** + * AbortSignal to cancel the request. + * + * Use with React 19.2's cacheSignal() to abort fetches when cache lifetime ends. + */ + signal?: AbortSignal | null; }; /** @@ -199,7 +205,10 @@ function setupClient(options: NextjsOptions) { if (options.adminToken !== undefined) { client.setAdminAuth(options.adminToken); } - client.setFetchOptions({ cache: "no-store" }); + client.setFetchOptions({ + cache: "no-store", + signal: options.signal ?? undefined, + }); return client; }