Skip to content

fix(indexedDB): close the database when the editor closes - #9630

Merged
mejo- merged 7 commits into
mainfrom
fix/connection_issue
Nov 18, 2026
Merged

mejo- merged 7 commits into
mainfrom
fix/connection_issue

Conversation

@mejo-

@mejo- mejo- commented Nov 18, 2026

Copy link
Copy Markdown
Member

📝 Summary

Every opened document left its IndexedDB connection and awareness interval open after the editor was closed. Navigating between pages piled up dangling connections and timers.

Destroy the ydoc in close(). Its destroy event closes the IndexedDB connection and stops the awareness interval. Skip reading from the database once the ydoc is destroyed.

🏁 Checklist

  • Code is properly formatted (npm run lint / npm run stylelint / composer run cs:check)
  • Sign-off message is added to all commits

🤖 AI (if applicable)

  • The content of this PR was partly or fully generated using AI tools
  • The AI-generated content was reviewed, comprehended and tested by a human

@mejo- mejo- self-assigned this Nov 18, 2026
@github-project-automation github-project-automation Bot moved this to 🧭 Planning evaluation (don't pick) in 📝 Productivity team Nov 18, 2026
@mejo- mejo- moved this from 🧭 Planning evaluation (don't pick) to 🏗️ In progress in 📝 Productivity team Nov 18, 2026
@mejo- mejo- removed the status in 📝 Productivity team Nov 18, 2026
@nextcloud-command nextcloud-command added the AI assisted This PR contains AI-assisted commits label Nov 18, 2026
@mejo- mejo- moved this to 👀 In review in 📝 Productivity team Nov 18, 2026
@codecov

codecov Bot commented Nov 18, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.33333% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/composables/useSaveService.ts 83.33% 1 Missing ⚠️
src/services/SyncService.ts 90.90% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Comment thread src/components/CollaborativeEditor.vue Resolved
Comment thread src/components/CollaborativeEditor.vue Resolved
Comment thread src/components/CollaborativeEditor.vue Resolved
Comment thread src/components/CollaborativeEditor.vue Resolved
Comment thread src/components/CollaborativeEditor.vue Resolved
Comment thread src/components/CollaborativeEditor.vue Resolved
Comment thread src/composables/useIndexedDbProvider.ts Resolved
Comment thread src/components/CollaborativeEditor.vue Resolved
Comment thread src/composables/useIndexedDbProvider.ts Resolved
Comment thread src/composables/useIndexedDbProvider.ts Resolved
Comment thread src/components/CollaborativeEditor.vue Resolved
@mejo-
mejo- force-pushed the fix/connection_issue branch from 0758160 to 3045242 Compare November 18, 2026 12:55
@mejo-

mejo- commented Nov 18, 2026

Copy link
Copy Markdown
Member Author

/backport to stable35

A typo set `hasConnectionIssues` instead of `hasConnectionIssue`. After a
connection issue, a push rejected with 403 kept showing "The document
could not be loaded" instead of "You've been disconnected from the
server".

With the flag cleared, the connection issue watcher made the editor
editable again 200 ms later, although the rejected session had switched
it to read-only. The watcher now only re-enables editing in edit mode.
This also keeps documents that were opened read-only from becoming
editable after a connection issue.

A sync answered after the rejection could set the connection issue flag
again and bring back the old message. The status card now shows the
disconnected state first.

Signed-off-by: Jonas <jonas@freesources.org>
Assisted-by: ClaudeCode:claude-opus-5-5
Every opened document left its IndexedDB connection and awareness
interval open after the editor was closed. Navigating between pages
piled up dangling connections and timers.

Destroy the ydoc in `close()`. Its destroy event closes the IndexedDB
connection and stops the awareness interval. Skip reading from the
database once the ydoc is destroyed.

Signed-off-by: Jonas <jonas@freesources.org>
Assisted-by: ClaudeCode:claude-opus-5-5
…cting

When coming back online, the sync response retried the push while the
save was still pushing the same steps. The server stored them twice, so
the save only covered the first copy. The autosave scheduled for the
second one was then cancelled when the save finished, leaving the
document at "Unsaved changes".

- SyncService: sendStepsNow joins a push in flight instead of sending
  the outbox again. sendRemainingSteps waits for it and pushes any steps
  that remain, so saving and closing still send everything.
- SaveService: clear the pending autosave before emitting the save
  event, and only when the save succeeded.
- useSaveService: after a save, schedule an autosave if newer changes
  were pushed in the meantime.

Fixes the flaky autosave e2e test "saves after being disconnected for
2 minutes".

Signed-off-by: Jonas <jonas@freesources.org>
Assisted-by: ClaudeCode:claude-opus-5-5
Destroying the sync provider on close sends a last awareness step after
the connection was already cleared. It started the 200 ms send interval,
which only stopped after a push, so every closed editor left an interval
running that kept the sync service reachable. The interval now stops
once there is no connection; the next step after reconnecting starts a
new one.

The beforeunload listener stayed registered if the editor was closed
with unsaved changes, because only the dirty watcher removed it and
watchers no longer run after unmounting.

Signed-off-by: Jonas <jonas@freesources.org>
Assisted-by: ClaudeCode:claude-opus-5-5
…stener

Yjs sets `Doc.isDestroyed` before it emits `destroy`, so the composable
no longer tracks the destroyed ydoc in its own flag. The local flag now
only records that the data was cleared, which also closes the database
while the ydoc stays alive.

The early return in `whenSynced` could not run: y-indexeddb never emits
`synced` once it is destroyed, so `whenSynced` does not settle for a
ydoc destroyed before the initial load.

Signed-off-by: Jonas <jonas@freesources.org>
Assisted-by: ClaudeCode:claude-opus-5-5
Saving pushes the local changes first. If the server rejects that push,
the session is invalidated and the connection cleared, but the save went
ahead with it and failed with "Cannot read properties of undefined
(reading 'shareToken')". Check the connection after pushing instead.

Signed-off-by: Jonas <jonas@freesources.org>
Assisted-by: ClaudeCode:claude-opus-5-5
The status cards for connection issues, a rejected session or a
conflict are added and removed as the state changes and use
role="note", so screen readers did not announce them. The always
rendered status wrapper is now a polite live region.

Signed-off-by: Jonas <jonas@freesources.org>
Assisted-by: ClaudeCode:claude-opus-5-5
@mejo-
mejo- force-pushed the fix/connection_issue branch from 3045242 to 40d6400 Compare November 18, 2026 13:40
@mejo-
mejo- merged commit ed19a2d into main Nov 18, 2026
88 of 92 checks passed
@mejo-
mejo- deleted the fix/connection_issue branch November 18, 2026 15:11
@github-project-automation github-project-automation Bot moved this from 👀 In review to ☑️ Done in 📝 Productivity team Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review AI assisted This PR contains AI-assisted commits bug Something isn't working feature: offline support

Projects

Status: ☑️ Done

Development

Successfully merging this pull request may close these issues.

4 participants