diff --git a/server/pages/[domain]/index.page.tsx b/server/pages/[domain]/index.page.tsx index dd736e4c..9d513d29 100644 --- a/server/pages/[domain]/index.page.tsx +++ b/server/pages/[domain]/index.page.tsx @@ -41,7 +41,7 @@ import {useRouter} from 'next/router'; import {useSnackbar} from 'notistack'; import numeral from 'numeral'; import QueryString from 'qs'; -import React, {useEffect, useState} from 'react'; +import React, {useEffect, useLayoutEffect, useState} from 'react'; import useIsMounted from 'react-is-mounted-hook'; import {useStyles} from 'styles/pages/domain.styles'; import {titleCase} from 'title-case'; @@ -131,14 +131,15 @@ export type DomainProfilePageProps = { identity?: PersonaIdentity; }; +const udMeHostname = new URL(config.UD_ME_BASE_URL).hostname; + const DomainProfile = ({ domain, profileData: initialProfileData, identity, }: DomainProfilePageProps) => { // Redirect to listing page if domain is listed for sale and the host is not ud.me - useEffect(() => { - const udMeHostname = new URL(config.UD_ME_BASE_URL).hostname; + useLayoutEffect(() => { if ( initialProfileData?.isListedForSale && typeof window !== 'undefined' && // Make sure we're on client side @@ -146,7 +147,16 @@ const DomainProfile = ({ ) { window.location.replace(`${config.UNSTOPPABLE_WEBSITE_URL}/d/${domain}`); } - }, [initialProfileData]); + }, [initialProfileData, domain]); + + // If redirecting to listing page, we can prevent rendering the rest + if ( + initialProfileData?.isListedForSale && + typeof window !== 'undefined' && + window.location.hostname.toLowerCase() !== udMeHostname.toLowerCase() + ) { + return null; + } // hooks const [t] = useTranslationContext();