diff --git a/reflex/utils/format.py b/reflex/utils/format.py index 0c92dc738..3eb6ae8d3 100644 --- a/reflex/utils/format.py +++ b/reflex/utils/format.py @@ -473,10 +473,22 @@ def format_dict(prop: ComponentStyle) -> str: # Dump the dict to a string. fprop = json_dumps(prop) + def unescape_double_quotes_in_var(m: re.Match) -> str: + # Since the outer quotes are removed, the inner escaped quotes must be unescaped. + return re.sub('\\\\"', '"', m.group(1)) + # This substitution is necessary to unwrap var values. - fprop = re.sub('"{', "", fprop) - fprop = re.sub('}"', "", fprop) - fprop = re.sub('\\\\"', '"', fprop) + fprop = re.sub( + pattern=r""" + (? Event([E("mock_event", {})], _e)}', @@ -57,6 +66,13 @@ def mock_event(arg): {"a": BaseVar(name='state.colors["val"]', type_="str")}, '{{"a": state.colors["val"]}}', ), + # tricky real-world case from markdown component + ( + { + "h1": f"{{({{node, ...props}}) => }}" + }, + '{{"h1": ({node, ...props}) => }}', + ), ], ) def test_format_prop(prop: Var, formatted: str):