Skip to content

Commit

Permalink
Update withApollo.tsx (#102)
Browse files Browse the repository at this point in the history
This removes Head.Rewind as well as the Unused Import
  • Loading branch information
Lwachira authored Jun 24, 2021
1 parent 4857e58 commit 20bdfb0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions src/withApollo.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import {
ApolloClient,
ApolloProvider,
NormalizedCacheObject,
NormalizedCacheObject
} from "@apollo/client";
import { NextPage, NextPageContext } from "next";
import App, { AppContext } from "next/app";
import Head from "next/head";
import React from "react";

// On the client, we store the Apollo Client in the following variable.
Expand Down Expand Up @@ -35,7 +34,7 @@ export const initOnContext = (
acp: ApolloClientParam,
ctx: ContextWithApolloOptions
) => {
const ac = typeof acp === 'function' ? acp(ctx) : acp as ApolloClient<NormalizedCacheObject>;
const ac = typeof acp === 'function' ? acp(ctx) : acp as ApolloClient<NormalizedCacheObject>;
const inAppContext = Boolean(ctx.ctx);

// We consider installing `withApollo({ ssr: true })` on global App level
Expand All @@ -44,7 +43,7 @@ export const initOnContext = (
if (inAppContext) {
console.warn(
"Warning: You have opted-out of Automatic Static Optimization due to `withApollo` in `pages/_app`.\n" +
"Read more: https://err.sh/next.js/opt-out-auto-static-optimization\n"
"Read more: https://err.sh/next.js/opt-out-auto-static-optimization\n"
);
}
}
Expand Down Expand Up @@ -84,8 +83,8 @@ const initApolloClient = (
initialState: NormalizedCacheObject,
ctx: NextPageContext | undefined
) => {
const apolloClient = typeof acp === 'function' ? acp(ctx) : acp as ApolloClient<NormalizedCacheObject>;
const apolloClient = typeof acp === 'function' ? acp(ctx) : acp as ApolloClient<NormalizedCacheObject>;

// Make sure to create a new client for every server-side request so that data
// isn't shared between connections (which would be bad)
if (typeof window === "undefined") {
Expand Down Expand Up @@ -193,7 +192,6 @@ export default function withApollo<P, IP>(ac: ApolloClientParam) {

// getDataFromTree does not call componentWillUnmount
// head side effect therefore need to be cleared manually
Head.rewind();
}
}

Expand All @@ -216,7 +214,7 @@ const createApolloClient = (
acp: ApolloClientParam,
initialState: NormalizedCacheObject,
ctx: NextPageContext | undefined
) => {
) => {
const apolloClient = typeof acp === 'function' ? acp(ctx) : acp as ApolloClient<NormalizedCacheObject>;
// The `ctx` (NextPageContext) will only be present on the server.
// use it to extract auth headers (ctx.req) or similar.
Expand Down

0 comments on commit 20bdfb0

Please sign in to comment.