fix: make sheet version restore fully functional#957
Merged
Conversation
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>
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
approved these changes
May 22, 2026
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.
Summary
A customer reported that restoring a sheet from version history was completely broken. Three bugs were identified:
Crash on second restore click:
resetSheetsclearedel.classNameentirely, stripping theda-sheetCSS class. The restore handler queriesdocument.querySelector('.da-sheet')at restore time, so after the first restore the element was unfindable and the second click passednulltoinitSheet, crashing withTypeError: Cannot read properties of null (reading 'jexcel'). Fix: useel.classList.remove('jexcel_tabs')to only remove the class jspreadsheet uses to detect an already-initialised container, leavingda-sheetintact.Save after restore reverts to original content: The restore handler called
staleCheck.markSynced(verReview.data)with jspreadsheet-format data.checkForDriftfetches 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: replacemarkSynced(verReview.data)withmarkEdited(), 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.datawas never updated during restore, so the Preview pane still showed the original content. Fix: setsheetPanes.data = convertSheets(daTitle.sheet)after reinitialising the spreadsheet.Test plan
Test url: https://fixrestr--da-live--adobe.aem.live/
npm testpasses (3 new tests for the double-restore crash inindex.test.js, 2 new tests for the save regression inutils-utils.test.js)🤖 Generated with Claude Code