|
9 | 9 | from lxml import etree |
10 | 10 | from lxml.html import fromstring |
11 | 11 |
|
12 | | -from reactpy import html as _html |
| 12 | +from reactpy import h |
13 | 13 | from reactpy.transforms import RequiredTransforms, attributes_to_reactjs |
14 | 14 | from reactpy.types import Component, VdomDict |
15 | 15 |
|
@@ -105,11 +105,11 @@ def string_to_reactpy( |
105 | 105 | event handler that prevents the browser from navigating to the link. This is |
106 | 106 | useful if you would rather have `reactpy-router` handle your URL navigation. |
107 | 107 | """ |
108 | | - if not html.strip(): |
109 | | - return _html.div() |
110 | 108 | if not isinstance(html, str): |
111 | 109 | msg = f"Expected html to be a string, not {type(html).__name__}" |
112 | 110 | raise TypeError(msg) |
| 111 | + if not html.strip(): |
| 112 | + return h.div() |
113 | 113 | if "<" not in html or ">" not in html: |
114 | 114 | msg = "Expected html string to contain HTML tags, but no tags were found." |
115 | 115 | raise ValueError(msg) |
@@ -158,7 +158,7 @@ def _etree_to_vdom( |
158 | 158 | attributes = attributes_to_reactjs(dict(node.items())) |
159 | 159 |
|
160 | 160 | # Convert the lxml node to a VDOM dict |
161 | | - constructor = getattr(_html, str(node.tag)) |
| 161 | + constructor = getattr(h, str(node.tag)) |
162 | 162 | el = constructor(attributes, children) |
163 | 163 |
|
164 | 164 | # Perform necessary transformations on the VDOM attributes to meet VDOM spec |
@@ -241,13 +241,13 @@ def component_to_vdom(component: Component) -> VdomDict: |
241 | 241 | """Convert the first render of a component into a VDOM dictionary""" |
242 | 242 | result = component.render() |
243 | 243 |
|
| 244 | + if result is None: |
| 245 | + return h.fragment() |
244 | 246 | if isinstance(result, dict): |
245 | 247 | return result |
246 | 248 | if hasattr(result, "render"): |
247 | 249 | return component_to_vdom(cast(Component, result)) |
248 | | - elif isinstance(result, str): |
249 | | - return _html.div(result) |
250 | | - return _html.div() |
| 250 | + return h.div(result) if isinstance(result, str) else h.div() |
251 | 251 |
|
252 | 252 |
|
253 | 253 | def _react_attribute_to_html(key: str, value: Any) -> tuple[str, str]: |
|
0 commit comments