Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
zbeyens committed Nov 25, 2024
1 parent c36d537 commit e79c165
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
15 changes: 14 additions & 1 deletion apps/www/src/components/block-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ function BlockViewerProvider({
>(highlightedFiles?.[0]?.target ?? null);
const [isLoading, setIsLoading] = React.useState(false);
const [isSettled, setIsSettled] = React.useState(false);
const [hasError, setHasError] = React.useState(false); // Add error state
const resizablePanelRef = React.useRef<ImperativePanelHandle>(null);

// Load code files when switching to code view
Expand All @@ -124,6 +125,7 @@ function BlockViewerProvider({
highlightedFiles?.[1] &&
!highlightedFiles[1].content &&
!isLoading &&
!hasError &&
!isSettled
) {
const loadFiles = async () => {
Expand All @@ -136,6 +138,9 @@ function BlockViewerProvider({
if (!activeFile && files?.length) {
setActiveFile(files[0].target!);
}
} catch (error) {
console.error('Failed to load files:', error);
setHasError(true); // Set error state to prevent retries
} finally {
setIsLoading(false);
}
Expand All @@ -144,7 +149,15 @@ function BlockViewerProvider({
};
void loadFiles();
}
}, [activeFile, highlightedFiles, isLoading, isSettled, item.name, view]);
}, [
activeFile,
hasError,
highlightedFiles,
isLoading,
isSettled,
item.name,
view,
]);

return (
<BlockViewerContext.Provider
Expand Down
2 changes: 1 addition & 1 deletion apps/www/src/lib/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ async function getAllItemFiles(
}

async function getFileContent(filePath: string) {
const raw = await fs.readFile(filePath, 'utf8');
const raw = await fs.readFile(path.join(process.cwd(), filePath), 'utf8');

const project = new Project({
compilerOptions: {},
Expand Down

0 comments on commit e79c165

Please sign in to comment.