From c81612e39b1fb38b9d09049d93bde51ec930448d Mon Sep 17 00:00:00 2001 From: Jelte Lagendijk Date: Wed, 11 Sep 2024 23:53:55 +0200 Subject: [PATCH] Bugfix for dynamic urls not properly replaces on Search (#2124) * Bugfix for search items * Fixing server side rendering issues --- src/components/layout/header/Search.tsx | 4 +++- src/hooks/useExternalUrl.ts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/components/layout/header/Search.tsx b/src/components/layout/header/Search.tsx index e0de950b2b8..a49085a6a63 100644 --- a/src/components/layout/header/Search.tsx +++ b/src/components/layout/header/Search.tsx @@ -13,6 +13,7 @@ import { useTranslation } from 'next-i18next'; import { useRouter } from 'next/router'; import { ReactNode, forwardRef, useMemo, useRef, useState } from 'react'; import { useConfigContext } from '~/config/provider'; +import { useGetExternalUrl } from '~/hooks/useExternalUrl'; import { api } from '~/utils/api'; import { MovieModal } from './Search/MovieModal'; @@ -141,6 +142,7 @@ const getItemComponent = (icon: SearchAutoCompleteItem['icon']) => { const useConfigApps = (search: string) => { const { config } = useConfigContext(); + const getHref = useGetExternalUrl(); return useMemo(() => { if (search.trim().length === 0) return []; const apps = config?.apps.filter((app) => @@ -153,7 +155,7 @@ const useConfigApps = (search: string) => { value: app.name, sort: 'app', metaData: { - url: app.behaviour.externalUrl, + url: getHref(app), }, })) ?? [] ); diff --git a/src/hooks/useExternalUrl.ts b/src/hooks/useExternalUrl.ts index bbd774220e1..c992a11f224 100644 --- a/src/hooks/useExternalUrl.ts +++ b/src/hooks/useExternalUrl.ts @@ -3,6 +3,10 @@ import * as tldts from 'tldts'; import { AppType } from '~/types/app'; export const useGetExternalUrl = () => { + if (typeof window === 'undefined') { + return (appType: AppType) => appType.behaviour.externalUrl || appType.url; + } + const parsedUrl = useMemo(() => { try { return tldts.parse(window.location.toString());