diff --git a/nui/include/nui/frontend/utility/stabilize.hpp b/nui/include/nui/frontend/utility/stabilize.hpp index def2fe0..a0898f2 100644 --- a/nui/include/nui/frontend/utility/stabilize.hpp +++ b/nui/include/nui/frontend/utility/stabilize.hpp @@ -22,6 +22,7 @@ namespace Nui private: std::shared_ptr stableElement_; + bool reset_; }; /** diff --git a/nui/src/nui/frontend/utility/stabilize.cpp b/nui/src/nui/frontend/utility/stabilize.cpp index 5098a80..07e76be 100644 --- a/nui/src/nui/frontend/utility/stabilize.cpp +++ b/nui/src/nui/frontend/utility/stabilize.cpp @@ -7,15 +7,16 @@ namespace Nui { void StableElement::reset() { - stableElement_ = {}; + reset_ = true; } ElementRenderer stabilize(StableElement& stableElement, ElementRenderer const& encapsulatedRenderer) { return [encapsulatedRenderer, &stableElement](Dom::Element& actualParent, Renderer const& gen) -> std::shared_ptr { - if (!stableElement.stableElement_) + if (stableElement.reset_ || !stableElement.stableElement_) { + stableElement.reset_ = false; // Needs to be valid element for replace and fragments: stableElement.stableElement_ = Dom::Element::makeElement(HtmlElement{"div"}); stableElement.stableElement_->replaceElement(encapsulatedRenderer); diff --git a/nui/test/nui/test_render.hpp b/nui/test/nui/test_render.hpp index 2029012..3e9c8ad 100644 --- a/nui/test/nui/test_render.hpp +++ b/nui/test/nui/test_render.hpp @@ -506,6 +506,8 @@ namespace Nui::Tests globalEventContext.executeActiveEventsImmediately(); stable.reset(); + // Is not deleted immediately! + ASSERT_EQ(Nui::val::global("document")["body"]["children"]["length"].as(), 1); toggle = true; globalEventContext.executeActiveEventsImmediately();