Next.js Discord

Discord Forum

Error with "use cache"

Unanswered
Sloth bear posted this in #help-forum
Open in Discord
Avatar
Sloth bearOP
I have a file with a getMember query call marked as import 'server-only' and when I invoke it on page.tsx I am getting
Route "/[lang]/dashboard/members/[...form]": A component accessed data, headers, params, searchParams, or a short-lived cache without a Suspense boundary nor a "use cache" above it

, even tho I do use Suspense, and I followed the the changes [here](https://nextjs.org/docs/messages/next-prerender-missing-suspense) and I moved Clerk's currentUser to the component level instead of in the getMember db query call.

// page.tsx
type PageParams = Promise<Record<'form', ['add' | 'new', string]>>;

export default async function Page(props: { params: PageParams }) {
    return (
        <Suspense fallback={<PageFormSkeleton />}>
            <PageForm params={props.params} />
        </Suspense>
    );
}

const PageForm = async (props: { params: PageParams }) => {
    const user = await currentUser();
    if (!user) {
        throw new Error('Unauthorized access');
    }

    const params = await props.params;
    const memberId = params.form[1];
    const member = await getMember(Number(memberId));

    return <MemberForm member={member ?? undefined} />;
};

// dbquery
import 'server-only';

export const getMember = async (id: number): Promise<Member | null> => {
    'use cache';
    cacheTag('member', id.toString());

    return prisma.member.findUnique({
        where: {
            id
        }
    });
};

4 Replies

Avatar
Sloth bearOP
bump
Avatar
is all of this code in just 1 file?
Avatar
Sloth bearOP
No the dbqueires file is a seperate one
Avatar
I don't have any idea about this, sorry