File tree Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Expand file tree Collapse file tree 2 files changed +18
-7
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,14 @@ type RSCPayloadContainerInnerProps = {
1414 getChunkPromise : ( chunkIndex : number ) => Promise < StreamChunk > ;
1515} ;
1616
17+ // In JavaScript, when an escape sequence with a backslash (\) is followed by a character
18+ // that isn't a recognized escape character, the backslash is ignored, and the character
19+ // is treated as-is.
20+ // This behavior allows us to use the backslash to escape characters that might be
21+ // interpreted as HTML tags, preventing them from being processed by the HTML parser.
22+ // For example, we can escape the comment tag <!-- as <\!-- and the script tag </script>
23+ // as <\/script>.
24+ // This ensures that these tags are not prematurely closed or misinterpreted by the browser.
1725function escapeScript ( script : string ) {
1826 return script . replace ( / < ! - - / g, '<\\!--' ) . replace ( / < \/ ( s c r i p t ) / gi, '</\\$1' ) ;
1927}
@@ -104,7 +112,7 @@ export default function RSCPayloadContainerWrapper({ RSCPayloadStream }: RSCPayl
104112
105113 const getChunkPromise = React . useCallback (
106114 ( chunkIndex : number ) => {
107- if ( chunkIndex > chunkPromises . length ) {
115+ if ( chunkIndex >= chunkPromises . length ) {
108116 throw new Error ( 'React on Rails Error: RSC Chunk index out of bounds' ) ;
109117 }
110118
Original file line number Diff line number Diff line change @@ -104,12 +104,15 @@ const RSCServerRoot: RenderFunction = async (
104104 rscPayloadStream . pipe ( rscPayloadStream2 ) ;
105105 const serverComponentElement = createFromReactOnRailsNodeStream ( rscPayloadStream1 , ssrManifest ) ;
106106
107- return ( ) => (
108- < >
109- < React . Fragment key = "serverComponentElement" > { use ( serverComponentElement ) } </ React . Fragment >
110- < RSCPayloadContainer RSCPayloadStream = { rscPayloadStream2 } key = "rscPayloadContainer" />
111- </ >
112- ) ;
107+ return ( ) => {
108+ const resolvedServerComponent = use ( serverComponentElement ) ;
109+ return (
110+ < >
111+ < React . Fragment key = "serverComponentElement" > { resolvedServerComponent } </ React . Fragment >
112+ < RSCPayloadContainer RSCPayloadStream = { rscPayloadStream2 } key = "rscPayloadContainer" />
113+ </ >
114+ ) ;
115+ } ;
113116} ;
114117
115118export default RSCServerRoot ;
You can’t perform that action at this time.
0 commit comments