[Question] Server Components #2474
-
Hello! We're finding React Native Web a very productive tool for building out UI. When a project supports iOS/Android and Web, even if the mobile UI isn't directly reused on the web, the reduced context switching of being able to use the same components and patterns across both is great. Thanks for all the work on it. In some cases the web experience may be a single-page app, where this setup works perfectly as it is. But in others it may be desirable to take advantage of server-side rendering. I've been having a look at the latest developments of Server Components in React, and gave it a try in the latest NextJS beta (the framework which the React team are directly collaborating with). Unfortunately using RNWeb in this setup hits a blocker pretty early on:
So my question is: is supporting Server Components likely to be on the roadmap for RNWeb in the future? In which case I could stick with mostly Client Components for now, with an eye to migrate them in future versions to Server Components, and/or locally patch some components now to remove usage of client APIs like Context. OR, is this a non-goal, and if SSR is a requirement of a project you'd suggest looking at other solutions than RNWeb? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 10 replies
-
I can't say I know much about server components. But I suppose the issue is related to the need for context to be present in the client. At Meta almost all the leaf component primitives in design systems use context as well. And Meta doesn't use server components in any meaningful capacity. Even if RNW didn't use context for RTL, it still uses it in every primitive to manage the relationship between View and Text as expected in RN. You can always SSR RNW code though. Server components are a different, experimental concept focused instead on not shipping "server only" code to the client. |
Beta Was this translation helpful? Give feedback.
-
If anyone happens to run into the same issue, I found the following solution to enable SSR on modern NextJS (13.4.10 using the app router): useServerInsertedHTML(() => {
return createElement('style', {
dangerouslySetInnerHTML: {
__html: StyleSheet.getSheet().textContent
}
});
}); Full gist: https://gist.github.com/filiptdz/974aeeb6a52254fc13128a36cdadb226 please let me know if there's something I'm missing |
Beta Was this translation helpful? Give feedback.
-
Where can I find some proper information on what's going on with RNW and NextJs? Most of us are looking for the scenario of sharing base components across web and mobile. I was evaluating remix and hit a roadblock, now im evaluating nextjs and running into similar issues. Who are some of the official voices on this thing? |
Beta Was this translation helpful? Give feedback.
I can't say I know much about server components. But I suppose the issue is related to the need for context to be present in the client.
At Meta almost all the leaf component primitives in design systems use context as well. And Meta doesn't use server components in any meaningful capacity. Even if RNW didn't use context for RTL, it still uses it in every primitive to manage the relationship between View and Text as expected in RN.
You can always SSR RNW code though. Server components are a different, experimental concept focused instead on not shipping "server only" code to the client.