Add script deletion logic in diff.lua for improved sync handling

- Introduced a new function, `shouldDeleteChild`, to determine if child instances should be deleted based on their class name, even in scripts-only mode.
- Defined `SCRIPT_CLASS_NAMES` to always allow deletion of Script, LocalScript, and ModuleScript instances.
- Updated existing deletion logic to utilize the new function, ensuring scripts are marked for deletion appropriately in the sync diff.
This commit is contained in:
Joe 2026-01-30 05:30:12 -06:00
parent ec3a6cf6af
commit ace839e46f

View file

@ -151,6 +151,30 @@ local function shouldDeleteUnknownInstances(virtualInstance)
end end
end end
-- Script class names that should always be eligible for deletion,
-- even when the parent has ignoreUnknownInstances: true (scripts-only mode)
local SCRIPT_CLASS_NAMES = {
Script = true,
LocalScript = true,
ModuleScript = true,
}
local function shouldDeleteChild(virtualInstance, childInstance)
-- If the parent allows deleting unknown instances, always allow
if shouldDeleteUnknownInstances(virtualInstance) then
return true
end
-- In scripts-only mode (where parent has ignoreUnknownInstances: true),
-- we still want to allow deletion of scripts. This ensures deleted
-- script files show up in the sync diff.
if SCRIPT_CLASS_NAMES[childInstance.ClassName] then
return true
end
return false
end
local function diff(instanceMap, virtualInstances, rootId) local function diff(instanceMap, virtualInstances, rootId)
local patch = { local patch = {
removed = {}, removed = {},
@ -381,8 +405,9 @@ local function diff(instanceMap, virtualInstances, rootId)
-- This is an existing instance not present in the virtual DOM. -- This is an existing instance not present in the virtual DOM.
-- We can mark it for deletion unless the user has asked us not -- We can mark it for deletion unless the user has asked us not
-- to delete unknown stuff. -- to delete unknown stuff. Scripts are always eligible for deletion
if shouldDeleteUnknownInstances(virtualInstance) then -- even in scripts-only mode (where ignoreUnknownInstances is true).
if shouldDeleteChild(virtualInstance, childInstance) then
table.insert(patch.removed, childInstance) table.insert(patch.removed, childInstance)
end end
else else