refactor(web): extract contentSaver + shared progress-merge from monoliths (TASK-2029)#885
Merged
Merged
Conversation
…/collection monoliths (TASK-2029)
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.
TASK-2029 (PLAN-1984 Web-UX audit)
Behavior-preserving refactor. Pulls two tangled clusters out of the item/collection page monoliths into cohesive, unit-tested modules so future feature work can touch them safely.
A.
contentSaver.svelte.ts— raw-markdown saver (item detail page)New
web/src/lib/items/contentSaver.svelte.ts—createContentSaver({ debounceMs, save })returns a saver owning the 1.2s debounce, thependingdirty tracker (wasrawPendingMarkdown), andflushNow({ keepalive })/queue/cancel/clearPending/dirty. The actual PATCH + all reactiveitem/saveStatus/editorStorebookkeeping stays in the page as the injectedsavecallback, so the module has no Svelte/API deps and is testable in plain node.Rewired in
[collection]/[slug]/+page.svelte:handleRawContentUpdate→rawContentSaver.queue(markdown)beforeunloadkeepalive block (BUG-2024) →rawContentSaver.flushNow({ keepalive: true })— keepalive-on-unload, debounce-cancel, dirty prompt, and clear-on-save all preserved; collab flush still fires first.flushRawIfPendingdrain loop → usessaver.pending/saver.cancel()/saver.clearPending()(its own awaited PATCH loop unchanged).handleContentUpdatepath cancel the saver too, preserving the shared-timer mode-toggle non-trample.pendingis a plain closure var (not$state) per CONVE-1688 — the reactive dirty flag stays ineditorStore.B.
progressMerge.ts— deduped progress fetch/merge (collection page)New
web/src/lib/collections/progressMerge.ts— pureplansProgressToMap+mergeChildAndCheckboxProgress(BUG-1509 preference logic) plusfetchCollectionProgress(parallel fetch + merge, per-fetch.catch(() => [])). Both duplicated copies in[collection]/+page.svelte(refreshProgressand inline inloadCollection) now call the shared fn; each keeps its own seq-guard / label / error handling so behavior is identical.Tests
contentSaver.test.ts(7, fake timers): debounce coalescing, dirty set/clear, flush-now cancels pending debounce, keepalive flag plumbed, no-save-when-clean, cancel leaves dirty, default debounce.progressMerge.test.ts(8): plans map, all three merge branches, defensive orphan-checkbox, empties.npm run check: 0 errors.npm run build: success. Codex review: CLEAN.Line deltas
[collection]/+page.svelte: 2957 → 2891 (-66)[collection]/[slug]/+page.svelte: 4648 → ~4660 (raw-save mechanics moved to the tested module; the page-coupled PATCH body remains as the injected callback, so net LOC on this file is flat — the win is the extracted, tested primitive + removed unload duplication)Behavior-preserving: no user-visible change to save timing, keepalive-on-unload (BUG-2024), dirty prompt, collab flush order, or progress badges.