This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 141
Further update children re-rentrancy problems. #315
Merged
oltrep
merged 14 commits into
Roblox:master
from
ConorGriffin37:updateChildrenReentrancy2
Aug 11, 2021
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
b60d009
New test for update children re-rentrancy
ConorGriffin37 7bea7bc
Change to old fix
ConorGriffin37 8ba3b45
add new test that wrecks me
ConorGriffin37 cb8657c
Fix for unmount issue
ConorGriffin37 bea79f7
Add some debugging
ConorGriffin37 6ccce30
fix shadowing
ConorGriffin37 5fde639
remove debug code
ConorGriffin37 48982a6
Update src/createReconciler.lua
ConorGriffin37 c0581b8
fix check
ConorGriffin37 0cd6416
Add comment
ConorGriffin37 54ddb63
Add new test for bug
ConorGriffin37 ab2c4a7
remove print
ConorGriffin37 78615fb
more asserts
ConorGriffin37 cb0684c
Increment rotriever.toml
ConorGriffin37 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1025,5 +1025,335 @@ return function() | |
reconciler.unmountVirtualNode(instance) | ||
end) | ||
end) | ||
|
||
it("should not allow re-entrancy in updateChildren even with callbacks", function() | ||
local configValues = { | ||
tempFixUpdateChildrenReEntrancy = true, | ||
} | ||
|
||
GlobalConfig.scoped(configValues, function() | ||
local LowestComponent = Component:extend("LowestComponent") | ||
|
||
function LowestComponent:render() | ||
return createElement("Frame") | ||
end | ||
|
||
function LowestComponent:didMount() | ||
self.props.onDidMountCallback() | ||
end | ||
|
||
local ChildComponent = Component:extend("ChildComponent") | ||
|
||
function ChildComponent:init() | ||
self:setState({ | ||
firstTime = true | ||
}) | ||
end | ||
|
||
local childCoroutine | ||
|
||
function ChildComponent:render() | ||
if self.state.firstTime then | ||
return createElement("Frame") | ||
end | ||
|
||
return createElement(LowestComponent, { | ||
onDidMountCallback = self.props.onDidMountCallback | ||
}) | ||
end | ||
|
||
function ChildComponent:didMount() | ||
childCoroutine = coroutine.create(function() | ||
self:setState({ | ||
firstTime = false | ||
}) | ||
end) | ||
end | ||
|
||
local ParentComponent = Component:extend("ParentComponent") | ||
|
||
local didMountCallbackCalled = 0 | ||
|
||
function ParentComponent:init() | ||
self:setState({ | ||
count = 1 | ||
}) | ||
|
||
self.onDidMountCallback = function() | ||
didMountCallbackCalled = didMountCallbackCalled + 1 | ||
if self.state.count < 5 then | ||
self:setState({ | ||
count = self.state.count + 1, | ||
}) | ||
end | ||
end | ||
end | ||
|
||
function ParentComponent:render() | ||
return createElement("Frame", { | ||
|
||
}, { | ||
ChildComponent = createElement(ChildComponent, { | ||
count = self.state.count, | ||
onDidMountCallback = self.onDidMountCallback, | ||
}) | ||
}) | ||
end | ||
|
||
local parent = Instance.new("ScreenGui") | ||
parent.Parent = game.CoreGui | ||
|
||
local tree = createElement(ParentComponent) | ||
|
||
local hostKey = "Some Key" | ||
local instance = reconciler.mountVirtualNode(tree, parent, hostKey) | ||
|
||
coroutine.resume(childCoroutine) | ||
|
||
expect(#parent:GetChildren()).to.equal(1) | ||
|
||
local frame = parent:GetChildren()[1] | ||
|
||
expect(#frame:GetChildren()).to.equal(1) | ||
|
||
-- In an ideal world, the didMount callback would probably be called only once. Since it is called by two different | ||
-- LowestComponent instantiations 2 is also acceptable though. | ||
expect(didMountCallbackCalled <= 2).to.equal(true) | ||
|
||
reconciler.unmountVirtualNode(instance) | ||
end) | ||
end) | ||
|
||
it("should never call unmount twice when tempFixUpdateChildrenReEntrancy is turned on", function() | ||
local configValues = { | ||
tempFixUpdateChildrenReEntrancy = true, | ||
} | ||
|
||
GlobalConfig.scoped(configValues, function() | ||
local unmountCounts = {} | ||
|
||
local function addUnmount(id) | ||
unmountCounts[id] = unmountCounts[id] + 1 | ||
end | ||
|
||
local function addInit(id) | ||
unmountCounts[id] = 0 | ||
end | ||
|
||
local LowestComponent = Component:extend("LowestComponent") | ||
function LowestComponent:init() | ||
addInit(tostring(self)) | ||
end | ||
|
||
function LowestComponent:render() | ||
return createElement("Frame") | ||
end | ||
|
||
function LowestComponent:didMount() | ||
self.props.onDidMountCallback() | ||
end | ||
|
||
function LowestComponent:willUnmount() | ||
addUnmount(tostring(self)) | ||
end | ||
|
||
local FirstComponent = Component:extend("FirstComponent") | ||
function FirstComponent:init() | ||
addInit(tostring(self)) | ||
end | ||
|
||
function FirstComponent:render() | ||
return createElement("TextLabel") | ||
end | ||
|
||
function FirstComponent:willUnmount() | ||
addUnmount(tostring(self)) | ||
end | ||
|
||
local ChildComponent = Component:extend("ChildComponent") | ||
|
||
function ChildComponent:init() | ||
addInit(tostring(self)) | ||
|
||
self:setState({ | ||
firstTime = true | ||
}) | ||
end | ||
|
||
local childCoroutine | ||
|
||
function ChildComponent:render() | ||
if self.state.firstTime then | ||
return createElement(FirstComponent) | ||
end | ||
|
||
return createElement(LowestComponent, { | ||
onDidMountCallback = self.props.onDidMountCallback | ||
}) | ||
end | ||
|
||
function ChildComponent:didMount() | ||
childCoroutine = coroutine.create(function() | ||
self:setState({ | ||
firstTime = false | ||
}) | ||
end) | ||
end | ||
|
||
function ChildComponent:willUnmount() | ||
addUnmount(tostring(self)) | ||
end | ||
|
||
local ParentComponent = Component:extend("ParentComponent") | ||
|
||
local didMountCallbackCalled = 0 | ||
|
||
function ParentComponent:init() | ||
self:setState({ | ||
count = 1 | ||
}) | ||
|
||
self.onDidMountCallback = function() | ||
didMountCallbackCalled = didMountCallbackCalled + 1 | ||
if self.state.count < 5 then | ||
self:setState({ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thing as above ⬆️ (or below, I don't know how github will order my comments 😄 ) |
||
count = self.state.count + 1, | ||
}) | ||
end | ||
end | ||
end | ||
|
||
function ParentComponent:render() | ||
return createElement("Frame", { | ||
|
||
}, { | ||
ChildComponent = createElement(ChildComponent, { | ||
count = self.state.count, | ||
onDidMountCallback = self.onDidMountCallback, | ||
}) | ||
}) | ||
end | ||
|
||
local parent = Instance.new("ScreenGui") | ||
parent.Parent = game.CoreGui | ||
|
||
local tree = createElement(ParentComponent) | ||
|
||
local hostKey = "Some Key" | ||
local instance = reconciler.mountVirtualNode(tree, parent, hostKey) | ||
|
||
coroutine.resume(childCoroutine) | ||
|
||
expect(#parent:GetChildren()).to.equal(1) | ||
|
||
local frame = parent:GetChildren()[1] | ||
|
||
expect(#frame:GetChildren()).to.equal(1) | ||
|
||
-- In an ideal world, the didMount callback would probably be called only once. Since it is called by two different | ||
-- LowestComponent instantiations 2 is also acceptable though. | ||
expect(didMountCallbackCalled <= 2).to.equal(true) | ||
|
||
reconciler.unmountVirtualNode(instance) | ||
|
||
for _, value in pairs(unmountCounts) do | ||
expect(value).to.equal(1) | ||
end | ||
end) | ||
end) | ||
|
||
it("should never unmount a node unnecesarily in the case of re-rentry", function() | ||
local configValues = { | ||
tempFixUpdateChildrenReEntrancy = true, | ||
} | ||
|
||
GlobalConfig.scoped(configValues, function() | ||
local LowestComponent = Component:extend("LowestComponent") | ||
function LowestComponent:render() | ||
return createElement("Frame") | ||
end | ||
|
||
function LowestComponent:didUpdate(prevProps, prevState) | ||
if prevProps.firstTime and not self.props.firstTime then | ||
self.props.onChangedCallback() | ||
end | ||
end | ||
|
||
local ChildComponent = Component:extend("ChildComponent") | ||
|
||
function ChildComponent:init() | ||
self:setState({ | ||
firstTime = true | ||
}) | ||
end | ||
|
||
local childCoroutine | ||
|
||
function ChildComponent:render() | ||
return createElement(LowestComponent, { | ||
firstTime = self.state.firstTime, | ||
onChangedCallback = self.props.onChangedCallback | ||
}) | ||
end | ||
|
||
function ChildComponent:didMount() | ||
childCoroutine = coroutine.create(function() | ||
self:setState({ | ||
firstTime = false | ||
}) | ||
end) | ||
end | ||
|
||
local ParentComponent = Component:extend("ParentComponent") | ||
|
||
local onChangedCallbackCalled = 0 | ||
|
||
function ParentComponent:init() | ||
self:setState({ | ||
count = 1 | ||
}) | ||
|
||
self.onChangedCallback = function() | ||
onChangedCallbackCalled = onChangedCallbackCalled + 1 | ||
if self.state.count < 5 then | ||
self:setState({ | ||
count = self.state.count + 1, | ||
}) | ||
end | ||
end | ||
end | ||
|
||
function ParentComponent:render() | ||
return createElement("Frame", { | ||
|
||
}, { | ||
ChildComponent = createElement(ChildComponent, { | ||
count = self.state.count, | ||
onChangedCallback = self.onChangedCallback, | ||
}) | ||
}) | ||
end | ||
|
||
local parent = Instance.new("ScreenGui") | ||
parent.Parent = game.CoreGui | ||
|
||
local tree = createElement(ParentComponent) | ||
|
||
local hostKey = "Some Key" | ||
local instance = reconciler.mountVirtualNode(tree, parent, hostKey) | ||
|
||
coroutine.resume(childCoroutine) | ||
|
||
expect(#parent:GetChildren()).to.equal(1) | ||
|
||
local frame = parent:GetChildren()[1] | ||
|
||
expect(#frame:GetChildren()).to.equal(1) | ||
|
||
expect(onChangedCallbackCalled).to.equal(1) | ||
|
||
reconciler.unmountVirtualNode(instance) | ||
end) | ||
end) | ||
end) | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a specific reason why
5
? To me it looks likeonDidMountCallback
should be called only once, soself.state.count
should be1
and then turn into2
. If that is correct then maybe we could add an explicit assertion here that shows that (i.e.expect(self.state.count).to.equal(1)
).There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No specific reason why 5, just want to make sure there isn't a scenario where this test starts looping an unreasonable amount of times. Before the bug fix, onDidMountCallback would actually be called multiple times due to the duplicate components being mounted. I'll add the expect here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, onDidMountCallback is still called twice here. Basically, two different LowestComponent are still mounted so this is actually called twice. The first LowestComponent to be mounted is unmounted to prevent the duplication issue.