Skip to content

Commit d9d949f

Browse files
Console Error
An async function with useActionState was called outside
1 parent 48cfd5a commit d9d949f

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

  • src/app/(app)/projects/[id]/codespace/files/[[...path]]

src/app/(app)/projects/[id]/codespace/files/[[...path]]/page.tsx

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
'use client';
33

4-
import { useEffect, useState, Suspense, useCallback, useMemo } from 'react';
4+
import { useEffect, useState, Suspense, useCallback, useMemo, startTransition as ReactStartTransition } from 'react';
55
import { useParams, useRouter } from 'next/navigation';
66
import Link from 'next/link';
77
import { useAuth } from '@/hooks/useAuth';
@@ -34,7 +34,7 @@ import remarkGfm from 'remark-gfm';
3434
import { Badge } from '@/components/ui/badge';
3535
import NextImage from 'next/image';
3636
import { useForm } from 'react-hook-form';
37-
import { useActionState as useReactActionState } from 'react';
37+
import { useActionState } from 'react';
3838
import { zodResolver } from '@hookform/resolvers/zod';
3939
import * as z from 'zod';
4040

@@ -98,7 +98,7 @@ function FileExplorerContent() {
9898

9999
const [isAiScaffoldModalOpen, setIsAiScaffoldModalOpen] = useState(false);
100100
const aiScaffoldForm = useForm<AiScaffoldFormValues>({ resolver: zodResolver(aiScaffoldFormSchema), defaultValues: { prompt: ''}});
101-
const [aiScaffoldState, aiScaffoldFormAction, isAiScaffolding] = useReactActionState(generateProjectFilesWithAIAction, { message: "", error: ""});
101+
const [aiScaffoldState, aiScaffoldFormAction, isAiScaffolding] = useActionState(generateProjectFilesWithAIAction, { message: "", error: ""});
102102

103103

104104
const newFileForm = useForm<NewFileFormValues>({ resolver: zodResolver(newFileFormSchema), defaultValues: { fileName: '', initialContent: ''}});
@@ -203,10 +203,7 @@ function FileExplorerContent() {
203203
} else if (project && !project.githubRepoName && !isLoadingProject) {
204204
setIsLoadingPathContent(false);
205205
}
206-
// Deliberately not including forceReloadContent or currentPath in deps to avoid loops.
207-
// forceReloadContent is called explicitly or when project data changes.
208-
// currentPath changes trigger URL navigation, which leads to this effect running again via param changes.
209-
}, [project, authLoading, isLoadingProject, currentPath]); // Removed forceReloadContent from here
206+
}, [project, authLoading, isLoadingProject, currentPath, forceReloadContent]);
210207

211208

212209
const handleSaveFile = async () => {
@@ -263,7 +260,7 @@ function FileExplorerContent() {
263260
if (result.success) {
264261
toast({ title: "File Deleted", description: `${contentToDelete.name} deleted successfully.`});
265262
setContentToDelete(null);
266-
if (isViewingFile && fileData?.path === contentToDelete.path) { // If viewing the deleted file, go up
263+
if (isViewingFile && fileData?.path === contentToDelete.path) {
267264
const parentPath = currentPath.substring(0, currentPath.lastIndexOf('/'));
268265
await forceReloadContent(parentPath);
269266
router.push(`/projects/${projectUuid}/codespace/files${parentPath ? '/' + parentPath : ''}`);
@@ -281,7 +278,9 @@ function FileExplorerContent() {
281278
formData.append('projectUuid', project.uuid);
282279
formData.append('prompt', values.prompt);
283280
formData.append('basePath', currentPath);
284-
aiScaffoldFormAction(formData);
281+
ReactStartTransition(() => {
282+
aiScaffoldFormAction(formData);
283+
});
285284
};
286285

287286
useEffect(() => {
@@ -290,7 +289,7 @@ function FileExplorerContent() {
290289
toast({ title: "AI Scaffold Success", description: aiScaffoldState.message });
291290
setIsAiScaffoldModalOpen(false);
292291
aiScaffoldForm.reset();
293-
forceReloadContent(); // Reload current directory
292+
forceReloadContent();
294293
}
295294
if (aiScaffoldState.error) {
296295
toast({ variant: "destructive", title: "AI Scaffold Error", description: aiScaffoldState.error });
@@ -661,7 +660,6 @@ function FileExplorerContent() {
661660
<DialogTitle>Edit: {fileData?.name}</DialogTitle>
662661
<DialogDescription>
663662
Modify the content of the file. Your changes will be committed to GitHub.
664-
{/* Placeholder for AI button */}
665663
<Button variant="outline" size="sm" className="ml-auto mt-2" disabled>
666664
<Sparkles className="mr-2 h-4 w-4 text-primary" /> Assist with AI (Soon)
667665
</Button>

0 commit comments

Comments
 (0)