@@ -55,20 +55,9 @@ export function createHtmlFunction (source, scope, config) {
5555 const soFooterTemplate = createHtmlTemplateFunction ( soFooterSource )
5656 // This function gets registered as reply.html()
5757 return function ( { routes, context, app } ) {
58- // Initialize hydration, which can stay empty if context.serverOnly is true
59- let hydration = ''
6058 // Decide which templating functions to use, with and without hydration
6159 const headTemplate = context . serverOnly ? soHeadTemplate : unHeadTemplate
6260 const footerTemplate = context . serverOnly ? soFooterTemplate : unFooterTemplate
63- // Decide whether or not to include the hydration script
64- if ( ! context . serverOnly ) {
65- hydration = (
66- '<script>\n' +
67- `window.route = ${ devalue ( context . toJSON ( ) ) } \n` +
68- `window.routes = ${ devalue ( routes . toJSON ( ) ) } \n` +
69- '</script>'
70- )
71- }
7261 // Render page-level <head> elements
7362 const head = new Head ( context . head ) . render ( )
7463 const style = (
@@ -86,7 +75,18 @@ export function createHtmlFunction (source, scope, config) {
8675 head,
8776 hydration,
8877 } ) ,
89- footer : footerTemplate ( context ) ,
78+ footer : ( ) => footerTemplate ( {
79+ ...context ,
80+ // Decide whether or not to include the hydration script
81+ ...! context . serverOnly && {
82+ hydration : (
83+ '<script>\n' +
84+ `window.route = ${ devalue ( context . toJSON ( ) ) } \n` +
85+ `window.routes = ${ devalue ( routes . toJSON ( ) ) } \n` +
86+ '</script>'
87+ )
88+ }
89+ } ) ,
9090 } ) )
9191 // Send out header and readable stream with full response
9292 this . type ( 'text/html' )
0 commit comments