platforms icon indicating copy to clipboard operation
platforms copied to clipboard

minor: (invalid?) use of promises

Open thoaionline opened this issue 1 year ago • 0 comments

1. invalid promise type check

in this repo, under apps/magic/lib/actions.ts:

import { revalidateTag } from "next/cache";

then subsequently:

await revalidateTag(
  `${subdomain}.${process.env.NEXT_PUBLIC_ROOT_DOMAIN}-metadata`,
);

however, the declared return type is

export declare function revalidateTag(tag: string): void;

which is not a promise, and thus shouldn't be await-ed.

i checked the implementation here and it's indeed not a promise.

2. promise executor functions should not be async.

there are a couple of

    new Promise<void>(async (resolve, reject) => ...

the async kindas defeat the purpose of a Promise constructor these days. should be a trivial fix.

those 2 issues are the main bugs that come up in sonarcloud from scanning a fresh clone.

i'm happy to make a PR for both but wanted first to check if the await was intentional.

thoaionline avatar Feb 23 '24 00:02 thoaionline