Skip to content

Commit 7591d1f

Browse files
committed
Update tests per maintaing "key" in vdom attrs
1 parent 35f9e7d commit 7591d1f

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

src/reactpy/_html.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def _fragment(
104104
event_handlers: EventHandlerDict,
105105
) -> VdomDict:
106106
"""An HTML fragment - this element will not appear in the DOM"""
107-
if attributes or event_handlers:
107+
if (attributes and any(a != "key" for a in attributes)) or event_handlers:
108108
msg = "Fragments cannot have attributes besides 'key'"
109109
raise TypeError(msg)
110110
model = VdomDict(tagName="")

src/reactpy/transforms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def infer_key_from_attributes(vdom: VdomDict) -> None:
103103
return
104104

105105
# Infer 'key' from 'attributes.key'
106-
key = attributes.pop("key", None)
106+
key = attributes.get("key", None)
107107

108108
# Infer 'key' from 'attributes.id'
109109
if key is None:

tests/test_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ def test_string_to_reactpy(case):
188188
# 8: Infer ReactJS `key` from the `key` attribute
189189
{
190190
"source": '<div key="my-key"></div>',
191-
"model": {"tagName": "div", "key": "my-key"},
191+
"model": {"tagName": "div", "attributes": {"key": "my-key"}, "key": "my-key"},
192192
},
193193
],
194194
)
@@ -253,7 +253,7 @@ def test_non_html_tag_behavior():
253253
"tagName": "my-tag",
254254
"attributes": {"data-x": "something"},
255255
"children": [
256-
{"tagName": "my-other-tag", "key": "a-key"},
256+
{"tagName": "my-other-tag", "attributes": {"key": "a-key"}, "key": "a-key"},
257257
],
258258
}
259259

0 commit comments

Comments
 (0)