From d04aa8d1c16e1a4589517d1652b2830fc10cbe27 Mon Sep 17 00:00:00 2001 From: Kha Nguyen Date: Thu, 17 Jul 2025 20:08:08 -0500 Subject: [PATCH] fix: prevent multiple project creation when project doesn't exist --- apps/web/src/app/editor/[project_id]/page.tsx | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/apps/web/src/app/editor/[project_id]/page.tsx b/apps/web/src/app/editor/[project_id]/page.tsx index ad8561ac..039e7ca0 100644 --- a/apps/web/src/app/editor/[project_id]/page.tsx +++ b/apps/web/src/app/editor/[project_id]/page.tsx @@ -37,7 +37,6 @@ export default function Editor() { const params = useParams(); const router = useRouter(); const projectId = params.project_id as string; - const handledProjectIds = useRef>(new Set()); const [isOnboardingOpen, setIsOnboardingOpen] = useState(true); useDisableBrowserZoom(); @@ -45,20 +44,14 @@ export default function Editor() { useEffect(() => { const initProject = async () => { - if (!projectId) return; - - if (handledProjectIds.current.has(projectId)) { - return; - } - try { await loadProject(projectId); - } catch (error) { - handledProjectIds.current.add(projectId); - - const newProjectId = await createNewProject("Untitled Project"); - router.replace(`/editor/${newProjectId}`); - return; + } catch (error: any) { + // if the project is not found, go back to the projects page, + // creating a new project here will cause multiple projects to be created + if (error.message.includes("not found")) { + router.push("/projects"); + } } };