Skip to content

Commit

Permalink
Merge pull request #222 from unstoppabledomains/ryan/improve-redirect…
Browse files Browse the repository at this point in the history
…-performance

Improve listing page redirect performance
  • Loading branch information
sudoryan authored Oct 30, 2024
2 parents 4b1d998 + dc36ca2 commit e456ff1
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions server/pages/[domain]/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -131,22 +131,32 @@ 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
window.location.hostname.toLowerCase() !== udMeHostname.toLowerCase()
) {
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();
Expand Down

0 comments on commit e456ff1

Please sign in to comment.