Skip to content

Wiki本文の意図しない複製を防ぐ - #12

Open
NishikawaKoharu wants to merge 1 commit into
RCOSDP:developfrom
NishikawaKoharu:feature/wiki-prevent-duplicate-content-milkdown
Open

Wiki本文の意図しない複製を防ぐ#12
NishikawaKoharu wants to merge 1 commit into
RCOSDP:developfrom
NishikawaKoharu:feature/wiki-prevent-duplicate-content-milkdown

Conversation

@NishikawaKoharu

Copy link
Copy Markdown
Contributor

Purpose

Fix unintended duplication of Wiki page content in the Milkdown collaborative editor.

Stale local IndexedDB operations could be merged with the live Yjs document after y-websocket sync—for example, when a tab is closed without saving, the collaborative server state later becomes empty, and the user re-enters Edit while stale IndexedDB data still exists. This caused the same content to appear multiple times in the editor.

This PR connects IndexedDB persistence only after WebSocket sync and clears stale local IndexedDB data when the remote collaborative document already has content, preventing duplicate merges.

Changes

  • Add attachIndexeddbForSession: attach IndexedDB only after y-websocket sync; clear stale local IndexedDB ops when remote content already exists.
  • Add helpers: isCollabXmlFragmentEmpty, waitForIndexeddbSynced.
  • Update connectCollab: determine whether the remote document has content before attaching IndexedDB, instead of connecting IndexedDB immediately on editor creation.
  • Add typing assist (armEditorTypingAssist / disarmEditorTypingAssist): restore editor focus when the user starts typing after entering edit mode.

Changed files: addons/wiki/static/wikiPageMilkdown.js only.

QA Notes

  • Does this change require a data migration? If so, what data will we migrate?
    • No. Frontend-only change.
  • What is the level of risk?
    • Low to medium. Scope is limited to the Wiki Milkdown editor UI.
  • Any permissions code touched?
    • No.
  • Is this an additive or subtractive change, other?
    • Behavioral fix (not a breaking API change).
  • How can QA verify? (Through UI, API, AdminApp or AdminAdminApp?)
    • Through UI — Wiki edit page (Milkdown editor).
  • If verifying through API, what's the new version? Please include the endpoints in PR notes or Dev docs.
    • N/A — no API changes.
  • What features or workflows might this change impact?
    • Wiki edit mode entry / re-entry
    • Edit after closing a tab without saving
    • Re-entering Edit when stale IndexedDB data remains and the collaborative server state is empty
  • How will this impact performance?
    • Minimal. IndexedDB may be cleared once on connect when remote content exists.

Suggested QA scenarios

  1. Single browser — tab close without save

    • Save a Wiki page with a single line of content.
    • Open Edit, do not save, close the browser tab (not the in-page Close button).
    • Reopen the Wiki and enter Edit again.
    • Expected: Content remains a single line; no duplicate lines.
  2. Save and reload

    • Edit, save, reload the page, enter Edit again.
    • Expected: Saved content loads correctly with no duplication.
  3. Typing after entering Edit

    • Enter Edit on an empty or existing page and start typing immediately.
    • Expected: Characters appear in the editor without needing an extra click to focus.
  4. Stale IndexedDB + empty y-websocket (main repro)

    • Save a Wiki page with a single line of content.
    • Browser A: Open Edit, then close the tab with × (not the in-page Close button).
    • Restart y-websocket so the collaborative server state is empty.
    • Browser B: Open Edit on the same Wiki, then close the tab with ×.
    • Browser A: Open Edit again.
    • Expected: Content remains a single line; no duplicate lines.

Documentation

  • No documentation updates required.
  • No API versioning changes.

Side Effects

  • Local IndexedDB cache for a Wiki page may be cleared when reconnecting to a session where the remote collaborative document already has content. This is intentional to prevent stale local ops from merging as duplicate inserts.
  • Requires deploying the rebuilt wiki-edit-page.js bundle for changes to take effect in the main application.

Ticket

https://redmine.devops.rcos.nii.ac.jp/issues/61562

@NishikawaKoharu
NishikawaKoharu requested a review from hide24 August 26, 2026 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant