-
Notifications
You must be signed in to change notification settings - Fork 0
[WIP - on HOLD] Initital Implementation of RSC #346
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
Conversation
Gemfile.development_dependencies
Outdated
| gem "react_on_rails", "13.3.4" # keep in sync with package.json files | ||
| # gem "react_on_rails", "13.3.4" # keep in sync with package.json files | ||
|
|
||
| # For local development | ||
| # gem "react_on_rails", path: "../react_on_rails" | ||
| gem "react_on_rails", path: "../react_on_rails" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do not include in the PR!
| import React, { Suspense } from 'react'; | ||
|
|
||
| import { marked } from 'marked'; // 35.9K (11.2K gzipped) | ||
| import sanitizeHtml from 'sanitize-html'; // 206K (63.3K gzipped) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No point including comments which will get obsolete so easily.
| const allowedAttributes = Object.assign( | ||
| {}, | ||
| sanitizeHtml.defaults.allowedAttributes, | ||
| { | ||
| img: ['alt', 'src'], | ||
| } | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could be simplified to
const allowedAttributes = { ...sanitizeHtml.defaults.allowedAttributes, img: ['alt', 'src'] };
as far as I can see.
514406f to
32399fb
Compare
Signed-off-by: Khaled Emara <[email protected]>
32399fb to
db0c386
Compare
| @@ -0,0 +1,17 @@ | |||
| // @ts-ignore | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use @ts-expect-error instead and write a comment about why it's ignored.
| }) { | ||
| const [count, setCount] = useState(0); | ||
|
|
||
| const allowedTags = [...defaultAllowedTags, ...['img', 'h1', 'h2', 'h3']]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the second spread, just [...defaultAllowedTags, 'img', 'h1', 'h2', 'h3'].
|
|
||
| # TODO: RailsContext | ||
| js_code = ReactOnRailsPro::ServerRenderingJsCode.render_rsc( | ||
| props_string(params[:props] || {}).gsub("\u2028", '\u2028').gsub("\u2029", '\u2029'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why just these two? Add a comment?
lib/react_on_rails_pro/server_rendering_pool/node_rendering_pool.rb
Outdated
Show resolved
Hide resolved
Signed-off-by: Khaled Emara <[email protected]>
| @@ -0,0 +1,11 @@ | |||
| node_modules | |||
| lib/ | |||
| webpack.config.js | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It normally shouldn't be ignored, any reason why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's taken from the react-on-rails package. Webpack isn't used anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO better to limit to the files we actually want to ignore.
| @@ -0,0 +1,12 @@ | |||
| node_modules | |||
|
|
|||
| lib | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Better ignore only at root: /lib, this is quite a likely name for needed directories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's needed here too as tsc outputs here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, I mean if you put /lib here it will only ignore this particular lib. If you have lib, it will ignore something like src/some_path/lib as well.
| node_modules/ | ||
| package.json | ||
| **/app/assets/webpack/ | ||
| lib/* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably also /lib/* if it's supported here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the main output directory there are no other output directories for this package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is not output but someone who names a directory inside sources lib later.
| @@ -0,0 +1,265 @@ | |||
| const acorn = require('acorn-loose'); | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why this file is JS instead of TS?
| @@ -0,0 +1,3 @@ | |||
| export default function context(this: void): Window | NodeJS.Global| typeof globalThis | void { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why a void parameter?
| // TODO: Check why importing "react-on-rails" is required. | ||
| // TODO: Check why we have to register using ReactOnRailsPro only. | ||
| // import statement added by react_on_rails:generate_packs rake task | ||
| import "./../generated/server-bundle-generated.js" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just ../generated (remove ./)?
| if (loading) return <p>Loading...</p>; | ||
| if (error) return <p>Error : {error.message}</p>; | ||
|
|
||
| const allowedTags = [...sanitizeHtml.defaults.allowedTags, ...['img', 'h1', 'h2', 'h3']]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also no need for the second spread.
| } | ||
|
|
||
| clientConfig.plugins.unshift(new ReactServerWebpackPlugin({ | ||
| isServer: false, clientReferences: [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move clientReferences to a separate line for readability (though Prettier will probably say that as well).
|
@KhaledEmaraDev @AbanoubGhadban should be closed in favor of #422? |
This is an initial implementation of React Server Components (RSC). In this PR:
props.ClientandSSRmanifests required for RSC to work and upload them to thenode-renderer.setImmediate()to thenode-renderer's context because it's being used by RSC.react-router-domand theRSCRoutefromreact_on_railsto render a server component that does two things:markedandsanitize-htmlwhich combined are 75K gzipped. (They aren't shipped to the server)Limitations:
Newer React Server rendering are generally done using streams to one by one stream rendered content and support React's
<Suspense>. The way we render right now one shots everything once it's done making<Suspense>useless on the server. Read here.Related to
shakacode/react_on_rails#1573