Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
Merge 179f8b9 into cea5057
Browse files Browse the repository at this point in the history
  • Loading branch information
AmaranthineCodices committed May 30, 2019
2 parents cea5057 + 179f8b9 commit 2a7f2b1
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Roact Changelog

## Unreleased

* Fixed an issue where updating a host element with children to an element with `nil` children caused the old children to not be unmounted.

## [1.0.0](https://github.com/Roblox/roact/releases/tag/v1.0.0)
This release significantly reworks Roact internals to enable new features and optimizations.

Expand Down
5 changes: 3 additions & 2 deletions src/RobloxRenderer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,9 @@ function RobloxRenderer.updateHostNode(reconciler, virtualNode, newElement)
end

local children = newElement.props[Children]
if children ~= nil then
reconciler.updateVirtualNodeWithChildren(virtualNode, virtualNode.hostObject, children)

if children ~= nil or oldProps[Children] ~= nil then
reconciler.updateVirtualNodeWithChildren(virtualNode, virtualNode.hostObject, newElement.props[Children])
end

if virtualNode.eventManager ~= nil then
Expand Down
27 changes: 27 additions & 0 deletions src/RobloxRenderer.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,33 @@ return function()
expect(message:find("RobloxRenderer%.spec")).to.be.ok()
end)
end)

it("should delete instances when reconciling to nil children", function()
local parent = Instance.new("Folder")
local key = "Some Key"

local element = createElement("Frame", {
Size = UDim2.new(1, 0, 1, 0),
}, {
child = createElement("Frame"),
})

local node = reconciler.createVirtualNode(element, parent, key)

RobloxRenderer.mountHostNode(reconciler, node)

expect(#parent:GetChildren()).to.equal(1)

local instance = parent:GetChildren()[1]
expect(#instance:GetChildren()).to.equal(1)

local newElement = createElement("Frame", {
Size = UDim2.new(0.5, 0, 0.5, 0),
})

RobloxRenderer.updateHostNode(reconciler, node, newElement)
expect(#instance:GetChildren()).to.equal(0)
end)
end)

describe("unmountHostNode", function()
Expand Down

0 comments on commit 2a7f2b1

Please sign in to comment.