File tree Expand file tree Collapse file tree 2 files changed +14
-3
lines changed
Expand file tree Collapse file tree 2 files changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -98,12 +98,18 @@ def input_element_value_prop_to_defaultValue(vdom: VdomDict) -> None:
9898 def infer_key_from_attributes (vdom : VdomDict ) -> None :
9999 """Infer the ReactJS `key` by looking at any attributes that should be unique."""
100100 attributes = vdom .get ("attributes" , {})
101+ if not attributes :
102+ return
103+
104+ # Infer 'key' from 'attributes.key'
105+ key = attributes .pop ("key" , None )
101106
102- # Infer 'key' from 'id'
107+ # Infer 'key' from 'attributes.id'
108+ if key is None :
103109 key = attributes .get ("id" )
104110
105- # Fallback: Infer 'key' from 'name'
106- if not key and vdom ["tagName" ] in {"input" , "select" , "textarea" }:
111+ # Infer 'key' from 'attributes. name'
112+ if key is None and vdom ["tagName" ] in {"input" , "select" , "textarea" }:
107113 key = attributes .get ("name" )
108114
109115 if key :
Original file line number Diff line number Diff line change @@ -185,6 +185,11 @@ def test_html_to_vdom(case):
185185 "attributes" : {"type" : "text" , "name" : "my-input" },
186186 },
187187 },
188+ # 8: Infer ReactJS `key` from the `key` attribute
189+ {
190+ "source" : '<div key="my-key"></div>' ,
191+ "model" : {"tagName" : "div" , "key" : "my-key" },
192+ },
188193 ],
189194)
190195def test_html_to_vdom_default_transforms (case ):
You can’t perform that action at this time.
0 commit comments