Next.js: React portal support for server side rendering

Created on 23 Dec 2017  路  10Comments  路  Source: vercel/next.js

Currently i am working on a AMP project where i need to render some AMP components directing into BODY. Though there are some external modules like 'react-portal' , 'react-portal-universal' does the same, but would like to see the native support in nextjs itself, as it can avoid extra webpack config change and react render tweaks.

Most helpful comment

I think this answer is a bit too simplistic to say that one need to create their own implementation. I understand that it works differently serverside, but actually this is nothing I should be worrying about. Portals should just be supported by next.js out of the box.

All 10 comments

Portals are a client only feature because you need to provide a DOM element where to render them and there no API inside react-dom/server.

I have a requirement to do this in SSR as well. Trying to figure out the best way to do this.

@antonybritto I think you'll need to create your own implementations of portals.

I think this answer is a bit too simplistic to say that one need to create their own implementation. I understand that it works differently serverside, but actually this is nothing I should be worrying about. Portals should just be supported by next.js out of the box.

@alinchican why not motivate your downvote instead of just downvoting? It sounds like you have a different opinion, so I would like to hear about that.

In my eyes next.js is a library for isomorphic react applications. Portals are a react feature and it sounds like next.js is not complete by not having support for a default react feature. Without support it would just partially support react and that would be a pity. It is great that next.js simplifies SSR and I think it should aim for being feature complete.

I'm not sure what you're referring to, React.createPortal is supported just fine, here's an example:
https://github.com/zeit/next.js/tree/canary/examples/with-portals

The original issue is about "Currently i am working on a AMP project" AMP has very different semantics and doesn't run client-side React.

Thanks @timneutkens. I ran into an issue (using PortalWithState) and arrived here in this topic and concluded incorrectly that it wasn't supported. It turns out that it works indeed when a pure portal is used. I understand that AMP is a total different case.

Excuses for the confusion and thanks for your time.

@PaulTondeur Because you didn't search for an answer. Last reply was posted 1 year ago, a lot of things have changed meanwhile. Also, this framework is named next.js and not zeit.js. I didn't think it was necessary to motivate my reaction. I'm glad your issue was resolved.

Edit: Nevermind, I missed that the example returns null if this.element is not set.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  3Comments

sospedra picture sospedra  路  3Comments

olifante picture olifante  路  3Comments

renatorib picture renatorib  路  3Comments

wagerfield picture wagerfield  路  3Comments