File tree Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Expand file tree Collapse file tree 2 files changed +18
-10
lines changed Original file line number Diff line number Diff line change @@ -33,16 +33,24 @@ export function createRenderFunction (
3333 if ( cache . has ( key ) ) {
3434 return write ( cache . get ( key ) , next )
3535 } else {
36- if ( ! write . caching ) {
37- // initialize if not already caching
38- write . caching = true
39- const _next = next
40- next = ( ) => {
41- cache . set ( key , write . buffer )
36+ write . caching = true
37+ const buffer = write . cacheBuffer
38+ const bufferIndex = buffer . push ( '' ) - 1
39+ const _next = next
40+ next = ( ) => {
41+ const result = buffer [ bufferIndex ]
42+ cache . set ( key , result )
43+ if ( bufferIndex === 0 ) {
44+ // this is a top-level cached component,
45+ // exit caching mode.
4246 write . caching = false
43- write . buffer = ''
44- _next ( )
47+ } else {
48+ // parent component is also being cached,
49+ // merge self into parent's result
50+ buffer [ bufferIndex - 1 ] += result
4551 }
52+ buffer . length = bufferIndex
53+ _next ( )
4654 }
4755 }
4856 }
Original file line number Diff line number Diff line change @@ -9,7 +9,7 @@ export function createWriteFunction (
99 let stackDepth = 0
1010 const cachedWrite = ( text , next ) => {
1111 if ( text && cachedWrite . caching ) {
12- cachedWrite . buffer += text
12+ cachedWrite . cacheBuffer [ cachedWrite . cacheBuffer . length - 1 ] += text
1313 }
1414 const waitForNext = write ( text , next )
1515 if ( ! waitForNext ) {
@@ -27,6 +27,6 @@ export function createWriteFunction (
2727 }
2828 }
2929 cachedWrite . caching = false
30- cachedWrite . buffer = ''
30+ cachedWrite . cacheBuffer = [ ]
3131 return cachedWrite
3232}
You can’t perform that action at this time.
0 commit comments