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

This commit is contained in:
Masen Furer 2023-12-21 16:58:45 -07:00 committed by GitHub
parent f75d5f2808
commit 0211e9a0e5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 0 deletions

View File

@ -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:

View File

@ -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]: ...

View File

@ -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()

View File

@ -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.