Skip to main content

Function: resolveArtifact()

resolveArtifact(store, slug): Promise<Artifact | null>

Defined in: resolveArtifact.ts:31

Resolves whatever is published at a catch-all route: one pointer read, then one artifact read. The page component and generateMetadata both want the same answer, so wrap the call in React's cache rather than reading the store twice per request.

Parameters

store

ArtifactStore

The store the route was published through. Only pointer and read are called, so a read-only implementation serves the whole render path.

slug

readonly string[] | undefined

The catch-all param for the request, passed through routeFromSlug. undefined and the empty array are the root route.

Returns

Promise<Artifact | null>

The artifact serving that route, or null — for a route with no pointer, and for a pointer naming a hash the store no longer holds. Absence is a value rather than a failure: it is what the caller turns into notFound(), and it is why unpublishing produces a server 404 instead of an empty page.

Throws

Whatever the store raises. Both calls answer absence with null, so anything thrown from here is storage failing rather than a route that is not published.

Example

export default async function Page({ params }: { params: Promise<{ slug?: string[] }> }) {
const artifact = await resolveArtifact(store, (await params).slug);
if (!artifact) notFound();
return <Renderer artifact={artifact} registry={blockRegistry} resolveHole={resolveHole} />;
}