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.

In order to render modals at the end of the DOM rather than in place there is a concept of “Portals” which render React DOM into a new context.

Most implementations of this (including the one in react-modal) work by using:

ReactDOM.unstable_renderSubtreeIntoContainer(...)

and a little extra magic to update the portal appropriately.

The problem with this (other than using an api still marked “unstable”) is that it does not work in a server-side/universal/isomorphic context because it works by creating an element and appending it to document.body.

Obviously this is not an ideal solution, so I’ve created a new way of doing this that fits within the normal react rendering cycle.

<GatewayProvider>
  <div className="application">
    <div className="application-content">
      <Gateway into="example">
        Hello from Gateway
      </Gateway>
    </div>
    <GatewayDest name="example" className="gateway"/>
  </div>
</GatewayProvider>

Which will render like this:

<div class="application">
  <div class="application-content"></div>
  <div class="gateway">
    Hello from Gateway
  </div>
</div>

It does this by maintaining an internal registry which tracks containers and children and renders them using the normal react component lifecycle. I’ve published this module as react-gateway

I’ve used this to create a React modal library that can be rendered universally: react-modal2 (note this is not a drop-in replacement, it has a different/less-opinionated api).

I think it would be really awesome if react-modal could do the same and use react-gateway too.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
gaearoncommented, May 25, 2016

I don’t see why it wouldn’t work. It renders in componentWillReceiveProps which should be enough. Can you please file an issue with RHL and a minimal reproducing case?

0reactions
OliverJAshcommented, May 4, 2019

IIUC, SSR of the modal does not work because the modal uses portals. This proposal offers a solution. Is that correct?

I for one would very much like a solution to enable SSR for the modal.

Re. https://github.com/reactjs/react-modal/issues/580#issuecomment-489330313

Read more comments on GitHub >

github_iconTop Results From Across the Web

react-gateway - npm
Start using react-gateway in your project by running `npm i react-gateway`. There are 21 other projects in the npm registry using react-gateway.
Read more >
cloudflare/react-gateway: Render React DOM into a ... - GitHub
React Gateway works very differently than most React "portals" in order to work in server-side rendered React applications. It maintains an internal registry...
Read more >
react-gateway examples - CodeSandbox
React Gateway Examples. Learn how to use react-gateway by viewing and forking example apps that make use of react-gateway on CodeSandbox.
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 >
Merry Microservices: Part 2 'UI Gateway'–A React UI served by ...
Put your gateway.zip file where you want your combined UI and Gateway code to live. Then unzip it and create your react 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