Using createPortal and Router causes route to be removed
See original GitHub issueNot too sure if this belongs more here or on preact-router
. But I was investigating a strange behaviour in my app that I’m slowly moving from 8.4.2 to X.
I made a codesandbox that illustrates the issue.
It seems as that when you call createPortal
in a router path, it renders the contents of the portal, but removes everything else.
I would expect it to render into the defined element, either at the beginning or the end, but it seems to replace everything.
If this should be moved to preact-router
I can move it there.
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (6 by maintainers)
Top Results From Across the Web
Using createPortal and Router causes route to be removed
It seems as that when you call createPortal in a router path, it renders the contents of the portal, but removes everything else....
Read more >React-Router Redirect from a portal not redirecting
Since StreamDelete is directly rendered by a Route component <Route path="/streams/:id/delete" exact component={StreamDelete} />. Solution.
Read more >Portals - React
Portals provide a first-class way to render children into a DOM node that exists outside the DOM hierarchy of the parent component. ReactDOM.createPortal(child, ......
Read more >Understanding React Portals and Its Use-Cases
React Portal is a first-class way to render child components into a DOM node outside of the parent DOM hierarchy defined by the...
Read more >Portals with Context - React Training
Normally we might expect the modal to be rendered as a sibling to the "Remove User" button since that's how it looks in...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
This is a bug, when using createPortal it overrides the full given node instead of inserting before already existing elements.
I have tested it with a minimal example and it is.
Most minimal example to test with:
This will effectively remove
<p>Hello</p>
from rootI’ll reopen this until there is as definite answer,
document.body
works butdocument.querySelector(#root)
does not when used withpreact-router