-
Notifications
You must be signed in to change notification settings - Fork 5
Open
Description
Hi!
If you export server actions with memoize function, any call to any other function is going to be promisifed, too.
For example, let's say we have this file:
"use server";
import { desc, eq } from "drizzle-orm";
import { db } from "../db";
import { Posts } from "../db/schema";
import { memoize } from "nextjs-better-unstable-cache";
export const getPostMetadataById = memoize(
async (id: number) => {
return db.query.Posts.findFirst({
where: eq(Posts.id, id),
columns: { title: true, description: true },
});
},
{
revalidateTags: (id: number) => ["posts", "metadata", `post-${id}`],
},
);In this case, no errors will be thrown but revalidateTags will be an async function and since we're calling it without await the only tag is going to be all.
I think it makes sense to check if functions are async or not in
nextjs-better-unstable-cache/src/index.ts
Line 75 in e4529ad
| revalidateTagsFn(...args) : revalidateTagsFn |
and
nextjs-better-unstable-cache/src/index.ts
Line 70 in e4529ad
| additionalCacheKeyFn(...args) : additionalCacheKeyFn |
I can do the fix myself but I just wanted to make sure that I'm not the only one with this issue.
Versions
next: 14.2.3nextjs-better-unstable-cache: 1.1.0
alfonsusac
Metadata
Metadata
Assignees
Labels
No labels