fix 'me' on refresh
This commit is contained in:
		
							parent
							
								
									b468c033ca
								
							
						
					
					
						commit
						69b5aed85d
					
				@ -37,11 +37,20 @@ export function getGetServerSideProps (query, variables = null, notFoundFunc, re
 | 
			
		||||
  return async function ({ req, query: params }) {
 | 
			
		||||
    const { nodata, ...realParams } = params
 | 
			
		||||
    const vars = { ...realParams, ...variables }
 | 
			
		||||
    const client = await getSSRApolloClient(req)
 | 
			
		||||
 | 
			
		||||
    const { data: { me } } = await client.query({
 | 
			
		||||
      query: ME_SSR
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    const price = await getPrice()
 | 
			
		||||
 | 
			
		||||
    // we want to use client-side cache
 | 
			
		||||
    if (nodata && query) {
 | 
			
		||||
      return {
 | 
			
		||||
        props: {
 | 
			
		||||
          me,
 | 
			
		||||
          price,
 | 
			
		||||
          apollo: {
 | 
			
		||||
            query: print(query),
 | 
			
		||||
            variables: vars
 | 
			
		||||
@ -56,7 +65,6 @@ export function getGetServerSideProps (query, variables = null, notFoundFunc, re
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const client = await getSSRApolloClient(req)
 | 
			
		||||
    let error = null; let data = null; let props = {}
 | 
			
		||||
    if (query) {
 | 
			
		||||
      ({ error, data } = await client.query({
 | 
			
		||||
@ -78,12 +86,6 @@ export function getGetServerSideProps (query, variables = null, notFoundFunc, re
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    const { data: { me } } = await client.query({
 | 
			
		||||
      query: ME_SSR
 | 
			
		||||
    })
 | 
			
		||||
 | 
			
		||||
    const price = await getPrice()
 | 
			
		||||
 | 
			
		||||
    return {
 | 
			
		||||
      props: {
 | 
			
		||||
        ...props,
 | 
			
		||||
 | 
			
		||||
@ -7,10 +7,10 @@ export const MeContext = React.createContext({
 | 
			
		||||
})
 | 
			
		||||
 | 
			
		||||
export function MeProvider ({ me, children }) {
 | 
			
		||||
  const { data } = useQuery(ME, { pollInterval: 1000 })
 | 
			
		||||
  const { data } = useQuery(ME, { pollInterval: 1000, fetchPolicy: 'cache-and-network' })
 | 
			
		||||
 | 
			
		||||
  const contextValue = {
 | 
			
		||||
    me: data ? data.me : me
 | 
			
		||||
    me: data?.me || me
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  return (
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user