mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-23 22:11:38 +00:00
Refactor Reconciler tests and update path handling logic
- Updated test descriptions in `diff.spec.lua` and `diff.stress.spec.lua` to reflect changes in behavior regarding duplicate-named children in both real and virtual DOM contexts. - Adjusted assertions to ensure that duplicate-named children are correctly removed or added based on the new matching logic. - Refactored `hydrate.lua` and `matching.lua` to streamline the matching process by removing unnecessary parameters, enhancing clarity and maintainability. - Updated metadata references in various test files to include the `.model.json5` extension for consistency in path handling. These changes improve the accuracy of reconciliation tests and enhance the overall robustness of the Reconciler's path handling logic.
This commit is contained in:
parent
3ad3c21c01
commit
bb9d241253
18 changed files with 129 additions and 94 deletions
|
|
@ -276,7 +276,7 @@ return function()
|
|||
end)
|
||||
|
||||
describe("duplicate-named siblings", function()
|
||||
it("should skip real DOM children with duplicate names", function()
|
||||
it("should remove real DOM children with duplicate names when not in virtual DOM", function()
|
||||
local knownInstances = InstanceMap.new()
|
||||
local virtualInstances = {
|
||||
ROOT = {
|
||||
|
|
@ -305,11 +305,11 @@ return function()
|
|||
|
||||
assert(ok, tostring(patch))
|
||||
|
||||
-- Duplicate-named children should be skipped (not removed)
|
||||
assert(isEmpty(patch.removed))
|
||||
-- Duplicate-named children should be removed (matching handles pairing)
|
||||
expect(#patch.removed).to.equal(2)
|
||||
end)
|
||||
|
||||
it("should skip virtual children with duplicate names among siblings", function()
|
||||
it("should add virtual children with duplicate names among siblings", function()
|
||||
local knownInstances = InstanceMap.new()
|
||||
local virtualInstances = {
|
||||
ROOT = {
|
||||
|
|
@ -340,8 +340,8 @@ return function()
|
|||
|
||||
assert(ok, tostring(patch))
|
||||
|
||||
-- Duplicate-named virtual children should not be added
|
||||
assert(isEmpty(patch.added))
|
||||
-- Duplicate-named virtual children should be added (matching handles pairing)
|
||||
expect(size(patch.added)).to.equal(2)
|
||||
end)
|
||||
end)
|
||||
|
||||
|
|
|
|||
|
|
@ -239,9 +239,8 @@ return function()
|
|||
local ok, patch = diff(instanceMap, virtualInstances, rootId)
|
||||
|
||||
expect(ok).to.equal(true)
|
||||
-- Duplicates should NOT be marked for removal
|
||||
-- Only if they had unique names would they be candidates
|
||||
expect(#patch.removed).to.equal(0)
|
||||
-- Duplicates should be marked for removal (matching handles pairing)
|
||||
expect(#patch.removed).to.equal(2)
|
||||
|
||||
instanceMap:stop()
|
||||
end)
|
||||
|
|
@ -290,9 +289,9 @@ return function()
|
|||
local ok, patch = diff(instanceMap, virtualInstances, rootId)
|
||||
|
||||
expect(ok).to.equal(true)
|
||||
-- Neither duplicate should be added since the path is ambiguous
|
||||
expect(patch.added[dup1Id]).to.equal(nil)
|
||||
expect(patch.added[dup2Id]).to.equal(nil)
|
||||
-- Both duplicates should be added (matching handles pairing)
|
||||
expect(patch.added[dup1Id]).to.be.ok()
|
||||
expect(patch.added[dup2Id]).to.be.ok()
|
||||
|
||||
instanceMap:stop()
|
||||
end)
|
||||
|
|
@ -350,8 +349,8 @@ return function()
|
|||
local ok, patch = diff(instanceMap, virtualInstances, rootId)
|
||||
|
||||
expect(ok).to.equal(true)
|
||||
-- Grandchild should also NOT be added since its parent is ambiguous
|
||||
expect(patch.added[grandchildId]).to.equal(nil)
|
||||
-- Grandchild should be added along with its parent (matching handles pairing)
|
||||
expect(patch.added[grandchildId]).to.be.ok()
|
||||
|
||||
instanceMap:stop()
|
||||
end)
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ local function hydrate(instanceMap, virtualInstances, rootId, rootInstance)
|
|||
end
|
||||
|
||||
-- Use the 3-pass matching algorithm to pair virtual ↔ studio children
|
||||
local result = Matching.matchChildren(validVirtualIds, existingChildren, virtualInstances, instanceMap)
|
||||
local result = Matching.matchChildren(validVirtualIds, existingChildren, virtualInstances)
|
||||
|
||||
-- Recursively hydrate matched pairs
|
||||
for _, pair in result.matched do
|
||||
|
|
|
|||
|
|
@ -114,8 +114,7 @@ local Matching = {}
|
|||
function Matching.matchChildren(
|
||||
virtualChildren: { string },
|
||||
studioChildren: { Instance },
|
||||
virtualInstances: { [string]: any },
|
||||
instanceMap: any
|
||||
virtualInstances: { [string]: any }
|
||||
)
|
||||
local matched: { { virtualId: string, studioInstance: Instance } } = {}
|
||||
local remainingVirtual: { string } = table.clone(virtualChildren)
|
||||
|
|
@ -344,7 +343,7 @@ function Matching._computeChangeCount(
|
|||
end
|
||||
|
||||
-- Recursive: match children and sum costs
|
||||
local childResult = Matching.matchChildren(validVChildren, studioKids, virtualInstances, nil)
|
||||
local childResult = Matching.matchChildren(validVChildren, studioKids, virtualInstances)
|
||||
|
||||
-- Matched children: recursively score each pair
|
||||
for _, pair in childResult.matched do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue