Revert "fix: prevent multiple project creation when project doesn't exist"

This reverts commit d04aa8d1c1.
This commit is contained in:
Kha Nguyen 2025-07-17 20:25:16 -05:00
parent d04aa8d1c1
commit e4748ecb09
1 changed files with 13 additions and 6 deletions

View File

@ -37,6 +37,7 @@ export default function Editor() {
const params = useParams(); const params = useParams();
const router = useRouter(); const router = useRouter();
const projectId = params.project_id as string; const projectId = params.project_id as string;
const handledProjectIds = useRef<Set<string>>(new Set());
const [isOnboardingOpen, setIsOnboardingOpen] = useState(true); const [isOnboardingOpen, setIsOnboardingOpen] = useState(true);
useDisableBrowserZoom(); useDisableBrowserZoom();
@ -44,14 +45,20 @@ export default function Editor() {
useEffect(() => { useEffect(() => {
const initProject = async () => { const initProject = async () => {
if (!projectId) return;
if (handledProjectIds.current.has(projectId)) {
return;
}
try { try {
await loadProject(projectId); await loadProject(projectId);
} catch (error: any) { } catch (error) {
// if the project is not found, go back to the projects page, handledProjectIds.current.add(projectId);
// creating a new project here will cause multiple projects to be created
if (error.message.includes("not found")) { const newProjectId = await createNewProject("Untitled Project");
router.push("/projects"); router.replace(`/editor/${newProjectId}`);
} return;
} }
}; };