With this experiment, we are making a significant change in the way you think about, and build Redwood apps. Redwood now becomes SSR-first, and moves away from the Jamstack model of deploying static web assets to a CDN. Your routes are streamed from the server, then hydrated on the client — leveraging React 18’s new streaming & Suspense capabilities.
Part 1: Let’s start rendering on the server + dynamic <meta>
tags for SEO and link sharing
What you’ll be able to do
Dev, with streaming + SSR
Build, then deploy a prod server
Dynamically generate HTML <meta>
headers, so that when you share your links on Discord/Twitter/Slack - you can generate link previews
Make sure you’re on the canary version of Redwood (v7.x-canary)
yarn rw upgrade -t canary
And now, let’s setup your project for streaming!
yarn rw exp setup-streaming-ssr
This will create a few files:
- (overwrite) web/src/entry.client.tsx
- web/src/entry.server.tsx
- web/src/components/Document.tsx
- Note that this now becomes your “index.html”. So if you have any customisations there, you might want to bring them in here.
- While SSR-Streaming is experimental, please don’t remove the index.html file in web/src/index.html - as this is still required.
It will also add a flag to your redwood.toml that’ll tell Redwood internally that we need to build and run your project differently.
Tada, that’s it!
Now when you:
- Run
yarn rw dev
— it will server-render your pages - If you want to run a built version:
yarn rw build
process will build your project ready for server renderingyarn rw serve
will run a web server (along with your usual api server)
- You can use the meta route hooks (see section below)
Additional Docs
What’s next?
In the next few days, I’ll add a follow up post with Part 2, which brings some really exciting new features:
- Cells being rendered on the server
- Ability to generate dynamic meta headers using the results in a Cell
- CSS-in-JS support (libraries like styled components, emotion) [untested]
- “Render-as-you-fetch” with Apollo client — to give your app a serious performance boost!