From b9893667750612b152bdd8a209fcd18d2bea4fe4 Mon Sep 17 00:00:00 2001 From: handtrix Date: Wed, 4 Sep 2019 14:44:24 +0200 Subject: [PATCH] Add client only example page https://github.com/zeit/next.js/pull/8620#issuecomment-527870886 --- examples/with-apollo/components/Header.js | 5 ++++ examples/with-apollo/components/InfoBox.js | 17 ++++++++++++ examples/with-apollo/pages/client-only.js | 31 ++++++++++++++++++++++ examples/with-apollo/pages/index.js | 13 +++++++++ 4 files changed, 66 insertions(+) create mode 100644 examples/with-apollo/components/InfoBox.js create mode 100644 examples/with-apollo/pages/client-only.js diff --git a/examples/with-apollo/components/Header.js b/examples/with-apollo/components/Header.js index fab93963bb91c5..23700a99a34e2d 100644 --- a/examples/with-apollo/components/Header.js +++ b/examples/with-apollo/components/Header.js @@ -6,6 +6,11 @@ const Header = ({ router: { pathname } }) => ( Home + + + Client-Only + + About diff --git a/examples/with-apollo/components/InfoBox.js b/examples/with-apollo/components/InfoBox.js new file mode 100644 index 00000000000000..9b84bf1fe78b55 --- /dev/null +++ b/examples/with-apollo/components/InfoBox.js @@ -0,0 +1,17 @@ +const InfoBox = ({ children }) => ( +
+ + {children} +
+) + +export default InfoBox diff --git a/examples/with-apollo/pages/client-only.js b/examples/with-apollo/pages/client-only.js new file mode 100644 index 00000000000000..1ad91beb1f8479 --- /dev/null +++ b/examples/with-apollo/pages/client-only.js @@ -0,0 +1,31 @@ +import App from '../components/App' +import InfoBox from '../components/InfoBox' +import Header from '../components/Header' +import Submit from '../components/Submit' +import PostList from '../components/PostList' +import { withApollo } from '../lib/apollo' + +const ClientOnlyPage = props => ( + +
+ + ℹ️ This example shows how to disable apollos query fetching on the server. + If you reload this page, you will see a loader + since Apollo didn't fetch any data on the server. This allows{' '} + + automatic static optimization + + . + + + + +) + +export default withApollo(ClientOnlyPage, { + // Disable apollo ssr fetching in favor of automatic static optimization + ssr: false +}) diff --git a/examples/with-apollo/pages/index.js b/examples/with-apollo/pages/index.js index 7ba78076068539..15b5e67073b87a 100644 --- a/examples/with-apollo/pages/index.js +++ b/examples/with-apollo/pages/index.js @@ -1,4 +1,5 @@ import App from '../components/App' +import InfoBox from '../components/InfoBox' import Header from '../components/Header' import Submit from '../components/Submit' import PostList from '../components/PostList' @@ -7,6 +8,18 @@ import { withApollo } from '../lib/apollo' const IndexPage = props => (
+ + ℹ️ This example shows how to fetch all initial apollo queries on the + server. If you reload this page you won't see a loader + since Apollo fetched all needed data on the server. This prevents{' '} + + automatic static optimization + {' '} + in favor of full Server-Side-Rendering. +