From 02bed8db5edb3da94639afa2649b308423656bd9 Mon Sep 17 00:00:00 2001 From: Jorge Moya Date: Fri, 13 Sep 2024 15:22:36 -0500 Subject: [PATCH] fix(core): manually pass in channel id for get favicon query --- .changeset/tidy-coats-press.md | 5 +++++ core/app/favicon.ico/route.ts | 7 +++++-- core/client/index.ts | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 .changeset/tidy-coats-press.md diff --git a/.changeset/tidy-coats-press.md b/.changeset/tidy-coats-press.md new file mode 100644 index 000000000..9a41274e3 --- /dev/null +++ b/.changeset/tidy-coats-press.md @@ -0,0 +1,5 @@ +--- +"@bigcommerce/catalyst-core": patch +--- + +Pass in default channel to favicon query, since `getLocale` can't be used in routes. diff --git a/core/app/favicon.ico/route.ts b/core/app/favicon.ico/route.ts index 870166ebe..f79e7bf38 100644 --- a/core/app/favicon.ico/route.ts +++ b/core/app/favicon.ico/route.ts @@ -9,10 +9,12 @@ * */ +import { getChannelIdFromLocale } from '~/channels.config'; import { client } from '~/client'; import { graphql } from '~/client/graphql'; +import { defaultLocale } from '~/i18n/routing'; -const GET_FAVICON_QUERY = graphql(` +const GetFaviconQuery = graphql(` query GetFavicon { site { settings { @@ -24,7 +26,8 @@ const GET_FAVICON_QUERY = graphql(` export const GET = async () => { const { data } = await client.fetch({ - document: GET_FAVICON_QUERY, + document: GetFaviconQuery, + channelId: getChannelIdFromLocale(defaultLocale), }); const faviconUrl = data.site.settings?.faviconUrl; diff --git a/core/client/index.ts b/core/client/index.ts index ae0c0fcd5..a1b8d1bb7 100644 --- a/core/client/index.ts +++ b/core/client/index.ts @@ -32,7 +32,7 @@ export const client = createClient({ return getChannelIdFromLocale(locale) ?? defaultChannelId; } catch { // eslint-disable-next-line no-console - console.error('Error using `getLocale`, using default channel id instead.'); + console.error('Warning: issue using `getLocale`, using default channel id instead.'); return defaultChannelId; }