Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Do not include inline JSON data if the page isn't going to be rehydrated
Browse files Browse the repository at this point in the history
  • Loading branch information
ianb committed Jan 14, 2019
1 parent d33477e commit b2610e2
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion server/src/reactrender.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ exports.render = function(req, res, page) {
const jsonString = JSON.stringify(jsonModel).replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029").replace(/<script/ig, "\\x3cscript").replace(/<\/script/ig, "\\x3c/script");
const pageLocale = req.userLocales && req.userLocales.length > 0 ? req.userLocales[0] : "en-US";
const pageDirection = req.isRtl ? "rtl" : "ltr";
let inlineJson = `<script id="json-data" type="data">${jsonString}</script>`;
if (page.noBrowserJavascript) {
inlineJson = "";
}
let doc = `
<html lang="${pageLocale}" dir="${pageDirection}">
${head}
<body class="app-body">
<div id="react-body-container">${body}</div>
<script id="json-data" type="data">${jsonString}</script>
${inlineJson}
</body></html>
`.trim();
if (!page.noBrowserJavascript) {
Expand Down

0 comments on commit b2610e2

Please # to comment.