A fully working beta of communitypackages:react-router-ssr which is compatible with Meteor 3 has been published. This brings full server rendering in react to Meteor 3 with full data hydration and the ability to to server render components containing suspense boundaries.
If you’re currently using this package, please upgrade and give it a test to help find any issues.
There’s still much to do such as React 19 compatibility. I’ll hold off on that till the next version though. If anyone wants to jump in and work on these kinds of updates, please do.
Thanks @minhna. Hoping to have a stable release in the next week or so. I’ll be putting it through its paces by upgrading a client app that’s been waiting to upgrade to Meteor 3 and has been blocked by the compatibility of this package.
I just tested this and it works really good using react 18. However using the latest react-meteor-data@3.0.5-beta.0 it doesn’t load the data. Can you have a look what’s the problem?
The community has made many improvements in react-meteor-data@3.0.5-beta.0, all backed by tests. Still, some scenarios might not behave as expected. Have you checked if it works with the previous stable version?
If it does, we should isolate your use case in the beta version so we can reproduce it in conjuntion with react-router-ssr in a test and include a fix with other updates in react-meteor-data. Could you provide more reproduction steps for them to fix? Or maybe the issue is on react-router-ssr side, we should verify.
It’s working with the current react-meteor-data stable version 3.0.3.
It can be replicated with copleykj’s react-router-ssr-demo. With the current stable react-meteor-data it loads all the links on the main page, with the new beta there are no links showing.
So after a lot of work and fighting with this I realized that there is just not a good way to get SSR working properly with React unless we fully embrace React’s rendering process. This requires bypassing Meteor’s default boilerplate and surrendering full HTML generation to React. To facilitate this we needed 2 things:
Access to the Express response object so we can pipe React’s rendered output to it.
Meteor not to generate its own boilerplate and pipe it to the response.
I’ve recently created this pull request on the meteor/meteor repository with changes to the webapp package which accomplish these 2 things and allow React to server render in the way that it’s API dictates.
Currently these changes are in review, but I’m hopeful that we might see them in a not so distant release. Once these changes are released I’ll release new major versions of fast-render and react-router-ssr and all will be right in the world of React SSR in Meteor once again (after probably several years). Notable things that this brings to the table
Why Is This Necessary
Previously the standard practice to server render React applications in Meteor was to use renderToString. For some time this was deprecated (not any longer it appears), and it does not support streaming, or awaiting data. This means our react-meteor-data integrations don’t work properly on the server, and we can’t use suspense boundaries on the server. Also since it doesn’t wait for data to return on rendering, fast-render never gathers the necessary data to send to the client resulting in incomplete population data in mini-mongo when the page loads.
What We Get Fully Embracing React’s Paradigm
isomorphic view rendering
Full use of Suspense and Error Boundaries
Use of React Router’s data routers, which enable things like scroll restore
Closing
Let me know what you guys think. This has been a long time coming, and I’m excited to possibly have proper support for SSR with React in Meteor again