Skip to content

Conversation

@sebmarkbage
Copy link
Collaborator

@sebmarkbage sebmarkbage commented Feb 28, 2023

Builds on #26257.

To do this we need access to a manifest for which scripts and CSS are used for each "page" (entrypoint).

The initial script to bootstrap the app is inserted with bootstrapScripts. Subsequent content are loaded using the chunks mechanism built-in.

The stylesheets for each pages are prepended to each RSC payload and rendered using Float. This doesn't yet support styles imported in components that are also SSR:ed nor imported through Server Components. That's more complex and not implemented in the node loader.

HMR doesn't work after reloads right now because the SSR renderer isn't hot reloaded because there's no idiomatic way to hot reload ESM modules in Node.js yet. Without killing the HMR server. This leads to hydration mismatches when reloading the page after a hot reload.

Notably this doesn't show serializing the stream through the HTML like real implementations do. This will lead to possible hydration mismatches based on the data. However, manually serializing the stream as a string isn't exactly correct due to binary data. It's not the idiomatic way this is supposed to work. This will all be built-in which will make this automatic in the future.

@sebmarkbage sebmarkbage requested a review from gaearon February 28, 2023 18:55
@facebook-github-bot facebook-github-bot added CLA Signed React Core Team Opened by a member of the React Core Team labels Feb 28, 2023
@react-sizebot
Copy link

react-sizebot commented Feb 28, 2023

Comparing: 40755c0...3684595

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 155.25 kB 155.25 kB = 48.98 kB 48.98 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 157.24 kB 157.24 kB = 49.64 kB 49.64 kB
facebook-www/ReactDOM-prod.classic.js = 532.50 kB 532.50 kB = 94.85 kB 94.85 kB
facebook-www/ReactDOM-prod.modern.js = 516.42 kB 516.42 kB = 92.45 kB 92.45 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-experimental/react-server-dom-webpack/cjs/react-server-dom-webpack-plugin.js = 4.20 kB 4.19 kB = 1.84 kB 1.83 kB
oss-stable-semver/react-server-dom-webpack/cjs/react-server-dom-webpack-plugin.js = 4.20 kB 4.19 kB = 1.84 kB 1.83 kB
oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-plugin.js = 4.20 kB 4.19 kB = 1.84 kB 1.83 kB

Generated by 🚫 dangerJS against 3684595

precedence: 'default',
})
),
React.createElement(App),
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why couldn't the mainCSSChunks be passed as prop to App which would then render the link elements in the head, similar to what is documented at https://beta.reactjs.org/reference/react-dom/server/renderToPipeableStream#reading-css-and-js-asset-paths-from-the-build-output?

Copy link
Collaborator Author

@sebmarkbage sebmarkbage Feb 28, 2023

Choose a reason for hiding this comment

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

It could but this shows that you don't have to - using a new feature that places it in the right place. So the App code can't mess it up by forgetting.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Now I realise that this was a stupid question. I wasn't aware that this avoids the need to serialise them manually with bootstrapScriptContent, and instead "Float" is handling these elements automatically. Sorry for the noise my PR comments might create.


export const transformSource =
process.version < 'v16' ? babelTransformSource : undefined;
export const getSource = process.version < 'v16' ? getSourceImpl : undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

getting a ReferenceError: getSourceImpl is not defined error on node 14. Is this an oversight?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fixed. It still doesn't work on 14 though because undici isn't supported.

Copy link
Collaborator

@gnoff gnoff left a comment

Choose a reason for hiding this comment

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

Aside from the error on old node, I think this looks good

@sebmarkbage sebmarkbage merged commit 67a61d5 into facebook:main Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed React Core Team Opened by a member of the React Core Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants