quarto-dev / quarto-cli

Open-source scientific and technical publishing system built on Pandoc.
https://quarto.org
Other
3.97k stars 327 forks source link

Wrong preview url used when `_quarto.yml` is present #10265

Open skwde opened 4 months ago

skwde commented 4 months ago

Bug description

When _quarto.yml is present (even if empty) a wrong preview url is used even though the correct one is displayed after running quarto preview test.qmd. (I use the VSCode extension)

Possibly related: https://github.com/quarto-dev/quarto-cli/issues/6409

Steps to reproduce

Create an empty _quarto.yml and a test.qmd like

---
title: "Test"
---

# abc

and run quarto preview test.qmd.

When choosing either preview option (Editor / Browser) it tries to open the URL http://127.0.0.1:<port>/ while the preview command actually shows http://localhost:<port>/test.html as the correct URL.

Expected behavior

Use correct URL to preview

Actual behavior

Wrong URL is used to preview

Your environment

Quarto check output

# quarto check
Quarto 1.5.54
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.2.0: OK
      Dart Sass version 1.70.0: OK
      Deno version 1.41.0: OK
      Typst version 0.11.0: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 1.5.54
      Path: /opt/quarto/bin

[✓] Checking tools....................OK
      TinyTeX: v2024.07.03
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /root/.TinyTeX/bin/x86_64-linux
      Version: 2024

[✓] Checking basic markdown render....OK

[✓] Checking Python 3 installation....OK
      Version: 3.12.4 (Conda)
      Path: /opt/conda/bin/python
      Jupyter: 5.7.2
      Kernels: python3

[✓] Checking Jupyter engine render....OK

[✓] Checking R installation...........(None)

      Unable to locate an installed version of R.
      Install R from https://cloud.r-project.org/
cderv commented 4 months ago

it tries to open the URL http://127.0.0.1:/ while the preview

127.0.0.1 is supposed to be equivalent to localhost. What does the url get you too exactly ? What is the wrong preview showing exactly ?

I believe we use localhost for preview URL only , but the host really binds to 127.0.0.1

I found this discussion with history on this : https://github.com/quarto-dev/quarto-cli/pull/947

skwde commented 4 months ago

The preview just gives a 404 error.

Can you reproduce the error?

I think the problem is not with 127.0.0.1 / localhost but the missing document name (test.html).

Compare

with

Note that in the quarto preview version we have the test.html which is missing in the url used by the preview.

When I append test.html to the url used in the preview (http://127.0.0.1:<port>/) it renders properly.

cderv commented 4 months ago

I think the problem is not with 127.0.0.1 / localhost but the missing document name (test.html).

Oh thanks for making this clearer - I missed this. Definitely something wrong here...

cderv commented 4 months ago

Though I can't reproduce right now image

This is with Quarto: preview menu command.

Same result with quarto preview test.qmd in VSCODE terminal, though it opened in eternal browser.

In VSCODE we do special handling where the url does not show test.html but this si the file shown. So somehow this processing may not work for you.

Can you be sure to use latest version to tools ?

Does quarto preview test.qmd works for you outside of VSCODE in a standalone terminal ? Thanks

skwde commented 4 months ago

I confirm that the VSCode command Quarto: Preview works.

Here are the related versions

Since I am using a devcontainer it is not working outside VSCode.

Note also, that when _quarto.yml is not present quarto preview shows the same URL as used by VSCode when opening via the dialog

Screenshot 2024-07-12 at 06 06 52

So it seems to be a project specific problem with this dialog.

skwde commented 2 months ago

@cderv

I just noticed an additional wrong behavior.

The --port option seems to be ignored when serving.

When I run

quarto preview test.qmd --port 8010

I get the following output in VSCode

Screenshot 2024-09-04 at 10 33 44

and everything looks fine. But when I now click on "Preview in Editor" the following is opened

Screenshot 2024-09-04 at 10 34 42

The page is only accessible when I use http://localhost:58637/test.html.

cderv commented 2 months ago

If you click Open in Browser, or look at http://localhost:8010/test.html inside a browser does it works ?

skwde commented 2 months ago

@cdrev just realized that there was a response.

No, it doesn't matter wheter "Open in Borwser" or "Preview in Editor" is used.

cderv commented 2 months ago

look at http://localhost:8010/test.html inside a browser does it works ?

So nothing shows on 8010 port in browser ? (Outside of VSCODE)

skwde commented 2 months ago

I tested it again. So running

quarto preview test.qmd --port 8010

shows

Screenshot 2024-09-19 at 13 12 13

When I click "Open in Browser" a tab opens at http://localhost:8011/ which just shows Not Found.

If I connect to http://localhost:8011/test.html it works even though Is specified port 8010?!.

When I do the same but click "Preview in Editor" I get the same behavior.

Weirdly, VSCode also shows

Screenshot 2024-09-19 at 13 18 25

cderv commented 2 months ago

Interesting that it says localhost:8011 when you set 8010 🤔

Can you confirm that `quarto preview test.qmd --port 8010``work outside of VSCODE ?

This is to confirm this is Quarto CLI directly, or VSOCDE integration. Thanks.

skwde commented 2 months ago

@cderv outside of VSCode (on MacOS) it just works.