@@ -149,7 +149,7 @@ export default function Home() {
149149 }
150150
151151 loadProjectMessages ( )
152- } , [ currentProject ] )
152+ } , [ currentProject , supabase ] )
153153
154154 useEffect ( ( ) => {
155155 async function saveMessagesToDb ( ) {
@@ -164,7 +164,7 @@ export default function Home() {
164164 if ( messages . length > 0 && currentProject && session ) {
165165 saveMessagesToDb ( )
166166 }
167- } , [ messages , currentProject , session ] )
167+ } , [ messages , currentProject , session , supabase ] )
168168
169169 useEffect ( ( ) => {
170170 if ( object ) {
@@ -223,20 +223,18 @@ export default function Home() {
223223 stop ( )
224224 }
225225
226- // Create new project if none exists
227- if ( ! currentProject ) {
228- const title = await generateProjectTitle ( chatInput )
229- if ( supabase ) {
230- const newProject = await createProject ( supabase , title , selectedTemplate === 'auto' ? undefined : selectedTemplate )
231- if ( newProject ) {
232- setCurrentProject ( newProject )
233- }
234- }
235- }
236-
237- const content : Message [ 'content' ] = [ { type : 'text' , text : chatInput } ]
238- const images = await toMessageImage ( files )
226+ // Clear input and files immediately for better UX
227+ const currentInput = chatInput
228+ const currentFiles = [ ...files ]
229+ setChatInput ( '' )
230+ setFiles ( [ ] )
231+ setCurrentTab ( 'code' )
239232
233+ // Create message content immediately
234+ const content : Message [ 'content' ] = [ { type : 'text' , text : currentInput } ]
235+
236+ // Process images asynchronously
237+ const images = await toMessageImage ( currentFiles )
240238 if ( images . length > 0 ) {
241239 images . forEach ( ( image ) => {
242240 content . push ( { type : 'image' , image } )
@@ -250,6 +248,7 @@ export default function Home() {
250248 const updatedMessages = [ ...messages , newMessage ]
251249 setMessages ( updatedMessages )
252250
251+ // Start submission immediately
253252 submit ( {
254253 userID : session ?. user ?. id ,
255254 teamID : userTeam ?. id ,
@@ -259,9 +258,20 @@ export default function Home() {
259258 config : languageModel ,
260259 } )
261260
262- setChatInput ( '' )
263- setFiles ( [ ] )
264- setCurrentTab ( 'code' )
261+ // Handle project creation asynchronously without blocking
262+ if ( ! currentProject ) {
263+ try {
264+ const title = await generateProjectTitle ( currentInput )
265+ if ( supabase ) {
266+ const newProject = await createProject ( supabase , title , selectedTemplate === 'auto' ? undefined : selectedTemplate )
267+ if ( newProject ) {
268+ setCurrentProject ( newProject )
269+ }
270+ }
271+ } catch ( error ) {
272+ console . error ( 'Error creating project:' , error )
273+ }
274+ }
265275
266276 posthog . capture ( 'chat_submit' , {
267277 template : selectedTemplate ,
0 commit comments