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

Add RSC-based static site generator #10057

Merged
merged 8 commits into from
Dec 24, 2024
Merged

Add RSC-based static site generator #10057

merged 8 commits into from
Dec 24, 2024

Conversation

devongovett
Copy link
Member

This adds plugins for a React Server Components-based static site generator. In this setup, Parcel executes server components during the build and produces static HTML. Client components are hydrated at runtime.

It's implemented in two plugins:

  • @parcel/namer-static renames entry bundles to have a .html extension, so that the following packager runs.
  • @parcel/packager-react-static runs the JS assets in its bundle at build time, and uses React's static APIs to generate HTML.

Core changes are to support packagers returning multiple streams for different versions of the bundle. The react static packager returns both a .html file, as well as a .rsc file containing the raw RSC stream. This can be used for client-side navigations instead of reloading the whole page. Each PackagedBundle now has a files property which lists all of the files produced for that bundle, including source maps, and files produced by compressor plugins as well.

Page components receive a list of all of the pages (based on the entry bundles), along with the current page, from the packager as props. This lets them generate navigation links.

"targets": {
"default": {
"context": "react-server",
"scopeHoist": false
Copy link
Member Author

Choose a reason for hiding this comment

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

Slightly unfortunate: because we want to skip the JS packager and run the assets during the static packager directly, we have to turn off scope hoisting. It's easy to emulate the dev packager's output with node's vm but hard to handle the structure generated by the scope hoisting transformer.

@devongovett devongovett merged commit 393f497 into v2 Dec 24, 2024
17 checks passed
@devongovett devongovett deleted the react-ssg branch December 24, 2024 05:28
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.

1 participant