Skip to content

Commit

Permalink
Prevent the document editor from losing its state when (re)gaining fo…
Browse files Browse the repository at this point in the history
…cus (#1745)

Prevent the document editor from losing its state when (re)gaining focus

In v6.1.0 a loading indicator was added to the document editor (in
`PagesPage`).
This had an unwanted side effect: Focusing the edit page automatically
causes a GraphQL request to check for a newer version of the document.
This request also caused the loading indicator to render, thus
unmounting the editor (`EditComponent`). Consequently, the local state
of the editor was lost.

This didn't strike when testing locally because the focus aware polling
is disabled in dev mode.

---

Before:


https://github.com/vivid-planet/comet/assets/13380047/d72c7286-e5f3-434c-ad9c-5c32b95a6135

After:


https://github.com/vivid-planet/comet/assets/13380047/c2658da2-b8e6-438d-b770-c108ac21a344

---

Closes COM-482
  • Loading branch information
thomasdax98 authored Feb 22, 2024
1 parent 34bb33f commit 5dfe483
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .changeset/metal-penguins-tease.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@comet/cms-admin": patch
---

Prevent the document editor from losing its state when (re)gaining focus

In v6.1.0 a loading indicator was added to the document editor (in `PagesPage`).
This had an unwanted side effect: Focusing the edit page automatically causes a GraphQL request to check for a newer version of the document. This request also caused the loading indicator to render, thus unmounting the editor (`EditComponent`). Consequently, the local state of the editor was lost.
2 changes: 1 addition & 1 deletion packages/admin/cms-admin/src/pages/pagesPage/PagesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ export function PagesPage({
{(selectedId) => {
const page = data?.pages.find((page) => page.id == selectedId);

if (loading) {
if (loading && isInitialLoad.current) {
return <Loading behavior="fillPageHeight" />;
}

Expand Down

0 comments on commit 5dfe483

Please sign in to comment.