mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 16:15:10 +00:00
LibWeb: Don't invalidate layout when setting .innerHTML on <template>
HTML template elements don't affect rendering, so invalidating the entire document's layout after poking into a <template> was a huge waste of work on template-heavy pages.
This commit is contained in:
parent
ba5e511dc1
commit
64d5d633cf
2 changed files with 10 additions and 6 deletions
|
@ -488,12 +488,6 @@ WebIDL::ExceptionOr<DOM::Element const*> Element::closest(StringView selectors)
|
||||||
WebIDL::ExceptionOr<void> Element::set_inner_html(String const& markup)
|
WebIDL::ExceptionOr<void> Element::set_inner_html(String const& markup)
|
||||||
{
|
{
|
||||||
TRY(DOMParsing::inner_html_setter(*this, markup));
|
TRY(DOMParsing::inner_html_setter(*this, markup));
|
||||||
|
|
||||||
set_needs_style_update(true);
|
|
||||||
|
|
||||||
// NOTE: Since the DOM has changed, we have to rebuild the layout tree.
|
|
||||||
document().invalidate_layout();
|
|
||||||
document().set_needs_layout();
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <LibJS/Heap/Heap.h>
|
#include <LibJS/Heap/Heap.h>
|
||||||
|
#include <LibWeb/DOM/Document.h>
|
||||||
#include <LibWeb/DOM/DocumentFragment.h>
|
#include <LibWeb/DOM/DocumentFragment.h>
|
||||||
#include <LibWeb/DOMParsing/InnerHTML.h>
|
#include <LibWeb/DOMParsing/InnerHTML.h>
|
||||||
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
#include <LibWeb/HTML/Parser/HTMLParser.h>
|
||||||
|
@ -47,6 +48,15 @@ WebIDL::ExceptionOr<void> inner_html_setter(JS::NonnullGCPtr<DOM::Node> context_
|
||||||
// 4. Replace all with fragment within the context object.
|
// 4. Replace all with fragment within the context object.
|
||||||
context_object->replace_all(fragment);
|
context_object->replace_all(fragment);
|
||||||
|
|
||||||
|
// NOTE: We don't invalidate style & layout for <template> elements since they don't affect rendering.
|
||||||
|
if (!is<HTML::HTMLTemplateElement>(*context_object)) {
|
||||||
|
context_object->set_needs_style_update(true);
|
||||||
|
|
||||||
|
// NOTE: Since the DOM has changed, we have to rebuild the layout tree.
|
||||||
|
context_object->document().invalidate_layout();
|
||||||
|
context_object->document().set_needs_layout();
|
||||||
|
}
|
||||||
|
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue