Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/binder/src/Shared/Binder.Loading.spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,27 @@ describe("Binder load abandonment", function()

controller:Destroy()
end)

it("does not construct for an instance destroyed before its added signal runs", function()
local controller = BinderTestUtils.setup()

local strays = 0
local binder = controller.addBinder(function(inst)
if not inst:IsDescendantOf(game) then
strays += 1
end
return {}
end)
controller.initServiceBag()

local inst = controller.newInstance()
binder:Tag(inst)
inst:Destroy()
task.wait()

expect(strays).toEqual(0)
expect(binder:Get(inst)).toBeNil()

controller:Destroy()
end)
end)
5 changes: 4 additions & 1 deletion src/binder/src/Shared/Binder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,10 @@ function Binder.Start<T>(self: Binder<T>)
end

self._maid:GiveTask(CollectionService:GetInstanceAddedSignal(self._tagName):Connect(function(inst)
self:_add(inst)
-- A deferred signal can deliver an instance that was destroyed or removed after it was tagged.
if inst:IsDescendantOf(game) then
self:_add(inst)
end
end))
self._maid:GiveTask(CollectionService:GetInstanceRemovedSignal(self._tagName):Connect(function(inst)
self:_remove(inst)
Expand Down