From 982711dbba3cf8e7a78bd4318ed2399fd9a19a7c Mon Sep 17 00:00:00 2001 From: George Gevoian Date: Wed, 9 Jun 2021 20:48:39 -0700 Subject: [PATCH] (core) Update active view id when default view id changes Summary: This fixes a bug where deleting a page with the page id missing from the URL would cause JS errors to be thrown. Test Plan: Verified manually in dev environment. Browser test added that should hopefully replicate the repro steps and catch any regressions. Reviewers: dsagal, paulfitz Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2856 --- app/client/components/GristDoc.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/client/components/GristDoc.ts b/app/client/components/GristDoc.ts index 053e90b1..4adda671 100644 --- a/app/client/components/GristDoc.ts +++ b/app/client/components/GristDoc.ts @@ -153,7 +153,9 @@ export class GristDoc extends DisposableWithEvents { const defaultViewId = this.docInfo.newDefaultViewId; // Grainjs observable for current view id, which may be a string such as 'code'. - this.activeViewId = Computed.create(this, urlState().state, (use, s) => s.docPage || defaultViewId.peek()); + this.activeViewId = Computed.create(this, (use) => { + return use(urlState().state).docPage || use(defaultViewId); + }); // This viewModel reflects the currently active view, relying on the fact that // createFloatingRowModel() supports an observable rowId for its argument.