From 1502047bf220a09c936f1bdff9deace677c9994c Mon Sep 17 00:00:00 2001 From: Akhileshrangani4 Date: Sat, 31 Aug 2024 20:31:20 -0400 Subject: [PATCH] fix: files not loading when creating a new project --- frontend/components/dashboard/index.tsx | 6 ++---- frontend/components/editor/index.tsx | 13 ++++++++----- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/frontend/components/dashboard/index.tsx b/frontend/components/dashboard/index.tsx index 4724041..42231dd 100644 --- a/frontend/components/dashboard/index.tsx +++ b/frontend/components/dashboard/index.tsx @@ -49,10 +49,8 @@ export default function Dashboard({ const q = searchParams.get("q") const router = useRouter() - useEffect(() => { - if (!sandboxes) { - router.refresh() - } + useEffect(() => { // update the dashboard to show a new project + router.refresh() }, [sandboxes]) return ( diff --git a/frontend/components/editor/index.tsx b/frontend/components/editor/index.tsx index 5d4340d..3c4504b 100644 --- a/frontend/components/editor/index.tsx +++ b/frontend/components/editor/index.tsx @@ -45,9 +45,13 @@ export default function CodeEditor({ const { socket, setUserAndSandboxId } = useSocket(); useEffect(() => { - // Check if socket is null, and initialize it by setting userId and sandboxId - if (!socket && userData.id && sandboxData.id) { - setUserAndSandboxId(userData.id, sandboxData.id); + // Ensure userData.id and sandboxData.id are available before attempting to connect + if (userData.id && sandboxData.id) { + // Check if the socket is not initialized or not connected + if (!socket || (socket && !socket.connected)) { + // Initialize socket connection + setUserAndSandboxId(userData.id, sandboxData.id); + } } }, [socket, userData.id, sandboxData.id, setUserAndSandboxId]); @@ -477,8 +481,7 @@ export default function CodeEditor({ socket?.off("disableAccess", onDisableAccess) socket?.off("previewURL", loadPreviewURL) } - // }, []); - }, [terminals]) + }, [socket, terminals, setTerminals, setFiles, toast, setDisableAccess, isOwner, loadPreviewURL]); // Helper functions for tabs: