Fix postcommit callbacks being skipped (#1132)

This commit is contained in:
boatbomber
2025-10-14 12:13:59 -07:00
committed by GitHub
parent 441c469966
commit cd78f5c02c
3 changed files with 34 additions and 51 deletions

View File

@@ -1,5 +1,11 @@
# Rojo Changelog # Rojo Changelog
## Unreleased
* Fixed a bug where the last sync timestamp was not updating correctly in the plugin ([#1132])
[#1132]: https://github.com/rojo-rbx/rojo/pull/1132
## 7.6.0 - October 10th, 2025 ## 7.6.0 - October 10th, 2025
* Added flag to `rojo init` to skip initializing a git repository ([#1122]) * Added flag to `rojo init` to skip initializing a git repository ([#1122])
* Added fallback method for when an Instance can't be synced through normal means ([#1030]) * Added fallback method for when an Instance can't be synced through normal means ([#1030])

View File

@@ -602,46 +602,32 @@ function App:startSession()
}) })
end) end)
self.cleanupPostcommit = serveSession:hookPostcommit(function(patch, instanceMap, unappliedPatch) self.cleanupPostcommit = serveSession:hookPostcommit(function(patch, instanceMap, unappliedPatch)
-- Update tree with unapplied metadata local now = DateTime.now().UnixTimestamp
self:setState(function(prevState) self:setState(function(prevState)
local oldPatchData = prevState.patchData
local newPatchData = {
patch = patch,
unapplied = unappliedPatch,
timestamp = now,
}
if PatchSet.isEmpty(patch) then
-- Keep existing patch info, but use new timestamp
newPatchData.patch = oldPatchData.patch
newPatchData.unapplied = oldPatchData.unapplied
elseif now - oldPatchData.timestamp < 2 then
-- Patches that apply in the same second are combined for human clarity
newPatchData.patch = PatchSet.assign(PatchSet.newEmpty(), oldPatchData.patch, patch)
newPatchData.unapplied = PatchSet.assign(PatchSet.newEmpty(), oldPatchData.unapplied, unappliedPatch)
end
return { return {
patchTree = PatchTree.updateMetadata(prevState.patchTree, patch, instanceMap, unappliedPatch), patchTree = PatchTree.updateMetadata(prevState.patchTree, patch, instanceMap, unappliedPatch),
patchData = newPatchData,
} }
end) end)
end) end)
serveSession:hookPostcommit(function(patch, _instanceMap, unapplied)
local now = DateTime.now().UnixTimestamp
local old = self.state.patchData
if PatchSet.isEmpty(patch) then
-- Ignore empty patch, but update timestamp
self:setState({
patchData = {
patch = old.patch,
unapplied = old.unapplied,
timestamp = now,
},
})
return
end
if now - old.timestamp < 2 then
-- Patches that apply in the same second are
-- considered to be part of the same change for human clarity
patch = PatchSet.assign(PatchSet.newEmpty(), old.patch, patch)
unapplied = PatchSet.assign(PatchSet.newEmpty(), old.unapplied, unapplied)
end
self:setState({
patchData = {
patch = patch,
unapplied = unapplied,
timestamp = now,
},
})
end)
serveSession:onStatusChanged(function(status, details) serveSession:onStatusChanged(function(status, details)
if status == ServeSession.Status.Connecting then if status == ServeSession.Status.Connecting then
if self.dismissSyncReminder then if self.dismissSyncReminder then

View File

@@ -349,18 +349,11 @@ function ServeSession:__applyPatch(patch)
error(unappliedPatch) error(unappliedPatch)
end end
if PatchSet.isEmpty(unappliedPatch) then if Settings:get("enableSyncFallback") and not PatchSet.isEmpty(unappliedPatch) then
if historyRecording then -- Some changes did not apply, let's try replacing them instead
ChangeHistoryService:FinishRecording(historyRecording, Enum.FinishRecordingOperation.Commit) local addedIdList = PatchSet.addedIdList(unappliedPatch)
end local updatedIdList = PatchSet.updatedIdList(unappliedPatch)
return
end
local addedIdList = PatchSet.addedIdList(unappliedPatch)
local updatedIdList = PatchSet.updatedIdList(unappliedPatch)
local actualUnappliedPatches = PatchSet.newEmpty()
if Settings:get("enableSyncFallback") then
Log.debug("ServeSession:__replaceInstances(unappliedPatch.added)") Log.debug("ServeSession:__replaceInstances(unappliedPatch.added)")
Timer.start("ServeSession:__replaceInstances(unappliedPatch.added)") Timer.start("ServeSession:__replaceInstances(unappliedPatch.added)")
local addSuccess, unappliedAddedRefs = self:__replaceInstances(addedIdList) local addSuccess, unappliedAddedRefs = self:__replaceInstances(addedIdList)
@@ -371,20 +364,18 @@ function ServeSession:__applyPatch(patch)
local updateSuccess, unappliedUpdateRefs = self:__replaceInstances(updatedIdList) local updateSuccess, unappliedUpdateRefs = self:__replaceInstances(updatedIdList)
Timer.stop() Timer.stop()
-- Update the unapplied patch to reflect which Instances were replaced successfully
if addSuccess then if addSuccess then
table.clear(unappliedPatch.added) table.clear(unappliedPatch.added)
PatchSet.assign(actualUnappliedPatches, unappliedAddedRefs) PatchSet.assign(unappliedPatch, unappliedAddedRefs)
end end
if updateSuccess then if updateSuccess then
table.clear(unappliedPatch.updated) table.clear(unappliedPatch.updated)
PatchSet.assign(actualUnappliedPatches, unappliedUpdateRefs) PatchSet.assign(unappliedPatch, unappliedUpdateRefs)
end end
else
Log.debug("Skipping ServeSession:__replaceInstances because of setting")
end end
PatchSet.assign(actualUnappliedPatches, unappliedPatch)
if not PatchSet.isEmpty(actualUnappliedPatches) then if not PatchSet.isEmpty(unappliedPatch) then
Log.debug( Log.debug(
"Could not apply all changes requested by the Rojo server:\n{}", "Could not apply all changes requested by the Rojo server:\n{}",
PatchSet.humanSummary(self.__instanceMap, unappliedPatch) PatchSet.humanSummary(self.__instanceMap, unappliedPatch)
@@ -396,7 +387,7 @@ function ServeSession:__applyPatch(patch)
-- guaranteed to be called after the commit -- guaranteed to be called after the commit
for _, callback in self.__postcommitCallbacks do for _, callback in self.__postcommitCallbacks do
task.spawn(function() task.spawn(function()
local success, err = pcall(callback, patch, self.__instanceMap, actualUnappliedPatches) local success, err = pcall(callback, patch, self.__instanceMap, unappliedPatch)
if not success then if not success then
Log.warn("Postcommit hook errored: {}", err) Log.warn("Postcommit hook errored: {}", err)
end end