Skip to content

Commit

Permalink
Don't auto-run if app file is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
wch committed Jul 29, 2024
1 parent 1ce625f commit 38fe829
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/Components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,7 @@ export function App({
terminalMethods={terminalMethods}
viewerMethods={viewerMethods}
utilityMethods={utilityMethods}
runOnLoad={currentFiles.some(
(file) =>
file.name === "app.py" ||
file.name === "app.R" ||
file.name === "server.R",
)}
runOnLoad={isRunnableApp(currentFiles)}
updateUrlHashOnRerun={appOptions.updateUrlHashOnRerun}
appEngine={appEngine}
/>
Expand Down Expand Up @@ -454,12 +449,7 @@ export function App({
terminalMethods={terminalMethods}
viewerMethods={viewerMethods}
utilityMethods={utilityMethods}
runOnLoad={currentFiles.some(
(file) =>
file.name === "app.py" ||
file.name === "app.R" ||
file.name === "server.R",
)}
runOnLoad={isRunnableApp(currentFiles)}
updateUrlHashOnRerun={appOptions.updateUrlHashOnRerun}
appEngine={appEngine}
/>
Expand Down Expand Up @@ -774,6 +764,18 @@ const propertyOfAppOptions = function <AppOptions>(name: keyof AppOptions) {
return name;
};

// Return true if the FileContent[] contains an app.py, app.R, or server.R that
// is non-empty.
function isRunnableApp(files: FileContent[]): boolean {
return files.some(
(file) =>
(file.name === "app.py" ||
file.name === "app.R" ||
file.name === "server.R") &&
file.content !== "",
);
}

// =============================================================================
// Code templates
// =============================================================================
Expand Down

0 comments on commit 38fe829

Please sign in to comment.