question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug]: Dialog errors when used in a React routing framework

See original GitHub issue

What package within Headless UI are you using?

@headlessui/react

What version of that package are you using?

1.2.0

What browser are you using?

Firefox

Reproduction repository

React Router: https://codesandbox.io/s/mystifying-pond-0r5jv?file=/src/App.js Reach Router: https://codesandbox.io/s/jovial-euler-92zzn?file=/src/App.js

Describe your issue

When using either of the above routing frameworks, when navigating to a different page that renders a Dialog, the Dialog portal seems to get removed - resulting in the error:

There are no focusable elements inside the <FocusTrap />

To reproduce, one can observe the portal in the DOM on refresh, and on clicking a link to navigate to another page (which contains a modal) the portal gets removed from the DOM.

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:19
  • Comments:8

github_iconTop GitHub Comments

5reactions
ryanmrcommented, Jun 19, 2021

Hi all,

I made a small reproduction demo repo for this issue using next, tailwind, and @headlessui/react.

Edit:

I did end up finding a workaround. Adding the Dialog on mount seems to help this situation. See this branch in the same repo above for an example.

2reactions
RobinMalfaitcommented, Jan 19, 2022

Hey! Thank you for your bug report! Much appreciated! 🙏

This should be fixed and is available in the latest version, just update to the latest version and it should start working. Here is an updated codesandbox: https://codesandbox.io/s/zen-phoebe-hzy7i

Read more comments on GitHub >

github_iconTop Results From Across the Web

Problem with DialogComponent and react-router-dom
We have validated the issue, the Dialog is rendered by default with document.body as target. The console error “NotFoundError: Node was not ...
Read more >
Error Handling in React 16 – React Blog
Error boundaries catch errors during rendering, in lifecycle methods, and in constructors of the whole tree below them.
Read more >
React Js Redux with .net core 2.1 Framework error
Like the error says, identify the component that is undefined by the line numbers given and check if you imported it correctly and...
Read more >
Building a modal module for React with React-Router
We'll use four components from this package: BrowserRouter, Route, Link, and Switch. Since this is not a react-router tutorial, I won't be ...
Read more >
How to work with React the right way to avoid some common ...
The “setState warning” exists to help you catch bugs, because calling setState() on an unmounted component is an indication that your app/ ...
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