Skip to content

Commit

Permalink
[FIX] sheet view: DELETE_SHEET in initial revisions
Browse files Browse the repository at this point in the history
If a revision contains a `UPDATE_CELL`, the sheet is added to the
`sheetsWithDirtyViewports` set. But the sheet isn't when deleting the
sheet. So if the initial revisions a sheet is updated then deleted,
we'll try to update its viewport in the `finalize` and crash.

closes #5357

Task: 4405573
X-original-commit: e2c9c48
Signed-off-by: Pierre Rousseau (pro) <[email protected]>
Signed-off-by: Adrien Minne (adrm) <[email protected]>
  • Loading branch information
hokolomopo committed Dec 17, 2024
1 parent 1dab702 commit c8020b7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/plugins/ui_stateful/sheetview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ export class SheetViewPlugin extends UIPlugin {
break;
case "DELETE_SHEET":
this.cleanViewports();
this.sheetsWithDirtyViewports.delete(cmd.sheetId);
break;
case "ACTIVATE_SHEET":
this.sheetsWithDirtyViewports.add(cmd.sheetIdTo);
Expand Down
22 changes: 22 additions & 0 deletions tests/sheet/sheetview_plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import { ComposerStore } from "../../src/components/composer/composer/composer_s
import {
DEFAULT_CELL_HEIGHT,
DEFAULT_CELL_WIDTH,
DEFAULT_REVISION_ID,
MESSAGE_VERSION,
getDefaultSheetViewSize,
} from "../../src/constants";
import { isDefined, numberToLetters, range, toXC, toZone, zoneToXc } from "../../src/helpers";
import { Model } from "../../src/model";
import { SheetViewPlugin } from "../../src/plugins/ui_stateful/sheetview";
import { Zone } from "../../src/types";
import { StateUpdateMessage } from "../../src/types/collaborative/transport_service";
import {
activateSheet,
addColumns,
Expand Down Expand Up @@ -930,6 +933,25 @@ describe("Viewport of Simple sheet", () => {
height: 4.5 * DEFAULT_CELL_HEIGHT,
});
});

test("Loading a model with initial revisions in sheet that is deleted doesn't crash", () => {
const initialMessages: StateUpdateMessage[] = [
{
type: "REMOTE_REVISION",
serverRevisionId: DEFAULT_REVISION_ID,
nextRevisionId: "1",
version: MESSAGE_VERSION,
clientId: "bob",
commands: [
{ type: "CREATE_SHEET", position: 1, sheetId: "newSheetId" },
{ type: "UPDATE_CELL", sheetId: "newSheetId", col: 0, row: 0, content: "1" },
{ type: "DELETE_SHEET", sheetId: "newSheetId" },
],
},
];

expect(() => new Model({}, {}, initialMessages)).not.toThrow();
});
});

describe("Multi Panes viewport", () => {
Expand Down

0 comments on commit c8020b7

Please sign in to comment.