-
-
Notifications
You must be signed in to change notification settings - Fork 631
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
Initial Implementation of RSC #1573
Conversation
try { | ||
const path = require('path'); | ||
const { readFileSync } = require('fs'); | ||
const reactClientManifest = readFileSync(path.resolve(__dirname, 'react-client-manifest.json'), 'utf8'); |
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 should only be read once and cached.
Shared across workers is better.
node_package/src/RSCRoute.tsx
Outdated
|
||
import useRSC from './useRSC'; | ||
|
||
import type { RSCRouteProps } from './types/index'; |
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.
Don't include /index
here.
node_package/src/ReactOnRails.ts
Outdated
@@ -241,6 +244,16 @@ ctx.ReactOnRails = { | |||
return serverRenderReactComponent(options); | |||
}, | |||
|
|||
/** | |||
* Used for React Server Components by Rails | |||
* @param options |
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.
Don't leave a comment like this empty.
import ComponentRegistry from './ComponentRegistry'; | ||
import buildConsoleReplay from './buildConsoleReplay'; | ||
import handleError from './handleError'; | ||
import type { RenderParams, RenderResult, RenderingError } from './types/index'; |
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 line 3 import here (and remove /index
).
import handleError from './handleError'; | ||
import type { RenderParams, RenderResult, RenderingError } from './types/index'; | ||
|
||
import { Writable } from 'node:stream'; |
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.
And this should be above the local imports.
try { | ||
const componentObj = ComponentRegistry.get(name); | ||
const { component } = componentObj; | ||
const reactRenderingResult = React.createElement(component as ReactComponent, props); |
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.
There are a lot of casts here, can we minimize them?
* @param {*} other headers | ||
* @returns {*} header | ||
*/ | ||
|
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.
Extra line.
node_package/src/types/index.ts
Outdated
@@ -28,13 +29,13 @@ export interface RailsContext { | |||
httpAcceptLanguage: string; | |||
} | |||
|
|||
type AuthenticityHeaders = {[id: string]: string} & {'X-CSRF-Token': string | null; 'X-Requested-With': string}; | |||
type AuthenticityHeaders = { [id: string]: string } & { 'X-CSRF-Token': string | null; 'X-Requested-With': string }; |
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 to remove &
and just do
type AuthenticityHeaders = {
[id: string]: string;
'X-CSRF-Token': string | null;
'X-Requested-With': string;
};
if we are changing this place anyway.
node_package/src/useRSC.ts
Outdated
|
||
useEffect(() => { | ||
setContent(createFromFetch(fetch( | ||
'/rsc/' + encodeURIComponent(componentName) + '?props=' + encodeURIComponent(JSON.stringify(props)) |
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.
Use a template string (or URI class).
node_package/src/useRSC.ts
Outdated
@@ -0,0 +1,15 @@ | |||
// @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.
Fix before merging (or better, don't even start with this).
@@ -0,0 +1,2 @@ | |||
declare module 'react-server-dom-webpack/server.node'; | |||
declare module 'react-server-dom-webpack/client.browser'; |
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.
Should there be something in these declarations?
Signed-off-by: Khaled Emara <[email protected]>
1f932bb
to
6a42d6e
Compare
Is this PR ready for review? If yes, May you please update the description to reflect the state of the PR? |
@KhaledEmaraDev close this one? |
@justin808 No, it's needed for the Pro version to work. I think it could be accepted as-is. I will not introduce new changes to it. |
"homepage": "https://github.com/shakacode/react_on_rails#readme", | ||
"husky": { | ||
"hooks": { | ||
"pre-commit": "yalc check" |
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 is this needed pre-commit?
@@ -32,6 +32,7 @@ | |||
"eslint-plugin-jsx-a11y": "^6.7.1", | |||
"eslint-plugin-prettier": "^3.4.1", | |||
"eslint-plugin-react": "^7.32.1", | |||
"husky": "^4.3.6", |
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.
husky and yalc should be separate PRs.
"exports": { | ||
".": "./node_package/lib/ReactOnRails.js", | ||
"./*": "./node_package/lib/*.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.
@KhaledEmaraDev can you explain this?
Seems odd to start exporting everything from package.json
Why not add what's necessary to the current exports?
We already have:
https://github.com/shakacode/react_on_rails/blob/master/node_package/src/ReactOnRails.ts#L292-L293
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 file should not be changing, right?
Summary
This is an initial implementation of React Server Components (RSC). In this PR:
useRSC()
and a React Component that extendsreact-router-dom
'sRoute
namedRSCRoute
to be used to route to RSC components.Related to
https://github.com/shakacode/react_on_rails_pro/pull/346
Pull Request checklist
Remove this line after checking all the items here. If the item is not applicable to the PR, both check it out and wrap it by
~
.Add the CHANGELOG entry at the top of the file.
Other Information
Remove this paragraph and mention any other important and relevant information such as benchmarks.
This change is