Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve listing page redirect performance #222

Merged
merged 2 commits into from
Oct 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading