[FIX] Prevent document desync between VS Code and Code Editor#111
Merged
[FIX] Prevent document desync between VS Code and Code Editor#111
Conversation
- Cancel pending debounced sync and flush ShareDB content to disk before VS Code save to prevent mtime race causing "content is newer" dialog - Wait for pending ops (hasPending) before sending doc:save to server, matching Code Editor behavior and preventing stale content persistence - Track subscriptions only on successful load, clean up on error/destroy, and add resubscribe() for retry support - Add exponential backoff retry for failed document subscriptions instead of setting a terminal error - Check applyEdit return value in reconciliation: on failure, replace VS Code buffer from ShareDB state instead of pushing wrong state
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What's Changed
Fixes document state desync when editing the same file in both VS Code and PlayCanvas Code Editor simultaneously. Three root causes addressed:
1. Save conflict — "content is newer" dialog
document.save()to prevent mtime racedoc.hasPending()to clear before sendingdoc:save:to server, matching Code Editor behavior (save.ts:144-150). Includes re-check after listener registration to prevent TOCTOU race.2. Failed subscription cleanup and retry
subscriptions.set()intoloadhandler). Clean up and destroy doc on error.resubscribe()method for retry support_retryDocSubscription()with exponential backoff (1s, 2s, 4s, max 3 retries) replacing terminalerror.set()callsunlink()and duplicate retry timers for the same document3. Reconciliation robustness
applyEdit()return value: if edit was rejected, replace VS Code buffer from ShareDB state instead of pushing wrong state upstreamapplyEditalso failsFiles Changed
src/disk.tssrc/project-manager.tssrc/connections/sharedb.tsTesting
npm run lint— pass (prettier + eslint)npm run compile— pass (TypeScript)npm run pretest— pass (test compilation)