@@ -2204,7 +2204,8 @@ var ReactDOMServerRenderer = function () {
2204
2204
// TODO: type this more strictly:
2205
2205
2206
2206
2207
- ReactDOMServerRenderer . prototype . read = function read ( bytes , cache ) {
2207
+ ReactDOMServerRenderer . prototype . read = function read ( bytes , cache , isStreaming ,
2208
+ streamingStart ) {
2208
2209
/*
2209
2210
--- Component caching variables ---
2210
2211
start: Tracks start index in output string and templatization data for cached components
@@ -2304,7 +2305,13 @@ var ReactDOMServerRenderer = function () {
2304
2305
else r = this . render ( child , frame . context , frame . domNamespace ) ;
2305
2306
2306
2307
// For simple (non-template) caching, save start index of component in output string
2307
- if ( ! isTemplate ) start [ cacheKey ] = out . length ;
2308
+ if ( ! isTemplate ) {
2309
+ if ( isStreaming ) {
2310
+ // streamingStart[cacheKey] = out.length;
2311
+ streamingStart [ cacheKey ] = streamingStart . sliceStartCount + out . length ;
2312
+ console . log ( "finalcount" , streamingStart . finalSliceStart ) ;
2313
+ } else start [ cacheKey ] = out . length ;
2314
+ }
2308
2315
} else { // Component found in cache
2309
2316
if ( isTemplate ) {
2310
2317
restoredTemplate = restoreProps ( reply , realProps , lookup ) ;
@@ -2326,47 +2333,53 @@ var ReactDOMServerRenderer = function () {
2326
2333
/*
2327
2334
--- After initial render of cacheable components, recover from output string and store in cache ---
2328
2335
*/
2329
- for ( let component in start ) {
2330
- let tagStack = [ ] ;
2331
- let tagStart ;
2332
- let tagEnd ;
2333
- let componentStart = ( typeof start [ component ] === 'object' ) ? start [ component ] . startIndex : start [ component ] ;
2334
-
2335
- do {
2336
- if ( ! tagStart ) tagStart = componentStart ;
2337
- else tagStart = ( out [ tagEnd ] === '<' ) ? tagEnd : out . indexOf ( '<' , tagEnd ) ;
2338
- tagEnd = out . indexOf ( '>' , tagStart ) + 1 ;
2339
- // Skip stack logic for void/self-closing elements and HTML comments
2340
- // Note: Does not account for tags inside HTML comments
2341
- if ( out [ tagEnd - 2 ] !== '/' && out [ tagStart + 1 ] !== '!' ) {
2342
- // Push opening tags onto stack; pop closing tags off of stack
2343
- if ( out [ tagStart + 1 ] !== '/' ) tagStack . push ( out . slice ( tagStart , tagEnd ) ) ;
2344
- else tagStack . pop ( ) ;
2336
+ if ( ! isStreaming ) {
2337
+ for ( let component in start ) {
2338
+ let tagStack = [ ] ;
2339
+ let tagStart ;
2340
+ let tagEnd ;
2341
+ let componentStart = ( typeof start [ component ] === 'object' ) ? start [ component ] . startIndex : start [ component ] ;
2342
+
2343
+ do {
2344
+ if ( ! tagStart ) tagStart = componentStart ;
2345
+ else tagStart = ( out [ tagEnd ] === '<' ) ? tagEnd : out . indexOf ( '<' , tagEnd ) ;
2346
+ tagEnd = out . indexOf ( '>' , tagStart ) + 1 ;
2347
+ // Skip stack logic for void/self-closing elements and HTML comments
2348
+ // Note: Does not account for tags inside HTML comments
2349
+ if ( out [ tagEnd - 2 ] !== '/' && out [ tagStart + 1 ] !== '!' ) {
2350
+ // Push opening tags onto stack; pop closing tags off of stack
2351
+ if ( out [ tagStart + 1 ] !== '/' ) tagStack . push ( out . slice ( tagStart , tagEnd ) ) ;
2352
+ else tagStack . pop ( ) ;
2353
+ }
2354
+ } while ( tagStack . length !== 0 ) ;
2355
+ // Cache component by slicing 'out'
2356
+ const cachedComponent = out . slice ( componentStart , tagEnd ) ;
2357
+ if ( typeof start [ component ] === 'object' ) {
2358
+ saveTemplates . push ( start [ component ] ) ;
2359
+ start [ component ] . endIndex = tagEnd ;
2345
2360
}
2346
- } while ( tagStack . length !== 0 ) ;
2347
- // Cache component by slicing 'out'
2348
- const cachedComponent = out . slice ( componentStart , tagEnd ) ;
2349
- if ( typeof start [ component ] === 'object' ) {
2350
- saveTemplates . push ( start [ component ] ) ;
2351
- start [ component ] . endIndex = tagEnd ;
2361
+ cache . set ( component , cachedComponent ) ;
2352
2362
}
2353
- cache . set ( component , cachedComponent ) ;
2354
- }
2355
2363
2356
- // After caching all cacheable components, restore props to templates
2357
- if ( saveTemplates ) {
2358
- let outCopy = out ;
2359
- out = '' ;
2360
- let bookmark = 0 ;
2361
- saveTemplates . sort ( ( a , b ) => a . startIndex - b . startIndex ) ;
2362
- // Rebuild output string with actual props
2363
- saveTemplates . forEach ( savedTemplate => {
2364
- out += outCopy . substring ( bookmark , savedTemplate . startIndex ) ;
2365
- bookmark = savedTemplate . endIndex ;
2366
- out += restoreProps ( outCopy . slice ( savedTemplate . startIndex , savedTemplate . endIndex ) ,
2367
- savedTemplate . realProps , savedTemplate . lookup ) ;
2368
- } ) ;
2369
- out += outCopy . substring ( bookmark , outCopy . length ) ;
2364
+ // After caching all cacheable components, restore props to templates
2365
+ if ( saveTemplates ) {
2366
+ let outCopy = out ;
2367
+ out = '' ;
2368
+ let bookmark = 0 ;
2369
+ saveTemplates . sort ( ( a , b ) => a . startIndex - b . startIndex ) ;
2370
+ // Rebuild output string with actual props
2371
+ saveTemplates . forEach ( savedTemplate => {
2372
+ out += outCopy . substring ( bookmark , savedTemplate . startIndex ) ;
2373
+ bookmark = savedTemplate . endIndex ;
2374
+ out += restoreProps ( outCopy . slice ( savedTemplate . startIndex , savedTemplate . endIndex ) ,
2375
+ savedTemplate . realProps , savedTemplate . lookup ) ;
2376
+ } ) ;
2377
+ out += outCopy . substring ( bookmark , outCopy . length ) ;
2378
+ }
2379
+ } else {
2380
+ // console.log(out.length, streamingStart);
2381
+ streamingStart . sliceStartCount += out . length ;
2382
+ console . log ( "rolling count" , streamingStart [ "sliceStartCount" ] ) ;
2370
2383
}
2371
2384
return out ;
2372
2385
} ;
@@ -2653,21 +2666,29 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function"
2653
2666
var ReactMarkupReadableStream = function ( _Readable ) {
2654
2667
_inherits ( ReactMarkupReadableStream , _Readable ) ;
2655
2668
2656
- function ReactMarkupReadableStream ( element , makeStaticMarkup ) {
2669
+ function ReactMarkupReadableStream ( element , makeStaticMarkup , cache , streamingStart ) {
2657
2670
_classCallCheck$1 ( this , ReactMarkupReadableStream ) ;
2658
2671
2659
2672
var _this = _possibleConstructorReturn ( this , _Readable . call ( this , { } ) ) ;
2660
2673
// Calls the stream.Readable(options) constructor. Consider exposing built-in
2661
2674
// features like highWaterMark in the future.
2662
2675
2663
-
2676
+ _this . cache = cache ;
2677
+ _this . streamingStart = streamingStart ;
2664
2678
_this . partialRenderer = new ReactDOMServerRenderer ( element , makeStaticMarkup ) ;
2665
2679
return _this ;
2666
2680
}
2667
2681
2668
2682
ReactMarkupReadableStream . prototype . _read = function _read ( size ) {
2669
2683
try {
2670
- this . push ( this . partialRenderer . read ( size ) ) ;
2684
+ this . push (
2685
+ this . partialRenderer . read (
2686
+ size ,
2687
+ this . cache ,
2688
+ true ,
2689
+ this . streamingStart
2690
+ )
2691
+ ) ;
2671
2692
} catch ( err ) {
2672
2693
this . emit ( 'error' , err ) ;
2673
2694
}
@@ -2682,8 +2703,13 @@ var ReactMarkupReadableStream = function (_Readable) {
2682
2703
*/
2683
2704
2684
2705
2685
- function renderToNodeStream ( element ) {
2686
- return new ReactMarkupReadableStream ( element , false ) ;
2706
+ function renderToNodeStream ( element , cache , streamingStart ) {
2707
+ return new ReactMarkupReadableStream (
2708
+ element ,
2709
+ false ,
2710
+ cache ,
2711
+ streamingStart
2712
+ ) ;
2687
2713
}
2688
2714
2689
2715
/**
0 commit comments