We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
We should use JSON.parse instead of a JS literal for hydration state
See https://v8.dev/blog/cost-of-javascript-2019#json

We're currently doing this...
```
<script>window._react_data = {"locale": "en-US", "stringCatalog": {}, ... </script>
```

We should be doing...
```
<script>window._react_data = JSON.parse('{"locale": "en-US", "stringCatalog": {}, ... ')</script>
```


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `kuma/wiki/templatetags/ssr.py`
Content:
```
1 from __future__ import print_function
2 
3 import json
4 import os
5 
6 import requests
7 import requests.exceptions
8 from django.conf import settings
9 from django.utils import lru_cache
10 from django_jinja import library
11 
12 
13 @lru_cache.lru_cache()
14 def get_localization_data(locale):
15     """
16     Read the frontend string catalog for the specified locale, parse
17     it as JSON, and return the resulting dict. The returned values
18     are cached so that we don't have to read files all the time.
19     """
20     path = os.path.join(settings.BASE_DIR,
21                         'static', 'jsi18n',
22                         locale, 'react.json')
23     with open(path, 'r') as f:
24         return json.load(f)
25 
26 
27 @library.global_function
28 def render_react(component_name, locale, url, document_data, ssr=True):
29     """
30     Render a script tag to define the data and any other HTML tags needed
31     to enable the display of a React-based UI. By default, this does
32     server side rendering, falling back to client-side rendering if
33     the SSR attempt fails. Pass False as the second argument to do
34     client-side rendering unconditionally.
35 
36     Note that we are not defining a generic Jinja template tag here.
37     The code in this file is specific to Kuma's React-based UI.
38     """
39     localization_data = get_localization_data(locale)
40 
41     data = {
42         'locale': locale,
43         'stringCatalog': localization_data['catalog'],
44         'pluralExpression': localization_data['plural'],
45         'url': url,
46         'documentData': document_data,
47     }
48 
49     if ssr:
50         return server_side_render(component_name, data)
51     else:
52         return client_side_render(component_name, data)
53 
54 
55 def _render(component_name, html, state):
56     """A utility function used by both client side and server side rendering.
57     Returns a string that includes the specified HTML and a serialized
58     form of the state dict, in the format expected by the client-side code
59     in kuma/javascript/src/index.jsx.
60     """
61     # We're going to need this below, but we don't want to keep it around
62     pluralExpression = state['pluralExpression']
63     del state['pluralExpression']
64 
65     # Serialize the state object to JSON and be sure the string
66     # "</script>" does not appear in it, since we are going to embed it
67     # within an HTML <script> tag.
68     serializedState = json.dumps(state).replace('</', '<\\/')
69 
70     # In addition to the JSON-serialized data structure, we also want
71     # to pass the pluralForm() function required for the ngettext()
72     # localization function. Functions can't be included in JSON, but
73     # they are part of JavaScript, and our serializedState string is
74     # embedded in an HTML <script> tag, so it can include arbitrary
75     # JavaScript, not just JSON. The reason that we need to do this
76     # is that Django provides us with a JS expression as a string and
77     # we need to convert it into JS code. If we don't do it here with
78     # string manipulation, then we need to use eval() or `new Function()`
79     # on the client-side and that causes a CSP violation.
80     if pluralExpression:
81         # A JavaScript function expression as a Python string
82         js_function_text = (
83             'function(n){{var v=({});return(v===true)?1:((v===false)?0:v);}}'
84             .format(pluralExpression)
85         )
86         # Splice it into the JSON-formatted data string
87         serializedState = (
88             '{pluralFunction:' + js_function_text + ',' + serializedState[1:]
89         )
90 
91     # Now return the HTML and the state as a single string
92     return (
93         u'<div id="react-container" data-component-name="{}">{}</div>\n'
94         u'<script>window._react_data = {};</script>\n'
95     ).format(component_name, html, serializedState)
96 
97 
98 def client_side_render(component_name, data):
99     """
100     Output an empty <div> and a script with complete state so that
101     the UI can be rendered on the client-side.
102     """
103     return _render(component_name, '', data)
104 
105 
106 def server_side_render(component_name, data):
107     """
108     Pre-render the React UI to HTML and output it in a <div>, and then
109     also pass the necessary serialized state in a <script> so that
110     React on the client side can sync itself with the pre-rendred HTML.
111 
112     If any exceptions are thrown during the server-side rendering, we
113     fall back to client-side rendering instead.
114     """
115     url = '{}/{}'.format(settings.SSR_URL, component_name)
116     timeout = settings.SSR_TIMEOUT
117 
118     # Try server side rendering
119     try:
120         # POST the document data as JSON to the SSR server and we
121         # should get HTML text (encoded as plain text) in the body
122         # of the response
123         response = requests.post(url,
124                                  headers={'Content-Type': 'application/json'},
125                                  data=json.dumps(data).encode('utf8'),
126                                  timeout=timeout)
127 
128         # Even though we've got fully rendered HTML now, we still need to
129         # send the document data along with it so that React can sync its
130         # state on the client side with what is in the HTML. When rendering
131         # a document page, the data includes long strings of HTML that
132         # we can get away without duplicating. So as an optimization when
133         # component_name is "document", we're going to make a copy of the
134         # data (because the original belongs to our caller) and delete those
135         # strings from the copy.
136         #
137         # WARNING: This optimization can save 20kb in data transfer
138         # for typical pages, but it requires us to be very careful on
139         # the frontend. If any components render conditionally based on
140         # the state of bodyHTML, tocHTML or quickLinkHTML, then they will
141         # render differently on the client than during SSR, and the hydrate
142         # will not just work cleanly, and those components will re-render
143         # with empty strings. This has already caused Bug 1558308, and
144         # I've commented it out because the benefit in file size doesn't
145         # seem worth the risk of client-side bugs.
146         #
147         # As an alternative, it ought to be possible to extract the HTML
148         # strings from the SSR'ed document and rebuild the document object
149         # on the client right before we call hydrate(). So if you uncomment
150         # the lines below, you should also edit kuma/javascript/src/index.jsx
151         # to extract the HTML from the document as well.
152         #
153         # if component_name == 'document':
154         #     data = data.copy()
155         #     data['documentData'] = data['documentData'].copy()
156         #     data['documentData'].update(bodyHTML='',
157         #                                 tocHTML='',
158         #                                 quickLinksHTML='')
159 
160         return _render(component_name, response.text, data)
161 
162     except requests.exceptions.ConnectionError:
163         print("Connection error contacting SSR server.")
164         print("Falling back to client side rendering.")
165         return client_side_render(component_name, data)
166     except requests.exceptions.ReadTimeout:
167         print("Timeout contacting SSR server.")
168         print("Falling back to client side rendering.")
169         return client_side_render(component_name, data)
170
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/kuma/wiki/templatetags/ssr.py b/kuma/wiki/templatetags/ssr.py
--- a/kuma/wiki/templatetags/ssr.py
+++ b/kuma/wiki/templatetags/ssr.py
@@ -52,47 +52,22 @@
         return client_side_render(component_name, data)
 
 
-def _render(component_name, html, state):
+def _render(component_name, html, script, needs_serialization=False):
     """A utility function used by both client side and server side rendering.
     Returns a string that includes the specified HTML and a serialized
     form of the state dict, in the format expected by the client-side code
     in kuma/javascript/src/index.jsx.
     """
-    # We're going to need this below, but we don't want to keep it around
-    pluralExpression = state['pluralExpression']
-    del state['pluralExpression']
-
-    # Serialize the state object to JSON and be sure the string
-    # "</script>" does not appear in it, since we are going to embed it
-    # within an HTML <script> tag.
-    serializedState = json.dumps(state).replace('</', '<\\/')
-
-    # In addition to the JSON-serialized data structure, we also want
-    # to pass the pluralForm() function required for the ngettext()
-    # localization function. Functions can't be included in JSON, but
-    # they are part of JavaScript, and our serializedState string is
-    # embedded in an HTML <script> tag, so it can include arbitrary
-    # JavaScript, not just JSON. The reason that we need to do this
-    # is that Django provides us with a JS expression as a string and
-    # we need to convert it into JS code. If we don't do it here with
-    # string manipulation, then we need to use eval() or `new Function()`
-    # on the client-side and that causes a CSP violation.
-    if pluralExpression:
-        # A JavaScript function expression as a Python string
-        js_function_text = (
-            'function(n){{var v=({});return(v===true)?1:((v===false)?0:v);}}'
-            .format(pluralExpression)
-        )
-        # Splice it into the JSON-formatted data string
-        serializedState = (
-            '{pluralFunction:' + js_function_text + ',' + serializedState[1:]
-        )
-
-    # Now return the HTML and the state as a single string
+    if needs_serialization:
+        assert isinstance(script, dict), type(script)
+        script = json.dumps(script).replace('</', '<\\/')
+    else:
+        script = u'JSON.parse({})'.format(script)
+
     return (
         u'<div id="react-container" data-component-name="{}">{}</div>\n'
         u'<script>window._react_data = {};</script>\n'
-    ).format(component_name, html, serializedState)
+    ).format(component_name, html, script)
 
 
 def client_side_render(component_name, data):
@@ -100,7 +75,7 @@
     Output an empty <div> and a script with complete state so that
     the UI can be rendered on the client-side.
     """
-    return _render(component_name, '', data)
+    return _render(component_name, '', data, needs_serialization=True)
 
 
 def server_side_render(component_name, data):
@@ -114,7 +89,6 @@
     """
     url = '{}/{}'.format(settings.SSR_URL, component_name)
     timeout = settings.SSR_TIMEOUT
-
     # Try server side rendering
     try:
         # POST the document data as JSON to the SSR server and we
@@ -156,8 +130,8 @@
         #     data['documentData'].update(bodyHTML='',
         #                                 tocHTML='',
         #                                 quickLinksHTML='')
-
-        return _render(component_name, response.text, data)
+        result = response.json()
+        return _render(component_name, result['html'], result['script'])
 
     except requests.exceptions.ConnectionError:
         print("Connection error contacting SSR server.")

{"golden_diff": "diff --git a/kuma/wiki/templatetags/ssr.py b/kuma/wiki/templatetags/ssr.py\n--- a/kuma/wiki/templatetags/ssr.py\n+++ b/kuma/wiki/templatetags/ssr.py\n@@ -52,47 +52,22 @@\n         return client_side_render(component_name, data)\n \n \n-def _render(component_name, html, state):\n+def _render(component_name, html, script, needs_serialization=False):\n     \"\"\"A utility function used by both client side and server side rendering.\n     Returns a string that includes the specified HTML and a serialized\n     form of the state dict, in the format expected by the client-side code\n     in kuma/javascript/src/index.jsx.\n     \"\"\"\n-    # We're going to need this below, but we don't want to keep it around\n-    pluralExpression = state['pluralExpression']\n-    del state['pluralExpression']\n-\n-    # Serialize the state object to JSON and be sure the string\n-    # \"</script>\" does not appear in it, since we are going to embed it\n-    # within an HTML <script> tag.\n-    serializedState = json.dumps(state).replace('</', '<\\\\/')\n-\n-    # In addition to the JSON-serialized data structure, we also want\n-    # to pass the pluralForm() function required for the ngettext()\n-    # localization function. Functions can't be included in JSON, but\n-    # they are part of JavaScript, and our serializedState string is\n-    # embedded in an HTML <script> tag, so it can include arbitrary\n-    # JavaScript, not just JSON. The reason that we need to do this\n-    # is that Django provides us with a JS expression as a string and\n-    # we need to convert it into JS code. If we don't do it here with\n-    # string manipulation, then we need to use eval() or `new Function()`\n-    # on the client-side and that causes a CSP violation.\n-    if pluralExpression:\n-        # A JavaScript function expression as a Python string\n-        js_function_text = (\n-            'function(n){{var v=({});return(v===true)?1:((v===false)?0:v);}}'\n-            .format(pluralExpression)\n-        )\n-        # Splice it into the JSON-formatted data string\n-        serializedState = (\n-            '{pluralFunction:' + js_function_text + ',' + serializedState[1:]\n-        )\n-\n-    # Now return the HTML and the state as a single string\n+    if needs_serialization:\n+        assert isinstance(script, dict), type(script)\n+        script = json.dumps(script).replace('</', '<\\\\/')\n+    else:\n+        script = u'JSON.parse({})'.format(script)\n+\n     return (\n         u'<div id=\"react-container\" data-component-name=\"{}\">{}</div>\\n'\n         u'<script>window._react_data = {};</script>\\n'\n-    ).format(component_name, html, serializedState)\n+    ).format(component_name, html, script)\n \n \n def client_side_render(component_name, data):\n@@ -100,7 +75,7 @@\n     Output an empty <div> and a script with complete state so that\n     the UI can be rendered on the client-side.\n     \"\"\"\n-    return _render(component_name, '', data)\n+    return _render(component_name, '', data, needs_serialization=True)\n \n \n def server_side_render(component_name, data):\n@@ -114,7 +89,6 @@\n     \"\"\"\n     url = '{}/{}'.format(settings.SSR_URL, component_name)\n     timeout = settings.SSR_TIMEOUT\n-\n     # Try server side rendering\n     try:\n         # POST the document data as JSON to the SSR server and we\n@@ -156,8 +130,8 @@\n         #     data['documentData'].update(bodyHTML='',\n         #                                 tocHTML='',\n         #                                 quickLinksHTML='')\n-\n-        return _render(component_name, response.text, data)\n+        result = response.json()\n+        return _render(component_name, result['html'], result['script'])\n \n     except requests.exceptions.ConnectionError:\n         print(\"Connection error contacting SSR server.\")\n", "issue": "We should use JSON.parse instead of a JS literal for hydration state\nSee https://v8.dev/blog/cost-of-javascript-2019#json\r\n\r\nWe're currently doing this...\r\n```\r\n<script>window._react_data = {\"locale\": \"en-US\", \"stringCatalog\": {}, ... </script>\r\n```\r\n\r\nWe should be doing...\r\n```\r\n<script>window._react_data = JSON.parse('{\"locale\": \"en-US\", \"stringCatalog\": {}, ... ')</script>\r\n```\r\n\n", "before_files": [{"content": "from __future__ import print_function\n\nimport json\nimport os\n\nimport requests\nimport requests.exceptions\nfrom django.conf import settings\nfrom django.utils import lru_cache\nfrom django_jinja import library\n\n\n@lru_cache.lru_cache()\ndef get_localization_data(locale):\n    \"\"\"\n    Read the frontend string catalog for the specified locale, parse\n    it as JSON, and return the resulting dict. The returned values\n    are cached so that we don't have to read files all the time.\n    \"\"\"\n    path = os.path.join(settings.BASE_DIR,\n                        'static', 'jsi18n',\n                        locale, 'react.json')\n    with open(path, 'r') as f:\n        return json.load(f)\n\n\n@library.global_function\ndef render_react(component_name, locale, url, document_data, ssr=True):\n    \"\"\"\n    Render a script tag to define the data and any other HTML tags needed\n    to enable the display of a React-based UI. By default, this does\n    server side rendering, falling back to client-side rendering if\n    the SSR attempt fails. Pass False as the second argument to do\n    client-side rendering unconditionally.\n\n    Note that we are not defining a generic Jinja template tag here.\n    The code in this file is specific to Kuma's React-based UI.\n    \"\"\"\n    localization_data = get_localization_data(locale)\n\n    data = {\n        'locale': locale,\n        'stringCatalog': localization_data['catalog'],\n        'pluralExpression': localization_data['plural'],\n        'url': url,\n        'documentData': document_data,\n    }\n\n    if ssr:\n        return server_side_render(component_name, data)\n    else:\n        return client_side_render(component_name, data)\n\n\ndef _render(component_name, html, state):\n    \"\"\"A utility function used by both client side and server side rendering.\n    Returns a string that includes the specified HTML and a serialized\n    form of the state dict, in the format expected by the client-side code\n    in kuma/javascript/src/index.jsx.\n    \"\"\"\n    # We're going to need this below, but we don't want to keep it around\n    pluralExpression = state['pluralExpression']\n    del state['pluralExpression']\n\n    # Serialize the state object to JSON and be sure the string\n    # \"</script>\" does not appear in it, since we are going to embed it\n    # within an HTML <script> tag.\n    serializedState = json.dumps(state).replace('</', '<\\\\/')\n\n    # In addition to the JSON-serialized data structure, we also want\n    # to pass the pluralForm() function required for the ngettext()\n    # localization function. Functions can't be included in JSON, but\n    # they are part of JavaScript, and our serializedState string is\n    # embedded in an HTML <script> tag, so it can include arbitrary\n    # JavaScript, not just JSON. The reason that we need to do this\n    # is that Django provides us with a JS expression as a string and\n    # we need to convert it into JS code. If we don't do it here with\n    # string manipulation, then we need to use eval() or `new Function()`\n    # on the client-side and that causes a CSP violation.\n    if pluralExpression:\n        # A JavaScript function expression as a Python string\n        js_function_text = (\n            'function(n){{var v=({});return(v===true)?1:((v===false)?0:v);}}'\n            .format(pluralExpression)\n        )\n        # Splice it into the JSON-formatted data string\n        serializedState = (\n            '{pluralFunction:' + js_function_text + ',' + serializedState[1:]\n        )\n\n    # Now return the HTML and the state as a single string\n    return (\n        u'<div id=\"react-container\" data-component-name=\"{}\">{}</div>\\n'\n        u'<script>window._react_data = {};</script>\\n'\n    ).format(component_name, html, serializedState)\n\n\ndef client_side_render(component_name, data):\n    \"\"\"\n    Output an empty <div> and a script with complete state so that\n    the UI can be rendered on the client-side.\n    \"\"\"\n    return _render(component_name, '', data)\n\n\ndef server_side_render(component_name, data):\n    \"\"\"\n    Pre-render the React UI to HTML and output it in a <div>, and then\n    also pass the necessary serialized state in a <script> so that\n    React on the client side can sync itself with the pre-rendred HTML.\n\n    If any exceptions are thrown during the server-side rendering, we\n    fall back to client-side rendering instead.\n    \"\"\"\n    url = '{}/{}'.format(settings.SSR_URL, component_name)\n    timeout = settings.SSR_TIMEOUT\n\n    # Try server side rendering\n    try:\n        # POST the document data as JSON to the SSR server and we\n        # should get HTML text (encoded as plain text) in the body\n        # of the response\n        response = requests.post(url,\n                                 headers={'Content-Type': 'application/json'},\n                                 data=json.dumps(data).encode('utf8'),\n                                 timeout=timeout)\n\n        # Even though we've got fully rendered HTML now, we still need to\n        # send the document data along with it so that React can sync its\n        # state on the client side with what is in the HTML. When rendering\n        # a document page, the data includes long strings of HTML that\n        # we can get away without duplicating. So as an optimization when\n        # component_name is \"document\", we're going to make a copy of the\n        # data (because the original belongs to our caller) and delete those\n        # strings from the copy.\n        #\n        # WARNING: This optimization can save 20kb in data transfer\n        # for typical pages, but it requires us to be very careful on\n        # the frontend. If any components render conditionally based on\n        # the state of bodyHTML, tocHTML or quickLinkHTML, then they will\n        # render differently on the client than during SSR, and the hydrate\n        # will not just work cleanly, and those components will re-render\n        # with empty strings. This has already caused Bug 1558308, and\n        # I've commented it out because the benefit in file size doesn't\n        # seem worth the risk of client-side bugs.\n        #\n        # As an alternative, it ought to be possible to extract the HTML\n        # strings from the SSR'ed document and rebuild the document object\n        # on the client right before we call hydrate(). So if you uncomment\n        # the lines below, you should also edit kuma/javascript/src/index.jsx\n        # to extract the HTML from the document as well.\n        #\n        # if component_name == 'document':\n        #     data = data.copy()\n        #     data['documentData'] = data['documentData'].copy()\n        #     data['documentData'].update(bodyHTML='',\n        #                                 tocHTML='',\n        #                                 quickLinksHTML='')\n\n        return _render(component_name, response.text, data)\n\n    except requests.exceptions.ConnectionError:\n        print(\"Connection error contacting SSR server.\")\n        print(\"Falling back to client side rendering.\")\n        return client_side_render(component_name, data)\n    except requests.exceptions.ReadTimeout:\n        print(\"Timeout contacting SSR server.\")\n        print(\"Falling back to client side rendering.\")\n        return client_side_render(component_name, data)\n", "path": "kuma/wiki/templatetags/ssr.py"}], "after_files": [{"content": "from __future__ import print_function\n\nimport json\nimport os\n\nimport requests\nimport requests.exceptions\nfrom django.conf import settings\nfrom django.utils import lru_cache\nfrom django_jinja import library\n\n\n@lru_cache.lru_cache()\ndef get_localization_data(locale):\n    \"\"\"\n    Read the frontend string catalog for the specified locale, parse\n    it as JSON, and return the resulting dict. The returned values\n    are cached so that we don't have to read files all the time.\n    \"\"\"\n    path = os.path.join(settings.BASE_DIR,\n                        'static', 'jsi18n',\n                        locale, 'react.json')\n    with open(path, 'r') as f:\n        return json.load(f)\n\n\n@library.global_function\ndef render_react(component_name, locale, url, document_data, ssr=True):\n    \"\"\"\n    Render a script tag to define the data and any other HTML tags needed\n    to enable the display of a React-based UI. By default, this does\n    server side rendering, falling back to client-side rendering if\n    the SSR attempt fails. Pass False as the second argument to do\n    client-side rendering unconditionally.\n\n    Note that we are not defining a generic Jinja template tag here.\n    The code in this file is specific to Kuma's React-based UI.\n    \"\"\"\n    localization_data = get_localization_data(locale)\n\n    data = {\n        'locale': locale,\n        'stringCatalog': localization_data['catalog'],\n        'pluralExpression': localization_data['plural'],\n        'url': url,\n        'documentData': document_data,\n    }\n\n    if ssr:\n        return server_side_render(component_name, data)\n    else:\n        return client_side_render(component_name, data)\n\n\ndef _render(component_name, html, script, needs_serialization=False):\n    \"\"\"A utility function used by both client side and server side rendering.\n    Returns a string that includes the specified HTML and a serialized\n    form of the state dict, in the format expected by the client-side code\n    in kuma/javascript/src/index.jsx.\n    \"\"\"\n    if needs_serialization:\n        assert isinstance(script, dict), type(script)\n        script = json.dumps(script).replace('</', '<\\\\/')\n    else:\n        script = u'JSON.parse({})'.format(script)\n\n    return (\n        u'<div id=\"react-container\" data-component-name=\"{}\">{}</div>\\n'\n        u'<script>window._react_data = {};</script>\\n'\n    ).format(component_name, html, script)\n\n\ndef client_side_render(component_name, data):\n    \"\"\"\n    Output an empty <div> and a script with complete state so that\n    the UI can be rendered on the client-side.\n    \"\"\"\n    return _render(component_name, '', data, needs_serialization=True)\n\n\ndef server_side_render(component_name, data):\n    \"\"\"\n    Pre-render the React UI to HTML and output it in a <div>, and then\n    also pass the necessary serialized state in a <script> so that\n    React on the client side can sync itself with the pre-rendred HTML.\n\n    If any exceptions are thrown during the server-side rendering, we\n    fall back to client-side rendering instead.\n    \"\"\"\n    url = '{}/{}'.format(settings.SSR_URL, component_name)\n    timeout = settings.SSR_TIMEOUT\n    # Try server side rendering\n    try:\n        # POST the document data as JSON to the SSR server and we\n        # should get HTML text (encoded as plain text) in the body\n        # of the response\n        response = requests.post(url,\n                                 headers={'Content-Type': 'application/json'},\n                                 data=json.dumps(data).encode('utf8'),\n                                 timeout=timeout)\n\n        # Even though we've got fully rendered HTML now, we still need to\n        # send the document data along with it so that React can sync its\n        # state on the client side with what is in the HTML. When rendering\n        # a document page, the data includes long strings of HTML that\n        # we can get away without duplicating. So as an optimization when\n        # component_name is \"document\", we're going to make a copy of the\n        # data (because the original belongs to our caller) and delete those\n        # strings from the copy.\n        #\n        # WARNING: This optimization can save 20kb in data transfer\n        # for typical pages, but it requires us to be very careful on\n        # the frontend. If any components render conditionally based on\n        # the state of bodyHTML, tocHTML or quickLinkHTML, then they will\n        # render differently on the client than during SSR, and the hydrate\n        # will not just work cleanly, and those components will re-render\n        # with empty strings. This has already caused Bug 1558308, and\n        # I've commented it out because the benefit in file size doesn't\n        # seem worth the risk of client-side bugs.\n        #\n        # As an alternative, it ought to be possible to extract the HTML\n        # strings from the SSR'ed document and rebuild the document object\n        # on the client right before we call hydrate(). So if you uncomment\n        # the lines below, you should also edit kuma/javascript/src/index.jsx\n        # to extract the HTML from the document as well.\n        #\n        # if component_name == 'document':\n        #     data = data.copy()\n        #     data['documentData'] = data['documentData'].copy()\n        #     data['documentData'].update(bodyHTML='',\n        #                                 tocHTML='',\n        #                                 quickLinksHTML='')\n        result = response.json()\n        return _render(component_name, result['html'], result['script'])\n\n    except requests.exceptions.ConnectionError:\n        print(\"Connection error contacting SSR server.\")\n        print(\"Falling back to client side rendering.\")\n        return client_side_render(component_name, data)\n    except requests.exceptions.ReadTimeout:\n        print(\"Timeout contacting SSR server.\")\n        print(\"Falling back to client side rendering.\")\n        return client_side_render(component_name, data)\n", "path": "kuma/wiki/templatetags/ssr.py"}]}