77from datetime import UTC , datetime
88from email .utils import formatdate
99from logging import getLogger
10+ from pathlib import Path
1011from typing import Literal , Unpack , cast , overload
1112
1213from asgi_tools import ResponseHTML
2425 AsgiWebsocketScope ,
2526)
2627from reactpy .executors .pyscript .utils import pyscript_setup_html
27- from reactpy .executors .utils import server_side_component_html , vdom_head_to_html
28+ from reactpy .executors .utils import (
29+ html_noscript_path_to_html ,
30+ server_side_component_html ,
31+ vdom_head_to_html ,
32+ )
2833from reactpy .types import (
2934 PyScriptOptions ,
3035 ReactPyConfig ,
@@ -45,6 +50,7 @@ def __init__(
4550 * ,
4651 http_headers : dict [str , str ] | None = None ,
4752 html_head : VdomDict | None = None ,
53+ html_noscript_path : str | Path | None = None ,
4854 html_lang : str = "en" ,
4955 pyscript_setup : bool = False ,
5056 pyscript_options : PyScriptOptions | None = None ,
@@ -56,6 +62,8 @@ def __init__(
5662 root_component: The root component to render. This app is typically a single page application.
5763 http_headers: Additional headers to include in the HTTP response for the base HTML document.
5864 html_head: Additional head elements to include in the HTML response.
65+ html_noscript_path: Path to an HTML file whose contents are rendered within a
66+ `<noscript>` tag in the HTML body.
5967 html_lang: The language of the HTML document.
6068 pyscript_setup: Whether to automatically load PyScript within your HTML head.
6169 pyscript_options: Options to configure PyScript behavior.
@@ -66,6 +74,7 @@ def __init__(
6674 self .extra_headers = http_headers or {}
6775 self .dispatcher_pattern = re .compile (f"^{ self .dispatcher_path } ?" )
6876 self .html_head = html_head or html .head ()
77+ self .html_noscript_path = html_noscript_path
6978 self .html_lang = html_lang
7079
7180 if pyscript_setup :
@@ -229,11 +238,17 @@ async def __call__(
229238
230239 def render_index_html (self ) -> None :
231240 """Process the index.html and store the results in this class."""
241+ noscript = (
242+ html_noscript_path_to_html (self .parent .html_noscript_path )
243+ if self .parent .html_noscript_path
244+ else ""
245+ )
232246 self ._index_html = (
233247 "<!doctype html>"
234248 f'<html lang="{ self .parent .html_lang } ">'
235249 f"{ vdom_head_to_html (self .parent .html_head )} "
236250 "<body>"
251+ f"{ noscript } "
237252 f"{ server_side_component_html (element_id = 'app' , class_ = '' , component_path = '' )} "
238253 "</body>"
239254 "</html>"
0 commit comments