Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to latest Server Components conventions #62

Merged
merged 1 commit into from
Mar 31, 2023
Merged

Update to latest Server Components conventions #62

merged 1 commit into from
Mar 31, 2023

Conversation

gaearon
Copy link
Member

@gaearon gaearon commented Mar 31, 2023

This brings the demo up-to-date with the latest versions of the corresponding RFCs:

Changes in this pull request:

  • Bump dependencies (including React).
  • Get rid of .server.js and .client.js extensions.
    • The server-client split points are now signified by the 'use client' directive.
    • Where needed, import 'server-only' poison-pills server-only code (we do this in db.js).
  • Get rid of IO libraries like react-fetch, react-pg, etc.
    • Instead, use regular async/await.
  • Move "framework-like" code into src/framework.
    • I also simplified the API a bit so that the product code is easier to read.

This still isn't a production-ready setup because it doesn't include crucial parts like SSR. It also doesn't include first-class mutation support, which will be coming later as an RFC.

Co-authored-by: Matt Carroll <mattca@fb.com>
Copy link
Member

@rickhanlonii rickhanlonii left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v nice


You can watch a [recorded walkthrough of all these demo points here](https://youtu.be/La4agIEgoNg?t=600) (with timestamps).
You can watch a [recorded walkthrough of all these demo points here](https://youtu.be/La4agIEgoNg?t=600) with timestamps. (**Note:** this recording is slightly outdated because the repository has been updated to match the [latest conventions](https://react.dev/blog/2023/03/22/react-labs-what-we-have-been-working-on-march-2023#react-server-components).)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤘

@@ -6,7 +6,10 @@
*
*/

import {Pool} from 'react-pg';
// Error early if this is accidentally imported on the client.
import 'server-only';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add server-only to credentials.js?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe both? I was thinking it’s too easy to miss outside src folder.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they’re also imported from a seed script.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both is fine but it seems like the whole point is you stick it in your secret file.

@gaearon gaearon merged commit 37f20f9 into main Mar 31, 2023
@damassi
Copy link

damassi commented Apr 5, 2023

@gaearon

This still isn't a production-ready setup because it doesn't include crucial parts like SSR

Any suggestions on where to find examples to incorporate this missing bit? Would it be as simple as applying normal SSR patterns?

@gaearon
Copy link
Member Author

gaearon commented Apr 6, 2023

Any suggestions on where to find examples to incorporate this missing bit? Would it be as simple as applying normal SSR patterns?

It’s more involved because you need to consume the RSC stream in SSR, create HTML stream from it, and then combine them to ensure the initial render’s RSC output is inlined into HTML.

Have a look here for an example. https://github.com/unstubbable/mfng/blob/a0df63c893d3fe50c424914cc2237b3b55e48dc1/packages/core/src/server/create-html-stream.tsx#L19

@damassi
Copy link

damassi commented Apr 6, 2023

Just the repo I've been looking intently for. Thanks for the link @gaearon!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants