Skip to content

1137: Fix extraction editor unsaved-changes detection - #1141

Open
katsiarynaby wants to merge 2 commits into
epam:mainfrom
katsiarynaby:1137-fix-unsaved-message-banner-after-manually-revert-text-to-the-original-value
Open

1137: Fix extraction editor unsaved-changes detection#1141
katsiarynaby wants to merge 2 commits into
epam:mainfrom
katsiarynaby:1137-fix-unsaved-message-banner-after-manually-revert-text-to-the-original-value

Conversation

@katsiarynaby

Copy link
Copy Markdown
Collaborator

Summary

  • Fix incorrect "You have unsaved changes" banner when text is reverted, blocks are created then deleted, or edits survive a create/delete cycle
  • Compare editor HTML against saved extraction (savedEditorPages) separately from the session baseline (baselinePagesRef), which can drift after block create/delete
  • Extend splitHtmlByPage and add editorPageContentMatchesSaved so Tiptap markup and saved hOCR blocks compare correctly
  • Refactor useExtractionState helpers for clarity (session vs saved comparison, pending reconciliation pipeline)

Problem

hasChanges could be wrong in several manual flows:

Flow Expected Before
Edit text → revert to original Banner clears Sometimes stayed
Create block → delete block Banner clears OK
Edit → create → delete Banner stays (text edit remains) Sometimes cleared
Edit → create → delete → revert text Banner clears Sometimes stayed

Root causes:

  • Pending pages were reconciled against a drifted session baseline that already included in-progress edits
  • Saved extraction uses .ocr_carea[id] while the editor uses data-block-id, so comparisons against originalEditorPages often failed

Solution

  • Session baseline — detect edits within the current editor session
  • Saved extraction — decide whether content still differs from the server
  • On content change: align baseline when editor matches saved, clear pending when fully reverted (unless structural edits exist)
  • On deleting the last session-created block: drop pending only when it matches saved content, not the drifted baseline

Test plan

  • npm run test:run -- src/features/workspace/ (153 tests)
  • Edit block text → revert manually → banner clears
  • Create block → delete block → banner clears
  • Edit block 1 → create block 2 → delete block 2 → banner stays
  • Same as above → revert block 1 text → banner clears

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