convex-js
convex-js copied to clipboard
feat(nextjs): add abortsignal support for react 19.2 cachesignal
Summary
Adds signal parameter to NextjsOptions to support React 19.2's cacheSignal() API for automatic request cancellation.
Motivation
React 19.2 introduced cacheSignal() which returns an AbortSignal that automatically aborts when:
- Render completes successfully
- Render is aborted
- User navigates away
- Cache lifetime ends
This prevents wasted network requests and enables proper cleanup in Server Components.
Changes
Type Definitions:
- Added
signal?: AbortSignal | nulltoNextjsOptionsinsrc/nextjs/index.ts - Added
signal?: AbortSignaltoFetchOptionsinsrc/browser/http_client.ts
Runtime:
- Pass
signalfrom options toclient.setFetchOptions()insetupClient() - Signal flows through to all
fetch()calls automatically
Example Usage
import { cacheSignal } from 'react';
import { fetchQuery } from 'convex/nextjs';
import { api } from '@/convex/_generated/api';
export async function getProducts() {
'use cache';
return await fetchQuery(
api.catalog.getProducts,
{},
{ signal: cacheSignal() }
);
}
Testing
- TypeScript compilation passes
- Build succeeds with signal parameter
- Backwards compatible (signal is optional)
- Works with all function types (query/mutation/action)
- Tested in production Next.js 16 + React 19.2 application