amplify-ui: "Error: Maximum update depth exceeded" when attempting to render Authenticator component with React 18's createRoot API

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 React App

Please describe your bug.

Trying to render the Authenticator or withAuthenticator components with React 18’s createRoot API results in errors being thrown.

This newer render API might also be the cause of the Authenticator not rendering properly on newer Next.js (>= v12.1.1) apps built using create-next-app.

What’s the expected behaviour?

Authenticator components should render without errors

Help us reproduce the bug!

  1. npx create-react-app my-app
  2. cd my-app
  3. npm i aws-amplify @aws-amplify/ui-react
  4. copy paste provided code snippets into respective files
  5. npm run start
  6. Authenticator may render for a few seconds, try interacting with it to trigger the errors

Code Snippet

// index.js

import React from "react";
import * as ReactDOMClient from "react-dom/client";
import App from "./App";
import { Amplify } from "aws-amplify";
import awsmobile from "./aws-exports";

import "./index.css";

Amplify.configure(awsmobile);

const container = document.getElementById("root");

const root = ReactDOMClient.createRoot(container);

root.render(<App />);
// App.js

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

const App = () => {
  return <h1>Welcome</h1>;
};

export default withAuthenticator(App);

Additional information and screenshots

Screen Shot 2022-03-29 at 5 38 22 PM

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 4
  • Comments: 18 (8 by maintainers)

Most upvoted comments

This has been now published to @aws-amplify/ui-react@2.14.1. Can you update to the latest version and retry?

Please let us know if the problem persists, and please open a new issue if you find other frictions with React 18!

Hi all, I’m onto this and have found the root cause. This is due to cascading re-renders inside the Authenticator, and is being worked on in #1619 and #1620.

Hi All, I just merged my fixes and will be released later today. Will let you know again once it’s published!

context => [context.toResetPassword]

It works, thank you very much!

Thanks @chrisbonifacio ! I was able to reproduce this. We’ll have to do some work to get our Authenticator working with React 18!