From a68e0ab7c607b44c3988ae7b6949021ad48835a5 Mon Sep 17 00:00:00 2001 From: Joe Date: Sat, 28 Feb 2026 11:22:33 -0600 Subject: [PATCH] Add patch application state management in ServeSession - Introduced a new flag `__applyingPatch` to track the patch application state, preventing `DescendantAdded` events during reconciliation. - Updated the `__applyPatch` method to set and clear the `__applyingPatch` flag appropriately, enhancing control over script updates. - Added checks in the `__connectScriptsOnlyWatchers` method to avoid processing during patch application. These changes aim to improve the reliability of script handling during patch operations and prevent unintended side effects. --- plugin/src/ServeSession.lua | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/plugin/src/ServeSession.lua b/plugin/src/ServeSession.lua index c253849c..47b7d477 100644 --- a/plugin/src/ServeSession.lua +++ b/plugin/src/ServeSession.lua @@ -124,6 +124,7 @@ function ServeSession.new(options) __serverInfo = nil, __confirmingPatch = nil, __isConfirming = false, -- Explicit confirmation state flag for defense-in-depth + __applyingPatch = false, -- Set during reconciler patch application to suppress DescendantAdded __connections = connections, __precommitCallbacks = {}, __postcommitCallbacks = {}, @@ -561,8 +562,10 @@ function ServeSession:__applyPatch(patch) end Timer.stop() + self.__applyingPatch = true local patchApplySuccess, unappliedPatch = pcall(self.__reconciler.applyPatch, self.__reconciler, patch) if not patchApplySuccess then + self.__applyingPatch = false if historyRecording then ChangeHistoryService:FinishRecording(historyRecording, Enum.FinishRecordingOperation.Commit) end @@ -596,6 +599,7 @@ function ServeSession:__applyPatch(patch) PatchSet.assign(unappliedPatch, unappliedUpdateRefs) end end + self.__applyingPatch = false if not PatchSet.isEmpty(unappliedPatch) then Log.info( @@ -939,6 +943,9 @@ function ServeSession:__connectScriptsOnlyWatchers() if self.__changeBatcher:isPaused() then return end + if self.__applyingPatch then + return + end if not descendant:IsA("LuaSourceContainer") then return end