Guides
Every fetch function in @skyscribe-sdk/core accepts an optional AbortSignal as its last argument. When the signal fires, any in-flight HTTP requests are cancelled immediately.
fetchPublication(author, publicationUrl, signal?)
fetchDocumentBySlug(author, publicationUrl, documentSlug, signal?)
fetchDocument(author, rkey, signal?)
On the server, passing the request's signal cancels the PDS fetch if the visitor navigates away before your loader responds. Without it, the server keeps fetching data nobody will see.
In the browser, a signal from an AbortController lets you cancel the fetch when a component unmounts or its parameters change.
If you use a framework adapter, you don't need to manage signals yourself:
usePublication, useDocumentBySlug, useDocument): abort on unmount, and re-fetch (aborting the old request) when their arguments changerequest.signal throughinjectPublication, injectDocumentBySlug, injectDocument): abort when the host component is destroyedScribeService): abort when you unsubscribe, including when an async pipe's component is destroyed:key) to fetch something elseuseAsyncData runs the fetch once during server rendering and reuses the result on the clientOnly read on if you're using @skyscribe-sdk/core directly.
Pass request.signal from the incoming request:
// React Router v7/v8
export async function loader({ request }: LoaderFunctionArgs) {
return fetchPublication('alice.bsky.social', 'https://alice.bsky.social', request.signal);
}
// Next.js App Router route handler
export async function GET(request: Request) {
const publication = await fetchPublication('alice.bsky.social', 'https://alice.bsky.social', request.signal);
return Response.json(publication);
}
Create an AbortController and abort when needed:
// Cancel on component unmount (vanilla JS)
const controller = new AbortController();
const publication = await fetchPublication('alice.bsky.social', 'https://alice.bsky.social', controller.signal);
// Later, when the component unmounts or the visitor navigates away:
controller.abort();
In React you can do this inside useEffect:
useEffect(() => {
const controller = new AbortController();
fetchPublication('alice.bsky.social', 'https://alice.bsky.social', controller.signal)
.then(setSite)
.catch((err) => {
if (err.name !== 'AbortError') throw err;
});
return () => controller.abort();
}, []);
Note
@skyscribe-sdk/react's usePublication and useDocument already handle this AbortController lifecycle, so you rarely need to write it yourself.
When a signal fires, the promise rejects with an AbortError. Check for it and ignore it: a cancelled request isn't a failure.
try {
const publication = await fetchPublication(author, publicationUrl, controller.signal);
} catch (err) {
if (err instanceof Error && err.name === 'AbortError') {
return; // normal: the request was cancelled
}
throw err; // a real error: re-throw
}