mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-20 11:36:10 +00:00
LibWeb: Limit usage of getElementById() cache to connected roots
Fixes bug when we always return null from getElementById() on unconnected roots because id to element cache is only maintained for connected roots. Fixes broken Perf-Dashboard suite in Speedometer 3.
This commit is contained in:
parent
3c2a2bb39f
commit
d5edd62e57
Notes:
github-actions[bot]
2025-04-06 02:15:27 +00:00
Author: https://github.com/kalenikaliaksandr Commit: https://github.com/LadybirdBrowser/ladybird/commit/d5edd62e579 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/4247 Reviewed-by: https://github.com/awesomekling ✅
3 changed files with 24 additions and 8 deletions
|
@ -262,14 +262,16 @@ GC::Ref<HTMLCollection> ParentNode::get_elements_by_class_name(StringView class_
|
|||
|
||||
GC::Ptr<Element> ParentNode::get_element_by_id(FlyString const& id) const
|
||||
{
|
||||
// For document and shadow root we have a cache that allows fast lookup.
|
||||
if (is_document()) {
|
||||
auto const& document = static_cast<Document const&>(*this);
|
||||
return document.element_by_id().get(id);
|
||||
}
|
||||
if (is_shadow_root()) {
|
||||
auto const& shadow_root = static_cast<ShadowRoot const&>(*this);
|
||||
return shadow_root.element_by_id().get(id);
|
||||
if (is_connected()) {
|
||||
// For connected document and shadow root we have a cache that allows fast lookup.
|
||||
if (is_document()) {
|
||||
auto const& document = static_cast<Document const&>(*this);
|
||||
return document.element_by_id().get(id);
|
||||
}
|
||||
if (is_shadow_root()) {
|
||||
auto const& shadow_root = static_cast<ShadowRoot const&>(*this);
|
||||
return shadow_root.element_by_id().get(id);
|
||||
}
|
||||
}
|
||||
|
||||
GC::Ptr<Element> found_element;
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
HelloWorld
|
|
@ -0,0 +1,13 @@
|
|||
<!DOCTYPE html>
|
||||
<body></body>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
let host = document.createElement("div");
|
||||
let shadow = host.attachShadow({ mode: "open" });
|
||||
shadow.innerHTML = `<p id="foo">Hello</p><span id="bar">World</span>`;
|
||||
let foo = shadow.getElementById("foo");
|
||||
let bar = shadow.getElementById("bar");
|
||||
println(foo.textContent + bar.textContent);
|
||||
});
|
||||
</script>
|
Loading…
Add table
Reference in a new issue