Fix preview browse URL for single-file documents#14300
Merged
Conversation
PR #13804 made project always non-null via singleFileProjectContext(), causing the initialPath computation to always take the project branch. This produced URLs like http://localhost:PORT/hello.html instead of http://localhost:PORT/ for standalone files, breaking Posit Workbench proxy access. Guard with project.isSingleFile so single-file previews use root path. Extract computation into previewInitialPath() for testability. Fixes #14298
Extend createMockProjectContext() with options object supporting isSingleFile and config parameters. Use it in preview-initial-path tests instead of a duplicate mock function.
The handler selection at line 251 had the same project-truthiness bug as the URL path computation: single-file projects used projectHtmlFileRequestHandler (defaultFile="index.html") instead of htmlFileRequestHandler (defaultFile=basename of output). This caused GET / to return 404 for single-file previews since v1.9. Add isSingleFile guard to handler selection. Also fix test cleanup by letting createMockProjectContext own temp dir creation.
T17: Verify GET / returns 200 for single-file preview T18: Verify GET /filename.html also works T19: Verify project preview paths still work with isSingleFile guard
The skill now supports three invocation modes: - By test ID: /quarto-preview-test T17 T18 - By topic: /quarto-preview-test root URL (fuzzy match + confirm) - No args: ad-hoc preview testing workflow Also add tests/docs/manual/README.md documenting all manual test suites.
cderv
added a commit
that referenced
this pull request
Apr 3, 2026
[backport] Fix preview browse URL for single-file documents Backport of #14300. After #13804 made the project variable always non-null via singleFileProjectContext(), single-file preview broke: the browse URL included the output filename and GET / returned 404. Guard both the URL path computation and handler selection with !project.isSingleFile. - Fix initialPath using relative path instead of empty string - Fix handler selection using wrong default file for single files - Add unit tests for previewInitialPath() - Add manual preview test entries and plain.qmd fixture Fixes #14298
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
quarto preview hello.qmdprintsBrowse at http://localhost:PORT/hello.htmlinstead ofhttp://localhost:PORT/, andGET /returns 404. This breaks Posit Workbench Proxied Servers pane which uses the base URL.Root Cause
PR #13804 added
singleFileProjectContext()as a fallback, making theprojectvariable always non-null. Two code paths inpreview()branch onprojectbeing truthy:initialPathcomputedrelative(projectOutputDir, outputFile)="hello.html"instead of""for single filesprojectHtmlFileRequestHandler(defaultFile="index.html") instead ofhtmlFileRequestHandler(defaultFile=basename(outputFile)), causingGET /to 404Fix
Guard both branches with
!project.isSingleFile. TheisSingleFileflag is already set on single-file project contexts and used in ~15 other places for the same kind of guard. Extract URL path computation intopreviewInitialPath()for testability.Verification
Tested locally with
qvm— both browse URL and HTTP response:GET /GET /hello.htmlhttp://localhost:PORT/http://localhost:PORT/hello.htmlhttp://localhost:PORT/Unit tests added for
previewInitialPath()covering single-file, project, project-subdir, and undefined-project cases. Manual test entries T17-T19 added totests/docs/manual/preview/README.md.Fixes #14298