Skip to content

Fix preview browse URL for single-file documents#14300

Merged
cderv merged 6 commits intomainfrom
fix/issue-14298
Apr 3, 2026
Merged

Fix preview browse URL for single-file documents#14300
cderv merged 6 commits intomainfrom
fix/issue-14298

Conversation

@cderv
Copy link
Copy Markdown
Collaborator

@cderv cderv commented Apr 2, 2026

quarto preview hello.qmd prints Browse at http://localhost:PORT/hello.html instead of http://localhost:PORT/, and GET / returns 404. This breaks Posit Workbench Proxied Servers pane which uses the base URL.

Root Cause

PR #13804 added singleFileProjectContext() as a fallback, making the project variable always non-null. Two code paths in preview() branch on project being truthy:

  1. URL path computation (line 271): initialPath computed relative(projectOutputDir, outputFile) = "hello.html" instead of "" for single files
  2. Handler selection (line 251): used projectHtmlFileRequestHandler (defaultFile="index.html") instead of htmlFileRequestHandler (defaultFile=basename(outputFile)), causing GET / to 404

Fix

Guard both branches with !project.isSingleFile. The isSingleFile flag is already set on single-file project contexts and used in ~15 other places for the same kind of guard. Extract URL path computation into previewInitialPath() for testability.

Verification

Tested locally with qvm — both browse URL and HTTP response:

Version Browse URL GET / GET /hello.html
v1.8.27 http://localhost:PORT/ 200 200
v1.9.36 http://localhost:PORT/hello.html 404 200
This fix http://localhost:PORT/ 200 200

Unit tests added for previewInitialPath() covering single-file, project, project-subdir, and undefined-project cases. Manual test entries T17-T19 added to tests/docs/manual/preview/README.md.

Fixes #14298

cderv added 2 commits April 2, 2026 11:09
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
cderv added 4 commits April 2, 2026 12:13
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 cderv merged commit a42c44c into main Apr 3, 2026
51 checks passed
@cderv cderv deleted the fix/issue-14298 branch April 3, 2026 11:31
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Quarto 1.9 preview server appends output filename to Browse URL, breaking proxied server access

1 participant