Skip to content

Commit

Permalink
refactor: fallback missing pages to home page (#4600)
Browse files Browse the repository at this point in the history
See
https://discord.com/channels/955905230107738152/1318274135679438959/1318274135679438959

With undo current selected pages can be deleted
though we do not have a logic reverting selected page or instance.

So here is quick fix to always fallback to home page if pageId in url
references missing page.
  • Loading branch information
TrySound committed Dec 17, 2024
1 parent a2ad056 commit 0c2f4e4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion apps/builder/app/shared/pages/use-switch-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import {
} from "~/shared/nano-states";
import { builderPath } from "~/shared/router-utils";
import { $selectedPage, selectPage } from "../awareness";
import { findPageByIdOrPath } from "@webstudio-is/sdk";

const setPageStateFromUrl = () => {
const searchParams = new URLSearchParams(window.location.search);
const pages = $pages.get();
if (pages === undefined) {
return;
}
const pageId = searchParams.get("pageId") ?? pages.homePage.id;

let mode = searchParams.get("mode");

Expand All @@ -30,6 +30,12 @@ const setPageStateFromUrl = () => {

setBuilderMode(mode);

// check the page actually exists
// to avoid confusing the user with broken state
const pageId =
findPageByIdOrPath(searchParams.get("pageId") ?? "", pages)?.id ??
pages.homePage.id;

$selectedPageHash.set(searchParams.get("pageHash") ?? "");
selectPage(pageId);
};
Expand Down

0 comments on commit 0c2f4e4

Please sign in to comment.