Skip to content

Commit

Permalink
Fixed stabilize reset function.
Browse files Browse the repository at this point in the history
  • Loading branch information
5cript committed May 30, 2023
1 parent 0f967e0 commit a840a59
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions nui/include/nui/frontend/utility/stabilize.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace Nui

private:
std::shared_ptr<Dom::Element> stableElement_;
bool reset_;
};

/**
Expand Down
5 changes: 3 additions & 2 deletions nui/src/nui/frontend/utility/stabilize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Dom::Element> {
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);
Expand Down
2 changes: 2 additions & 0 deletions nui/test/nui/test_render.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<long long>(), 1);

toggle = true;
globalEventContext.executeActiveEventsImmediately();
Expand Down

0 comments on commit a840a59

Please sign in to comment.