-
Notifications
You must be signed in to change notification settings - Fork 152
wait for Y.js sync before disconnecting collaborative sessions #3675
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mattConnHarbour
wants to merge
1
commit into
main
Choose a base branch
from
matthew/sd-3396-fix-wait-for-yjs-sync-before-disconnecting-collaborative
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+164
−13
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /** | ||
| * Test script for IT-1142: verify edits persist after close in collab-only mode. | ||
| * | ||
| * Usage: | ||
| * 1. Start y-websocket server: HOST=0.0.0.0 PORT=8082 npx y-websocket | ||
| * 2. Run this script: npx tsx test-close-sync.ts | ||
| */ | ||
|
|
||
| import { SuperDocClient } from '@superdoc-dev/sdk'; | ||
|
|
||
| const COLLAB_URL = 'ws://localhost:8082'; | ||
| const ROOM_ID = `test-close-sync-${Date.now()}`; | ||
|
|
||
| async function main() { | ||
| console.log('=== Test: Close waits for Y.js sync ===\n'); | ||
| console.log(`Room: ${ROOM_ID}`); | ||
| console.log(`Collab URL: ${COLLAB_URL}\n`); | ||
|
|
||
| // --- Session 1: Make an edit and close immediately --- | ||
| console.log('1. Opening first session...'); | ||
| const client1 = new SuperDocClient({ | ||
| startupTimeoutMs: 15_000, | ||
| // Use local dev CLI for testing | ||
| env: { SUPERDOC_CLI_BIN: './dev-cli.sh' }, | ||
| }); | ||
| await client1.connect(); | ||
|
|
||
| const doc1 = await client1.open({ | ||
| collaboration: { | ||
| providerType: 'y-websocket', | ||
| url: COLLAB_URL, | ||
| documentId: ROOM_ID, | ||
| syncTimeoutMs: 10_000, | ||
| }, | ||
| }); | ||
| console.log(` Session opened: ${doc1.sessionId}`); | ||
|
|
||
| // Make an edit using create.paragraph | ||
| const testText = `Edit made at ${new Date().toISOString()}`; | ||
| console.log(`2. Creating paragraph with text: "${testText}"`); | ||
|
|
||
| try { | ||
| const result = await doc1.create.paragraph({ | ||
| text: testText, | ||
| at: { kind: 'documentStart' }, | ||
| }); | ||
| console.log(` Create result: success=${result?.receipt?.success}`); | ||
| } catch (e: any) { | ||
| console.log(` Create failed: ${e.message}`); | ||
| } | ||
|
|
||
| // Test close() WITHOUT discard - this used to throw "no source path" | ||
| console.log('3. Closing with close() (no discard flag)...'); | ||
| try { | ||
| await doc1.close(); // Should work now for collab-only sessions | ||
| console.log(' ✅ close() succeeded!'); | ||
| } catch (e: any) { | ||
| console.log(` ❌ close() failed: ${e.message}`); | ||
| } | ||
| await client1.dispose(); | ||
| console.log(' Client disposed\n'); | ||
|
|
||
| // --- Session 2: Reconnect and verify --- | ||
| console.log('4. Opening second session to verify...'); | ||
| const client2 = new SuperDocClient({ startupTimeoutMs: 15_000 }); | ||
| await client2.connect(); | ||
|
|
||
| const doc2 = await client2.open({ | ||
| collaboration: { | ||
| providerType: 'y-websocket', | ||
| url: COLLAB_URL, | ||
| documentId: ROOM_ID, | ||
| syncTimeoutMs: 10_000, | ||
| }, | ||
| }); | ||
| console.log(` Session opened: ${doc2.sessionId}`); | ||
|
|
||
| // Read the content | ||
| console.log('5. Reading document content...'); | ||
| try { | ||
| const text = await doc2.getText({}); | ||
| console.log(` Text length: ${text?.length ?? 0}`); | ||
| console.log(` Text preview: "${text?.substring(0, 100) ?? '(empty)'}"`); | ||
|
|
||
| if (text?.includes(testText)) { | ||
| console.log('\n✅ SUCCESS: Edit persisted after close!'); | ||
| } else { | ||
| console.log('\n❌ FAILURE: Edit was lost!'); | ||
| console.log(` Expected to find: "${testText}"`); | ||
| } | ||
| } catch (e: any) { | ||
| console.log(` Read failed: ${e.message}`); | ||
| } | ||
|
|
||
| // Cleanup | ||
| await doc2.close({ discard: true }).catch(() => {}); | ||
| await client2.dispose(); | ||
| console.log('\nDone.'); | ||
| } | ||
|
|
||
| main().catch((e) => { | ||
| console.error('Fatal error:', e); | ||
| process.exit(1); | ||
| }); |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing
OpenedDocument.dispose()to optionally return a promise makes collaborative one-shot/session cleanup asynchronous, but most callers still invoke it withoutawait(for examplemutation-orchestrator.tsandsave.tsfinally blocks). In those non-host collaborative commands,openCollaborativeDocument.dispose()now startsruntime.waitForSync()and returns immediately to the CLI, so the process can finish before the Y.js sync completes and before the provider is disconnected; the intended “wait before disconnecting” behavior only works in the session-pool path that was updated.Useful? React with 👍 / 👎.