Skip to content

fix: run new files even if marked saved#2360

Merged
deadlyjack merged 2 commits into
mainfrom
ajit/fix-run
Jun 22, 2026
Merged

fix: run new files even if marked saved#2360
deadlyjack merged 2 commits into
mainfrom
ajit/fix-run

Conversation

@deadlyjack

Copy link
Copy Markdown
Member

No description provided.

@greptile-apps

greptile-apps Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes preview/run for new (unsaved-to-disk) files that have been marked as saved by the editor but still lack a filesystem URI. The old condition only served in-buffer content when isUnsaved was true, so a new file whose save-state flag was cleared would fall through to a broken sendFile(null, …) path.

  • Core fix (!url || (file && file.loaded && file.isUnsaved)): when no URL exists (new file with no URI), the buffer is always served regardless of isUnsaved, correctly handling the "saved but no path yet" state in both the HTML and default MIME branches.
  • Sub-resource guard (filename === reqPath): prevents the active file's buffer from being returned for every linked asset (CSS, JS, images) when no pathName is set; those requests now correctly receive a 404.
  • Early-exit guard (!url && !file): replaces the silent fall-through into the switch with an explicit 404 when neither a URL nor an in-editor file was resolved.

Confidence Score: 5/5

Safe to merge — the three coordinated guards are logically consistent and cover all reachable code paths correctly.

All four changes work together: the filename === reqPath narrowing prevents sub-resources from matching the new-file branch, the !url && !file guard replaces the silent fall-through with an explicit 404, and the !url short-circuit in the switch correctly serves in-buffer content for new files regardless of their save-state flag. No existing path is regressed.

No files require special attention.

Important Files Changed

Filename Overview
src/lib/run.js Four targeted changes: adds filename===reqPath guard for the new-file branch, adds an early-exit 404 when neither URL nor file is resolved, and expands HTML/default switch conditions to serve from buffer whenever there is no URL (new file). Logic is sound; the previous P2 sub-resource issue is addressed.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[handleRequest] --> B[sendByExt]
    B --> C{SAFMode single?}
    C -- Yes --> D[serve single file or 404]
    C -- No --> E[url = activeFile.uri]
    E --> F{pathName set?}
    F -- Yes --> G[url = join pathName + reqPath\nfile = getFile by URI]
    F -- No --> H{!activeFile.uri\nAND filename === reqPath?}
    H -- Yes --> I[file = activeFile\nurl stays null]
    H -- No --> J[file = null\nurl stays null]
    G --> K{!url AND !file?}
    I --> K
    J --> K
    K -- Yes --> L[error 404 ← NEW early exit]
    K -- No --> M{ext?}
    M -- .html/.htm --> N{!url OR file.loaded AND isUnsaved?}
    M -- .md --> O{file set?}
    M -- default --> P{!url OR file.loaded AND isUnsaved?}
    N -- Yes --> Q[sendHTML from buffer]
    N -- No --> R[sendFileContent from disk]
    O -- Yes --> S[render markdown → sendText]
    P -- Yes --> T[sendText from buffer]
    P -- No --> U{url set?}
    U -- Yes --> V[sendFile from disk]
    U -- No --> W[error 404]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[handleRequest] --> B[sendByExt]
    B --> C{SAFMode single?}
    C -- Yes --> D[serve single file or 404]
    C -- No --> E[url = activeFile.uri]
    E --> F{pathName set?}
    F -- Yes --> G[url = join pathName + reqPath\nfile = getFile by URI]
    F -- No --> H{!activeFile.uri\nAND filename === reqPath?}
    H -- Yes --> I[file = activeFile\nurl stays null]
    H -- No --> J[file = null\nurl stays null]
    G --> K{!url AND !file?}
    I --> K
    J --> K
    K -- Yes --> L[error 404 ← NEW early exit]
    K -- No --> M{ext?}
    M -- .html/.htm --> N{!url OR file.loaded AND isUnsaved?}
    M -- .md --> O{file set?}
    M -- default --> P{!url OR file.loaded AND isUnsaved?}
    N -- Yes --> Q[sendHTML from buffer]
    N -- No --> R[sendFileContent from disk]
    O -- Yes --> S[render markdown → sendText]
    P -- Yes --> T[sendText from buffer]
    P -- No --> U{url set?}
    U -- Yes --> V[sendFile from disk]
    U -- No --> W[error 404]
Loading

Reviews (2): Last reviewed commit: "fix" | Re-trigger Greptile

@deadlyjack

Copy link
Copy Markdown
Member Author

@greptile_apps review

@deadlyjack deadlyjack merged commit 14f9042 into main Jun 22, 2026
@github-project-automation github-project-automation Bot moved this from Backlog to Done in The Code Board - Acode Jun 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done