@@ -2212,7 +2212,8 @@ var ReactDOMServerRenderer = function () {
2212
2212
restoreProps: Restores actual props to a templatized component
2213
2213
*/
2214
2214
const start = { } ;
2215
- let saveTemplates ;
2215
+ let saveTemplates ;
2216
+ let loadedTemplates ;
2216
2217
const restoreProps = ( template , props , lookup ) => {
2217
2218
return template . replace ( / \{ \{ [ 0 - 9 ] + \} \} / g, match => props [ lookup [ match ] ] ) ;
2218
2219
} ;
@@ -2285,28 +2286,35 @@ var ReactDOMServerRenderer = function () {
2285
2286
// Generate cache key for non-templatized component from its name and props
2286
2287
cacheKey = child . type . name + JSON . stringify ( child . props ) ;
2287
2288
}
2289
+
2290
+ let r ;
2291
+ let restoredTemplate ;
2288
2292
2289
- if ( ! cache . get ( cacheKey ) ) { // Component not found in cache
2290
- let r ;
2291
-
2292
- // If templatized component and template hasn't been generated, render a template
2293
- if ( ! start [ cacheKey ] && isTemplate ) {
2294
- r = this . render ( modifiedChild , frame . context , frame . domNamespace ) ;
2295
- start [ cacheKey ] = { startIndex : out . length , realProps, lookup } ;
2296
- }
2297
- // Otherwise, render with actual props
2298
- else r = this . render ( child , frame . context , frame . domNamespace ) ;
2299
-
2300
- // For simple (non-template) caching, save start index of component in output string
2301
- if ( ! isTemplate ) start [ cacheKey ] = out . length ;
2302
-
2303
- out += r ;
2304
- } else { // Component found in cache
2305
- let r = cache . get ( cacheKey ) ;
2306
- let restoredTemplate ;
2307
- if ( isTemplate ) restoredTemplate = restoreProps ( r , realProps , lookup ) ;
2308
- out += restoredTemplate ? restoredTemplate : r ;
2293
+ if ( loadedTemplates && loadedTemplates [ cacheKey ] ) { // Component found in loaded templates
2294
+ restoredTemplate = restoreProps ( loadedTemplates [ cacheKey ] , realProps , lookup ) ;
2295
+ } else {
2296
+ let reply = cache . get ( cacheKey ) ;
2297
+ if ( ! reply ) { // Component not found in cache
2298
+ // If templatized component and template hasn't been generated, render a template
2299
+ if ( ! start [ cacheKey ] && isTemplate ) {
2300
+ r = this . render ( modifiedChild , frame . context , frame . domNamespace ) ;
2301
+ start [ cacheKey ] = { startIndex : out . length , realProps, lookup } ;
2302
+ }
2303
+ // Otherwise, render with actual props
2304
+ else r = this . render ( child , frame . context , frame . domNamespace ) ;
2305
+
2306
+ // For simple (non-template) caching, save start index of component in output string
2307
+ if ( ! isTemplate ) start [ cacheKey ] = out . length ;
2308
+ } else { // Component found in cache
2309
+ r = reply ;
2310
+ if ( isTemplate ) {
2311
+ restoredTemplate = restoreProps ( r , realProps , lookup ) ;
2312
+ if ( ! loadedTemplates ) loadedTemplates = { } ;
2313
+ if ( ! loadedTemplates [ cacheKey ] ) loadedTemplates [ cacheKey ] = r ;
2314
+ }
2315
+ }
2309
2316
}
2317
+ out += restoredTemplate ? restoredTemplate : r ;
2310
2318
} else {
2311
2319
// Normal rendering for non-cached components
2312
2320
out += this . render ( child , frame . context , frame . domNamespace ) ;
@@ -2356,7 +2364,7 @@ var ReactDOMServerRenderer = function () {
2356
2364
saveTemplates . sort ( ( a , b ) => a . startIndex - b . startIndex ) ;
2357
2365
// Rebuild output string with actual props
2358
2366
saveTemplates . forEach ( savedTemplate => {
2359
- out += outCopy . substring ( bookmark , savedTemplate . startIndex )
2367
+ out += outCopy . substring ( bookmark , savedTemplate . startIndex ) ;
2360
2368
bookmark = savedTemplate . endIndex ;
2361
2369
out += restoreProps ( outCopy . slice ( savedTemplate . startIndex , savedTemplate . endIndex ) ,
2362
2370
savedTemplate . realProps , savedTemplate . lookup ) ;
0 commit comments