NextJS/Authenticator error: "Missing getServerSnapshot, which is required for server-rendered content."

See original GitHub issue

Before creating a new issue, please confirm:

On which framework/platform are you having an issue?

React

Which UI component?

Authenticator

How is your app built?

Create Next App

Please describe your bug.

When scaffolding a new Next.js app via npx create-next-app and trying to use the Authenticator component as documented, the app immediately breaks with a 500 internal server error:

Error: Missing getServerSnapshot, which is required for server-rendered content. Will revert to client rendering.

Screen Shot 2022-04-26 at 3 43 00 PM

What’s the expected behaviour?

The Authenticator component should render without any error and the app should build properly with yarn dev.

When the Authenticator is removed from index.js the app renders as expected.

Also, I tried both with/without wrapping _app.js with Authenticator.Provider and the error occurs in both approaches.

I feel like I’m maybe doing something wrong with my setup but can’t put my finger on it. The Amplify “Getting Started” docs for Next.js still uses import { AmplifyAuthenticator } from '@aws-amplify/ui-react-v1', but I wanted to work on some use cases for the new Authenticator with Next and haven’t found any relevant documentation on either the JS or UI docs site. I will update docs to use the new Authenticator component, but first want to make sure I am setting things up properly myself first.

Thanks for the help!

Help us reproduce the bug!

  1. npx create-next-app@latest next-example
  2. cd next-example && code .
  3. yarn add aws-amplify @aws-amplify/ui-react
  4. amplify add auth
  5. amplify push
  6. amplify init (default options)
  7. Import the Authenticator component into index.js (snippet attached)
  8. yarn dev
  9. The error occurs immediately

Code Snippet

// pages/index.js

import { Authenticator } from "@aws-amplify/ui-react";
import "@aws-amplify/ui-react/styles.css";

export default function Home() {
  return (
    <Authenticator>
      {({ signOut, user }) => (
        <main>
          <h1>Hello {user.username}</h1>
          <button onClick={signOut}>Sign out</button>
        </main>
      )}
    </Authenticator>
  );
}
// pages/_app.js

import { Amplify } from "aws-amplify";
import { Authenticator } from "@aws-amplify/ui-react";

import "../styles/globals.css";
import "@aws-amplify/ui-react/styles.css"; // default theme
import awsExports from "../src/aws-exports";

Amplify.configure({ ...awsExports, ssr: true });

export default function App({ Component, pageProps }) {
  return (
    <Authenticator.Provider>
      <Component {...pageProps} />
    </Authenticator.Provider>
  );
}

Additional information and screenshots

node -v
v16.14.2
{
  "name": "webpack-5-testing",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@aws-amplify/ui-react": "^2.15.5",
    "aws-amplify": "^4.3.20",
    "next": "12.1.5",
    "react": "18.0.0",
    "react-dom": "18.0.0"
  },
  "devDependencies": {
    "eslint": "8.14.0",
    "eslint-config-next": "12.1.5"
  }
}

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

11reactions
slaymancecommented, Apr 27, 2022

I’ve narrowed this issue down to React v18. We’re working on this issue now. In the meantime, the fix is to downgrade to React 17:

npm install react@17 react-dom@17

or, using yarn:

yarn add react@17 react-dom@17
3reactions
wlee221commented, Apr 29, 2022

Hey @nickarocho and those who found this issue, we just merged a fix #1798 and will be in the next release. I’ll let you know once it’s released!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Amlify react app throws Error: Missing getServerSnapshot ...
Amlify react app throws Error: Missing getServerSnapshot, which is required for server-rendered content. Will revert to client rendering.
Read more >
Data Fetching: getServerSideProps - Next.js
Pages using getServerSideProps will be server side rendered at request time and only be cached if cache-control headers are configured. If you do...
Read more >
Fix Next.js “Text content does not match server-rendered ...
Learn how to fix the React hydration error “Text content does not match server-rendered HTML” so you can personalize & transform HTML in ......
Read more >
Server-side rendering - Apollo GraphQL Docs
Server -side rendering (SSR) is a performance optimization for modern web apps. ... This enables you to specify any required authentication details when ......
Read more >
Getting Started with Server-Side Rendering (SSR) - JavaScript
To work well with server-rendered pages, Amplify JS requires slight modifications ... For client-only apps, Amplify.configure(awsExports) is all you need.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found