refactor(web): extract collab-flush path from item-detail monolith (TASK-2082)#889
Merged
Merged
Conversation
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
Behavior-preserving extraction of the Yjs collaborative-snapshot flush path out of the ~4.6k-line item detail page (
web/src/routes/[username]/[workspace]/[collection]/[slug]/+page.svelte) into a new focused module. Follow-on to TASK-2029 (which extracted the raw-markdowncontentSaver), part of PLAN-1984.Extracted —
web/src/lib/collab/collabFlush.svelte.tsA
createCollabFlusher()factory (mirrorscontentSaver.svelte.ts's pattern). The module owns: the 5s idle debounce timer, the per-itemlastFlushedContentdedupe state, and the two-stage dedupe decision (editor-space short-circuit viashouldDedupeEditorSpace+ storage-spacebaseline/lastFlushedcompare). Public API:schedule(ctx, markdown)— arm the 5s idle flush (wasscheduleCollabFlush)flush(ctx, markdown, keepalive)— run a flush now, returns'flushed'|'deduped'|'failed'|'skipped'(wasrunCollabFlush; called directly by the rich→raw toggle)flushNow(ctx, keepalive)— read live editor markdown + flush (wasflushCollabNow; editor teardown + beforeunload)cancel()/resetDedup()— replace the inlineclearTimeout(collabFlushTimer)/lastFlushedContent = nullsitesDeliberately LEFT in the page (injected as callbacks)
Everything Svelte-reactive / API / editor-coupled the module can't own: the
api.items.flushCollabContentPATCH + all reactive bookkeeping (saveStatus,editorStore, toast,showSaved), the op-log-cursor read + post-awaitforce_refreshcheck (insave), plusisRecovering(forceRefreshInFlight),serialize(markdownToWikiLinks/cleanBrokenLinksagainstlocalIndex),normalize(unescapeDocLinks),readEditorMarkdown,isActiveItem.activeCollabContext/seededProvider/ the collab$effectlifecycle stay in the page — they're deeply coupled to provider construction/teardown.Behavior-preserving
Line-for-line faithful to the original control flow. Verified invariants:
flushNow(ctx, true)still fires ALONGSIDE the BUG-2024 raw-markdown keepalive PATCH (both intact, unchanged ordering).forceRefreshInFlightgating (schedule + pre/post-await),seededProviderseeding,activeCollabContextswitch-on-item-change all unchanged.flushDedupe.tsreused as-is.cancel()+resetDedup()inloadData) — no cross-item bleed.One robustness addition from Codex review: a
resetGenerationguard so an in-flightresetDedup()(item-swap / out-of-band raw save) can't be re-polluted by a stale flush's deferredlastFlushedContentcommit — closes a window theawait config.save()split would otherwise widen, and strengthens the same-item raw-save case that was latently racy in the original.Line-count delta
Item page: 4649 → 4558 lines (−91). Net across files: +625 / −231 (new module + its unit tests).
Tests
New
web/src/lib/collab/collabFlush.test.ts(17 tests, node project): debounce/coalesce, recovery gate, editor-space + storage-space + baseline dedupe,lastFlushedrecording + active-item gate, failed/skipped non-recording,flushNowread/no-op/cancel,resetDedup, and the in-flight-reset invalidation.npm run checkclean (0 errors),npm run buildsucceeds, all 177 node tests pass. Codex review: CLEAN.Refs TASK-2082, PLAN-1984.