Skip to content

fix: make sheet version restore fully functional#957

Merged
chrischrischris merged 2 commits into
mainfrom
fixrestr
May 22, 2026
Merged

fix: make sheet version restore fully functional#957
chrischrischris merged 2 commits into
mainfrom
fixrestr

Conversation

@kptdobe
Copy link
Copy Markdown
Contributor

@kptdobe kptdobe commented May 22, 2026

Summary

A customer reported that restoring a sheet from version history was completely broken. Three bugs were identified:

  • Crash on second restore click: resetSheets cleared el.className entirely, stripping the da-sheet CSS class. The restore handler queries document.querySelector('.da-sheet') at restore time, so after the first restore the element was unfindable and the second click passed null to initSheet, crashing with TypeError: Cannot read properties of null (reading 'jexcel'). Fix: use el.classList.remove('jexcel_tabs') to only remove the class jspreadsheet uses to detect an already-initialised container, leaving da-sheet intact.

  • Save after restore reverts to original content: The restore handler called staleCheck.markSynced(verReview.data) with jspreadsheet-format data. checkForDrift fetches DA-JSON from the server; the formats never matched, so drift was always detected, onStale({ dirty: false }) silently reloaded the original sheet content and the restore was undone. Fix: replace markSynced(verReview.data) with markEdited(), which preserves the correct server baseline and marks the sheet dirty so any genuine concurrent edit shows a dialog instead of a silent reload.

  • Preview after restore shows pre-restore content: da-sheet-panes.data was never updated during restore, so the Preview pane still showed the original content. Fix: set sheetPanes.data = convertSheets(daTitle.sheet) after reinitialising the spreadsheet.

Test plan

Test url: https://fixrestr--da-live--adobe.aem.live/

  • Open a sheet, view version history, click a version to preview, click Restore — sheet renders the restored content
  • After restore, click Save — sheet saves the restored content (not the original)
  • After restore, click Preview — preview pane shows the restored content
  • Restore a second time from version history — no crash, second restore works correctly
  • Unit tests: npm test passes (3 new tests for the double-restore crash in index.test.js, 2 new tests for the save regression in utils-utils.test.js)

🤖 Generated with Claude Code

Three bugs made it impossible to restore a sheet from version history:

1. `resetSheets` cleared `el.className` (removing `da-sheet`), so the
   second restore's `document.querySelector('.da-sheet')` returned null
   and crashed with "Cannot read properties of null (reading 'jexcel')".
   Fix: remove only the `jexcel_tabs` class — the one jspreadsheet checks
   to decide whether to reuse existing children — instead of wiping all
   classes.

2. The restore handler called `staleCheck.markSynced(verReview.data)`
   with jspreadsheet-format data. `checkForDrift` fetches DA-JSON from
   the server, so these formats never matched, drift was always detected,
   and `onStale({ dirty: false })` silently reloaded the sheet from the
   server — undoing the restore before the user could save.
   Fix: call `staleCheck.markEdited()` instead, preserving the correct
   server-content baseline while marking the sheet dirty so any genuine
   concurrent edit shows a dialog rather than a silent reload.

3. After restore `da-sheet-panes.data` was never updated, so the Preview
   pane still showed the pre-restore content.
   Fix: set `sheetPanes.data = convertSheets(daTitle.sheet)` after
   reinitialising the spreadsheet.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@aem-code-sync
Copy link
Copy Markdown

aem-code-sync Bot commented May 22, 2026

Hello, I'm the AEM Code Sync Bot and I will run some actions to deploy your branch.
In case there are problems, just click the checkbox below to rerun the respective action.

  • Re-sync branch
Commits

Sheet version restore was only updating the local jspreadsheet UI; the
restored content was never POSTed, so a page refresh re-fetched the old
data from the server.

Extract restoreVersion into utils.js and have it call saveSheets after
re-initializing the sheet — that drives the PUT to /source plus preview
sync and staleCheck markSynced. Add unit tests covering both the PUT
and the preview-pane update.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@chrischrischris chrischrischris merged commit c766025 into main May 22, 2026
4 checks passed
@chrischrischris chrischrischris deleted the fixrestr branch May 22, 2026 11:58
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.

2 participants