Skip to content

Commit 738a6a9

Browse files
committed
fix: update vanity query url to use unstable_cache
1 parent 30b3a9c commit 738a6a9

1 file changed

Lines changed: 18 additions & 11 deletions

File tree

core/lib/seo/canonical.ts

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { unstable_cache } from 'next/cache';
12
import { cache } from 'react';
23

34
import { client } from '~/client';
@@ -45,20 +46,26 @@ const VanityUrlQuery = graphql(`
4546
}
4647
`);
4748

48-
const getVanityUrl = cache(async () => {
49-
const { data } = await client.fetch({
50-
document: VanityUrlQuery,
51-
fetchOptions: { next: { revalidate } },
52-
});
49+
const getCachedVanityUrl = unstable_cache(
50+
async () => {
51+
const { data } = await client.fetch({
52+
document: VanityUrlQuery,
53+
fetchOptions: { next: { revalidate } },
54+
});
5355

54-
const vanityUrl = data.site.settings?.url.vanityUrl;
56+
const vanityUrl = data.site.settings?.url.vanityUrl;
5557

56-
if (!vanityUrl) {
57-
throw new Error('Vanity URL not found in site settings');
58-
}
58+
if (!vanityUrl) {
59+
throw new Error('Vanity URL not found in site settings');
60+
}
61+
62+
return vanityUrl;
63+
},
64+
['get-vanity-url'],
65+
{ revalidate },
66+
);
5967

60-
return vanityUrl;
61-
});
68+
const getVanityUrl = cache(getCachedVanityUrl);
6269

6370
export async function getMetadataAlternates(options: CanonicalUrlOptions) {
6471
const { path, locale, includeAlternates = true } = options;

0 commit comments

Comments
 (0)