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

fix: plus gifter query error makes page slow #4179

Merged
merged 3 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ReactElement } from 'react';
import React from 'react';
import React, { useMemo } from 'react';

import classNames from 'classnames';
import { usePaymentContext } from '../../contexts/PaymentContext';
Expand All @@ -24,7 +24,7 @@ export const PlusCheckoutContainer = ({
const { isPlusAvailable } = usePaymentContext();
const { isPlus } = usePlusSubscription();

const getContainerElement = () => {
const ContainerElement = useMemo(() => {
if (!isPlusAvailable) {
return PlusUnavailable;
}
Expand All @@ -38,9 +38,7 @@ export const PlusCheckoutContainer = ({
}

return null;
};

const ContainerElement = getContainerElement();
}, [isPlusAvailable, giftToUser, isPlus]);
const shouldRenderCheckout = !ContainerElement;

return (
Expand Down
16 changes: 12 additions & 4 deletions packages/shared/src/graphql/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from './fragments';
import type { PublicProfile, UserShortProfile } from '../lib/user';
import type { Connection } from './common';
import { gqlClient } from './common';
import { ApiError, gqlClient } from './common';
import type { SourceMember } from './sources';
import type { SendType } from '../hooks';
import type { DayOfWeek } from '../lib/date';
Expand Down Expand Up @@ -720,8 +720,16 @@ export const GET_PLUS_GIFTER_USER = gql`
}
}
`;
export const getPlusGifterUser = async (): Promise<UserShortProfile> => {
const res = await gqlClient.request(GET_PLUS_GIFTER_USER);
export const getPlusGifterUser = async (): Promise<UserShortProfile | null> => {
try {
const res = await gqlClient.request(GET_PLUS_GIFTER_USER);
return res.plusGifterUser;
} catch (error) {
const errorCode = error.response?.errors?.[0]?.extensions?.code;
if (errorCode === ApiError.Forbidden) {
return null;
}

return res.plusGifterUser;
throw error;
}
};