don't use cache for SSR

This commit is contained in:
keyan 2023-08-05 14:46:29 -05:00
parent b9fdbde520
commit e4aaaac20f
3 changed files with 8 additions and 10 deletions

View File

@ -38,14 +38,14 @@ export default async function getSSRApolloClient ({ req, res, me = null }) {
assumeImmutableResults: true, assumeImmutableResults: true,
defaultOptions: { defaultOptions: {
watchQuery: { watchQuery: {
fetchPolicy: 'cache-only', fetchPolicy: 'no-cache',
nextFetchPolicy: 'cache-only', nextFetchPolicy: 'no-cache',
canonizeResults: true, canonizeResults: true,
ssr: true ssr: true
}, },
query: { query: {
fetchPolicy: 'cache-first', fetchPolicy: 'no-cache',
nextFetchPolicy: 'cache-only', nextFetchPolicy: 'no-cache',
canonizeResults: true, canonizeResults: true,
ssr: true ssr: true
} }

View File

@ -150,13 +150,15 @@ function getClient (uri) {
initialFetchPolicy: defaultFetchPolicy, initialFetchPolicy: defaultFetchPolicy,
fetchPolicy: defaultFetchPolicy, fetchPolicy: defaultFetchPolicy,
nextFetchPolicy: defaultNextFetchPolicy, nextFetchPolicy: defaultNextFetchPolicy,
canonizeResults: true canonizeResults: true,
ssr: SSR
}, },
query: { query: {
initialFetchPolicy: defaultFetchPolicy, initialFetchPolicy: defaultFetchPolicy,
fetchPolicy: defaultFetchPolicy, fetchPolicy: defaultFetchPolicy,
nextFetchPolicy: defaultNextFetchPolicy, nextFetchPolicy: defaultNextFetchPolicy,
canonizeResults: true canonizeResults: true,
ssr: SSR
} }
} }
}) })

View File

@ -72,10 +72,6 @@ function MyApp ({ Component, pageProps: { ...props } }) {
ssr data ssr data
*/ */
const { apollo, ssrData, me, price, ...otherProps } = props const { apollo, ssrData, me, price, ...otherProps } = props
// if we are on the server, useEffect won't run
if (SSR && client) {
writeQuery(client, apollo, ssrData)
}
useEffect(() => { useEffect(() => {
writeQuery(client, apollo, ssrData) writeQuery(client, apollo, ssrData)
}, [client, apollo, ssrData]) }, [client, apollo, ssrData])