Skip to content
Sarj Code Standards

prefer-native-fetch-in-server-actions

Server action modules should call native fetch instead of importing ky.

Why

ky wraps request bodies and responses for browser runtimes; in Next.js server actions it has failed on binary uploads with ArrayBuffer.slice errors, and its errors copy the signed request URL into messages and metadata.

Fix

Use the platform fetch with an explicit signal: AbortSignal.timeout(...) and check response.ok in the server action.

Examples

Before — flagged A server action imports ky
src/app/actions.ts
"use server";
import ky from "ky";
export async function upload(url: string, body: Blob): Promise<void> {
await ky.put(url, { body });
}
After — preferred A server action uploads with native fetch
src/app/actions.ts
"use server";
export async function upload(url: string, body: Blob): Promise<void> {
const response = await fetch(url, {
method: "PUT",
body,
signal: AbortSignal.timeout(30_000),
});
if (!response.ok) throw new Error(`upload failed: ${response.status}`);
}