fix setting ID attribute hiding element

This commit is contained in:
Face
2025-09-10 22:40:21 +03:00
parent 69f758d6e7
commit 48249e1a71
2 changed files with 18 additions and 3 deletions

View File

@@ -374,8 +374,14 @@ func register_dom_node(element: HTMLElement, node) -> void:
node.set_meta("html_element", element)
func update_dom_node_id(element: HTMLElement, new_id: String) -> void:
var old_id = element.get_id()
var temp_key = "_element_" + str(element.get_instance_id())
if parse_result.dom_nodes.has(temp_key):
if not old_id.is_empty() and parse_result.dom_nodes.has(old_id):
var node = parse_result.dom_nodes[old_id]
parse_result.dom_nodes.erase(old_id)
parse_result.dom_nodes[new_id] = node
elif parse_result.dom_nodes.has(temp_key):
var node = parse_result.dom_nodes[temp_key]
parse_result.dom_nodes.erase(temp_key)
parse_result.dom_nodes[new_id] = node

View File

@@ -955,10 +955,19 @@ static func _element_set_attribute_wrapper(vm: LuauVM) -> int:
if attribute_value == "":
element.attributes.erase(attribute_name)
else:
element.set_attribute(attribute_name, attribute_value)
if attribute_name == "id" and attribute_value != element_id:
element.set_attribute(attribute_name, attribute_value)
lua_api.dom_parser.update_dom_node_id(element, attribute_value)
vm.lua_pushstring(attribute_value)
vm.lua_setfield(1, "_element_id")
else:
element.set_attribute(attribute_name, attribute_value)
# Trigger visual update by calling init() again for DOM nodes (must be on main thread)
var dom_node = lua_api.dom_parser.parse_result.dom_nodes.get(element_id, null)
var current_element_id = element.get_id()
var dom_node = lua_api.dom_parser.parse_result.dom_nodes.get(current_element_id, null)
if dom_node and dom_node.has_method("init"):
dom_node.call_deferred("init", element, lua_api.dom_parser)