File tree Expand file tree Collapse file tree 4 files changed +20
-14
lines changed
Expand file tree Collapse file tree 4 files changed +20
-14
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " react-server-renderer" ,
3- "version" : " 0.0.1 " ,
3+ "version" : " 0.1.0 " ,
44 "description" : " simple React SSR solution inspired by vue-server-render" ,
55 "repository" : " git@github.com:JounQin/react-server-render.git" ,
66 "main" : " lib/index.js" ,
Original file line number Diff line number Diff line change @@ -120,7 +120,7 @@ export function createBundleRendererCreator(
120120 return promise
121121 } ,
122122
123- renderToStream : ( context ? : UserContext ) => {
123+ renderToStream : ( context : UserContext = { } ) => {
124124 const res = new PassThrough ( )
125125 run ( context )
126126 . catch ( err => {
@@ -142,12 +142,10 @@ export function createBundleRendererCreator(
142142
143143 // relay HTMLStream special events
144144 if ( rendererOptions && rendererOptions . template ) {
145- renderStream . on ( 'beforeStart' , ( ) => {
146- res . emit ( 'beforeStart' )
147- } )
148- renderStream . on ( 'beforeEnd' , ( ) => {
149- res . emit ( 'beforeEnd' )
150- } )
145+ renderStream
146+ . on ( 'beforeStart' , ( ) => res . emit ( 'beforeStart' ) )
147+ . on ( 'beforeEnd' , ( ) => res . emit ( 'beforeEnd' ) )
148+ . on ( 'redirect' , url => res . emit ( 'redirect' , url ) )
151149 }
152150
153151 renderStream . pipe ( res )
Original file line number Diff line number Diff line change @@ -65,18 +65,24 @@ export function createRenderer(
6565
6666 renderToStream (
6767 component : ReactElement < any > ,
68- context ? : UserContext ,
68+ context : UserContext ,
6969 ) : NodeJS . ReadableStream {
70- if ( context ) {
71- templateRenderer . bindRenderFns ( context )
72- }
73-
7470 const renderStream = renderToNodeStream ( component )
7571
76- if ( ! options . template ) {
72+ const { url } = context
73+
74+ if ( url ) {
75+ process . nextTick ( ( ) => {
76+ renderStream . emit ( 'redirect' , url )
77+ } )
78+ }
79+
80+ if ( ! options . template || url ) {
7781 return renderStream
7882 }
7983
84+ templateRenderer . bindRenderFns ( context )
85+
8086 const templateStream = templateRenderer . createStream ( context )
8187 renderStream . on ( 'error' , err => templateStream . emit ( 'error' , err ) )
8288 renderStream . pipe ( templateStream )
Original file line number Diff line number Diff line change @@ -24,7 +24,9 @@ export interface UserContext {
2424 head ?: string
2525 styles ?: string
2626 getPreloadFiles ?: any
27+ url ?: string
2728 _styles ?: any
2829 _mappedFiles ?: any
2930 _registeredComponents ?: Set < any >
31+ [ key : string ] : any
3032}
You can’t perform that action at this time.
0 commit comments