From 0211e9a0e528da0c1256ede5af0962adda864437 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Thu, 21 Dec 2023 16:58:45 -0700 Subject: [PATCH] Avoid passing props to lists and list items (#2326) --- reflex/components/markdown/markdown.py | 6 +++++ reflex/components/markdown/markdown.pyi | 1 + tests/components/test_component.py | 29 +++++++++++++++++++++++++ tests/test_testing.py | 3 +++ 4 files changed, 39 insertions(+) diff --git a/reflex/components/markdown/markdown.py b/reflex/components/markdown/markdown.py index 271be7ee0..4b9f28f9b 100644 --- a/reflex/components/markdown/markdown.py +++ b/reflex/components/markdown/markdown.py @@ -38,6 +38,8 @@ _REHYPE_KATEX = Var.create_safe("rehypeKatex", _var_is_local=False) _REHYPE_RAW = Var.create_safe("rehypeRaw", _var_is_local=False) _REHYPE_PLUGINS = Var.create_safe([_REHYPE_KATEX, _REHYPE_RAW]) +# These tags do NOT get props passed to them +NO_PROPS_TAGS = ("ul", "ol", "li") # Component Mapping @lru_cache @@ -215,6 +217,10 @@ class Markdown(Component): special_props = {_PROPS} children = [_CHILDREN] + # For certain tags, the props from the markdown renderer are not actually valid for the component. + if tag in NO_PROPS_TAGS: + special_props = set() + # If the children are set as a prop, don't pass them as children. children_prop = props.pop("children", None) if children_prop is not None: diff --git a/reflex/components/markdown/markdown.pyi b/reflex/components/markdown/markdown.pyi index bc5da9d72..1322e7622 100644 --- a/reflex/components/markdown/markdown.pyi +++ b/reflex/components/markdown/markdown.pyi @@ -36,6 +36,7 @@ _REMARK_PLUGINS = Var.create_safe([_REMARK_MATH, _REMARK_GFM]) _REHYPE_KATEX = Var.create_safe("rehypeKatex", _var_is_local=False) _REHYPE_RAW = Var.create_safe("rehypeRaw", _var_is_local=False) _REHYPE_PLUGINS = Var.create_safe([_REHYPE_KATEX, _REHYPE_RAW]) +NO_PROPS_TAGS = ("ul", "ol", "li") @lru_cache def get_base_component_map() -> dict[str, Callable]: ... diff --git a/tests/components/test_component.py b/tests/components/test_component.py index 35deae8fb..679fc8d80 100644 --- a/tests/components/test_component.py +++ b/tests/components/test_component.py @@ -883,3 +883,32 @@ def test_get_vars(component, exp_vars): sorted(exp_vars, key=lambda v: v._var_name), ): assert comp_var.equals(exp_var) + + +def test_instantiate_all_components(): + """Test that all components can be instantiated.""" + # These components all have required arguments and cannot be trivially instantiated. + untested_components = { + "Card", + "Cond", + "DebounceInput", + "Foreach", + "FormControl", + "Html", + "Icon", + "Markdown", + "MultiSelect", + "Option", + "Popover", + "Radio", + "Script", + "Tag", + "Tfoot", + "Thead", + } + for component_name in rx._ALL_COMPONENTS: # type: ignore + if component_name in untested_components: + continue + component = getattr(rx, component_name) + if isinstance(component, type) and issubclass(component, Component): + component.create() diff --git a/tests/test_testing.py b/tests/test_testing.py index 10b3d9663..b438b4fd8 100644 --- a/tests/test_testing.py +++ b/tests/test_testing.py @@ -1,8 +1,11 @@ """Unit tests for the included testing tools.""" +import pytest + from reflex.constants import IS_WINDOWS from reflex.testing import AppHarness +@pytest.mark.skip("Slow test that makes network requests.") def test_app_harness(tmp_path): """Ensure that AppHarness can compile and start an app.