Skip to content

Fix build errors #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions app/api/generate/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,27 +100,27 @@ export async function POST(request: NextRequest) {
}

// Repair the generated code using Benchify's API
// const { data } = await benchify.fixer.run({
// files: filesToSandbox.map(file => ({
// path: file.path,
// contents: file.content
// }))
// });
const { data } = await benchify.fixer.run({
files: filesToSandbox.map(file => ({
path: file.path,
contents: file.content
}))
});

let repairedFiles = filesToSandbox;
// if (data) {
// const { success, diff } = data;

// if (success && diff) {
// repairedFiles = filesToSandbox.map(file => {
// const patchResult = applyPatch(file.content, diff);
// return {
// ...file,
// content: typeof patchResult === 'string' ? patchResult : file.content
// };
// });
// }
// }
if (data) {
const { success, diff } = data;

if (success && diff) {
repairedFiles = filesToSandbox.map(file => {
const patchResult = applyPatch(file.content, diff);
return {
...file,
content: typeof patchResult === 'string' ? patchResult : file.content
};
});
}
}

const sandboxResult = await createSandbox({ files: repairedFiles });

Expand Down
10 changes: 5 additions & 5 deletions components/ui-builder/code-editor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useState, useEffect } from "react";
import { useState, useEffect, useCallback } from "react";
import { benchifyFileSchema } from "@/lib/schemas";
import { z } from "zod";
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
Expand Down Expand Up @@ -35,7 +35,7 @@ export function CodeEditor({ files = [] }: CodeEditorProps) {
const [openFolders, setOpenFolders] = useState<Set<string>>(new Set());

// Build file tree structure (pure function, no side effects)
const buildFileTree = (files: Array<{ path: string; content: string }>): { tree: FileNode[], allFolders: string[] } => {
const buildFileTree = useCallback((files: Array<{ path: string; content: string }>): { tree: FileNode[], allFolders: string[] } => {
const root: FileNode[] = [];
const folderMap = new Map<string, FileNode>();
const allFolders: string[] = [];
Expand Down Expand Up @@ -81,7 +81,7 @@ export function CodeEditor({ files = [] }: CodeEditorProps) {
});

return { tree: root, allFolders };
};
}, []);

const { tree: fileTree, allFolders } = buildFileTree(files);
const selectedFile = files.find(f => f.path === selectedFilePath);
Expand All @@ -91,14 +91,14 @@ export function CodeEditor({ files = [] }: CodeEditorProps) {
if (allFolders.length > 0) {
setOpenFolders(new Set(allFolders));
}
}, [files.length]); // Only trigger when files array changes
}, [allFolders]);

// Auto-select first file if none selected (only once when files change)
useEffect(() => {
if (!selectedFilePath && files.length > 0) {
setSelectedFilePath(files[0].path);
}
}, [files.length, selectedFilePath]); // Dependency on selectedFilePath prevents loops
}, [files, selectedFilePath]);

// Get file icon based on extension
const getFileIcon = (path: string) => {
Expand Down
14 changes: 12 additions & 2 deletions components/ui-builder/error-display.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ interface BuildError {
column?: number;
}

interface FixResult {
originalFiles: z.infer<typeof benchifyFileSchema>;
repairedFiles: z.infer<typeof benchifyFileSchema>;
buildOutput: string;
previewUrl: string;
buildErrors?: BuildError[];
hasErrors: boolean;
editInstruction?: string;
}

interface ErrorDisplayProps {
errors: BuildError[];
currentFiles?: z.infer<typeof benchifyFileSchema>;
onFixComplete?: (result: any) => void;
onFixComplete?: (result: FixResult) => void;
}

export function ErrorDisplay({ errors, currentFiles, onFixComplete }: ErrorDisplayProps) {
Expand Down Expand Up @@ -196,7 +206,7 @@ Please make the minimal changes necessary to resolve these errors while maintain
<li>• Verify that all props are properly typed</li>
<li>• Make sure all dependencies are correctly installed</li>
<li>• Try regenerating the component with more specific requirements</li>
{currentFiles && <li>• Use the "Fix with AI" button above for automatic error resolution</li>}
{currentFiles && <li>• Use the &quot;Fix with AI&quot; button above for automatic error resolution</li>}
</ul>
</div>
</div>
Expand Down
14 changes: 12 additions & 2 deletions components/ui-builder/preview-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,24 @@ interface BuildError {
column?: number;
}

interface FixResult {
originalFiles: z.infer<typeof benchifyFileSchema>;
repairedFiles: z.infer<typeof benchifyFileSchema>;
buildOutput: string;
previewUrl: string;
buildErrors?: BuildError[];
hasErrors: boolean;
editInstruction?: string;
}

interface PreviewCardProps {
previewUrl?: string;
code: z.infer<typeof benchifyFileSchema>;
isGenerating?: boolean;
prompt?: string;
buildErrors?: BuildError[];
hasErrors?: boolean;
onFixComplete?: (result: any) => void;
onFixComplete?: (result: FixResult) => void;
}

export function PreviewCard({
Expand Down Expand Up @@ -110,7 +120,7 @@ export function PreviewCard({
<CardHeader>
<CardTitle>Building Your UI</CardTitle>
<p className="text-sm text-muted-foreground mt-2">
"{prompt.substring(0, 100)}{prompt.length > 100 ? '...' : ''}"
&quot;{prompt.substring(0, 100)}{prompt.length > 100 ? '...' : ''}&quot;
</p>
</CardHeader>
<CardContent className="space-y-4">
Expand Down