瀏覽代碼

Avoid passing props to lists and list items (#2326)

Masen Furer 1 年之前
父節點
當前提交
0211e9a0e5

+ 6 - 0
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:

+ 1 - 0
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]: ...

+ 29 - 0
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()

+ 3 - 0
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.