Skip to content

Commit

Permalink
Fix auth ssr initial cache state (#10601)
Browse files Browse the repository at this point in the history
* Handle case where pageProps initial cache is undefined

* Use cache only fetch policy on ssr
  • Loading branch information
hdiniz authored Aug 19, 2024
1 parent 5071190 commit 90275e8
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion components/dashboard/sections/accounts/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ const Accounts = ({ accountSlug, subpath }: DashboardSectionProps) => {
const { data, error, loading, refetch } = useQuery(accountsQuery, {
variables: { accountSlug, ...queryFilter.variables },
context: API_V2_CONTEXT,
fetchPolicy: 'cache-and-network',
fetchPolicy: typeof window !== 'undefined' ? 'cache-and-network' : 'cache-first',
});
useEffect(() => {
if (subpath[0] !== ((showCollectiveOverview as Collective)?.id || showCollectiveOverview)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,13 @@ const HostApplications = ({ accountSlug: hostSlug }: DashboardSectionProps) => {

const { data, error, loading } = useQuery(hostApplicationsQuery, {
variables: { hostSlug, ...queryFilter.variables },
fetchPolicy: 'cache-and-network',
context: API_V2_CONTEXT,
});

// Open application account id, checking hash for backwards compatibility
const accountId = Number(router.query.accountId || window?.location.hash.split('application-')[1]);
const accountId = Number(
router.query.accountId || (typeof window !== 'undefined' && window?.location.hash.split('application-')[1]),
);
const [applicationInDrawer, setApplicationInDrawer] = React.useState(null);
const drawerOpen = accountId && applicationInDrawer;

Expand Down
4 changes: 2 additions & 2 deletions components/dashboard/sections/contributions/Contributions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ const Contributions = ({ accountSlug, direction, onlyExpectedFunds, includeHoste
includeHostedAccounts: !!includeHostedAccounts,
},
context: API_V2_CONTEXT,
fetchPolicy: 'cache-and-network',
fetchPolicy: typeof window !== 'undefined' ? 'cache-and-network' : 'cache-first',
});

const selectedContributionId = router.query.orderId ? parseInt(router.query.orderId as string) : null;
Expand Down Expand Up @@ -689,7 +689,7 @@ const Contributions = ({ accountSlug, direction, onlyExpectedFunds, includeHoste
: { expectedFundsFilter: null }),
},
context: API_V2_CONTEXT,
fetchPolicy: 'cache-and-network',
fetchPolicy: typeof window !== 'undefined' ? 'cache-and-network' : 'cache-first',
});

const [editOrder, setEditOrder] = React.useState<{ order?: { id: string | number }; action: EditOrderActions }>({
Expand Down
2 changes: 1 addition & 1 deletion pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class OpenCollectiveFrontendApp extends App {

getApolloClient = memoizeOne((ssrCache, pageServerSidePropsCache) => {
return initClient({
initialState: mergeDeep(ssrCache, pageServerSidePropsCache),
initialState: mergeDeep(ssrCache || {}, pageServerSidePropsCache || {}),
twoFactorAuthContext: this.props.twoFactorAuthContext,
});
});
Expand Down

0 comments on commit 90275e8

Please sign in to comment.