From ac92c4a49d8cd0b8a4aaf68884f781569d17e2dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carl=20T=C3=B6rnqvist?= Date: Thu, 8 Mar 2018 15:55:32 +0100 Subject: [PATCH] Expose initial state in head --- lib/graph-document.js | 8 ++++++++ test/document.js | 2 ++ 2 files changed, 10 insertions(+) diff --git a/lib/graph-document.js b/lib/graph-document.js index 2a6e5d9f..75a1f1b5 100644 --- a/lib/graph-document.js +++ b/lib/graph-document.js @@ -101,6 +101,7 @@ function node (state, createEdge) { var d = documentify(filename, html) var header = [ viewportTag(), + content.state && initialState(content.state), scriptTag({ hash: state.scripts.bundle.hash, base: base }), hasDynamicScripts && dynamicScriptsTag({ bundleNames: state.scripts.bundle.dynamicBundles, @@ -157,6 +158,13 @@ function preloadTag () { return `` } +function initialState (state) { + var json = JSON.stringify(state) + .replace(/\u2028/g, '\\u2028') + .replace(/\u2029/g, '\\u2029') + return `` +} + function scriptTag (opts) { var hex = opts.hash.toString('hex').slice(0, 16) var base64 = 'sha512-' + opts.hash.toString('base64') diff --git a/test/document.js b/test/document.js index 21bf17eb..ec41ad60 100644 --- a/test/document.js +++ b/test/document.js @@ -81,6 +81,7 @@ tape('server render choo apps', function (assert) { + @@ -151,6 +152,7 @@ tape('server render choo apps with root set', function (assert) { +