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

This commit is contained in:
Kha Nguyen 2025-07-17 20:08:08 -05:00
parent e7bad87217
commit d04aa8d1c1
1 changed files with 6 additions and 13 deletions

View File

@ -37,7 +37,6 @@ 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();
@ -45,20 +44,14 @@ 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) { } catch (error: any) {
handledProjectIds.current.add(projectId); // if the project is not found, go back to the projects page,
// creating a new project here will cause multiple projects to be created
const newProjectId = await createNewProject("Untitled Project"); if (error.message.includes("not found")) {
router.replace(`/editor/${newProjectId}`); router.push("/projects");
return; }
} }
}; };