Skip to content

Breaking changes on Dialog causing jest + @testinglibrary/react to fail due to infinite loops #3740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
anniegiang-octave opened this issue May 28, 2025 · 0 comments

Comments

@anniegiang-octave
Copy link

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

    "@headlessui/react": "2.2.4",
    "jest": "29.7.0",
    "jest-axe": "10.0.0",
    "jest-environment-jsdom": "29.7.0",
    "next": "14.2.28",
    "@testing-library/jest-dom": "6.6.3",
    "@testing-library/react": "16.3.0",
    "@testing-library/user-event": "14.6.1",

What browser are you using?
Browser N/A

jest.config.js

testEnvironment: 'jsdom'

Reproduction URL

N/A

Describe your issue
Tests that render the Dialog are failing with an error. It only fails when open is true.

Maximum update depth exceeded. This can happen when a component repeatedly calls setState inside componentWillUpdate or componentDidUpdate. React limits the number of nested updates to prevent infinite loops.
import { Dialog, DialogBackdrop, DialogPanel } from '@headlessui/react';

export const MyDialog = ({
  children,
  trigger,
  open,
  ...props
}) => {
  return (
    <>
      {trigger}
      <Dialog open={open} {...props}>
        <DialogBackdrop />
        <DialogPanel>
          {children}
        </DialogPanel>
      </Dialog>
    </>
  );
};
  test('should render the children when open is true', () => {
    render(
      <MyDialog open trigger={<button type="button">trigger</button>} onClose={jest.fn()}>
        <div>hello world</div>
      </MyDialog>,
    );

    expect(screen.getByText('hello world')).toBeInTheDocument();
  });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant