Closed L42y closed 8 years ago
Hi @L42y thanks for asking.
Since Transmit resolves data before and regardless of the React Component Tree (RCT) you need to compose the Transmit Promise Resolving Tree (PRT) separately. In your case, Layout
should be the root container, the one with initialVariables
. Then Home
could simply be nested by calling Home.getFragment(...)
etc within a Layout
-fragment. When adding more pages than just Home
you'll probably add some switch-statements in the Layout
-fragment to decide which page's fragments to nest. For example, Layout
may nest About
-fragments instead, depending on the route.
React doesn't have async rendering built-in, that's why isomorphic React and Transmit still relies on the concept of a separate PRT that resembles the RCT. When React supports async rendering in the future, we can attach our fragment queries directly to the RCT. More details here: https://github.com/facebook/react/issues/1739
The above is only necessary for the isomorphic part. For the client-side only/React Native stuff, deeper root containers are allowed, and deferred fragments are recommended as well to speed up the initial render.
Thanks for your great explanation!
@RickWong @L42y Do you have an example how to do that by any chance? Thanks.
@ngduc just a dummy example of how I have to do it currently: https://github.com/dimaip/neos-react-render/blob/master/src/Components/Root.js#L19
@RickWong hey, do you know if React would ever support async rendering in the future? Because from that discussion it doesn't seem they are planning to do anything in that direction... For me currently it's a major bummer, that increases the complexity of my components a lot. I even think of sacrificing server-side rendering in favor of simplicity for now.
When I use react-router together with react-transmit, I have a following use case:
This is the route definition:
Both
Layout
andHome
is or has react-transmit container, When render on server-side, only fragments inLayout
resolved and pass into client-side.I wonder if nested container is possible on isomorphic app, or is there any pattern I can use to have a global fragment (eg. user session).
Thanks!