quarto-dev / quarto-cli

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

Quarto preview only works on first call/render on draft document #10279

Open mcanouil opened 2 months ago

mcanouil commented 2 months ago

Bug description

Quarto preview only works on first call/render on draft document.

Steps to reproduce

  1. Create a blog
quarto create project blog website Website
  1. Add draft: true to posts/post-with-code/index.qmd frontmatter.

  2. Preview the draft post

quarto preview posts/post-with-code/index.qmd
  1. Modify the draft post

Expected behavior

Quarto should still preview a draft even when modified.

Actual behavior

https://github.com/quarto-dev/quarto-cli/assets/8896044/9f8e7efd-d97d-4bbd-9564-f1bc25dbc802

Quarto check output

9724c3dd403d4e723bcb0a7e7bef6e49d23a353a

Quarto 99.9.9
[✓] 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: 99.9.9
      commit: 9724c3dd403d4e723bcb0a7e7bef6e49d23a353a
      Path: /Users/mcanouil/Projects/quarto/quarto-cli/package/dist/bin

Check file:///Users/mcanouil/Projects/quarto/quarto-cli/src/resources/vendor/deno-land/x/puppeteer@9-0-2/mod.ts
[✓] Checking tools....................OK
      TinyTeX: v2024.07.03
      Chromium: (not installed)

[✓] Checking LaTeX....................OK
      Using: TinyTex
      Path: /Users/mcanouil/Library/TinyTeX/bin/universal-darwin
      Version: 2024

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

[✓] Checking Python 3 installation....OK
      Version: 3.12.4
      Path: /opt/homebrew/opt/python@3.12/bin/python3.12
      Jupyter: (None)

      Jupyter is not available in this Python installation.
      Install with python3 -m pip install jupyter

(|) Checking R installation...........ℹ R version 4.4.1 (2024-06-14)
! Config '~/.Rprofile' was loaded!
[✓] Checking R installation...........OK
      Version: 4.4.1
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Library/Frameworks/R.framework/Versions/4.4-arm64/Resources/library
      knitr: 1.46
      rmarkdown: 2.26

[✓] Checking Knitr engine render......OK
AlbertRapp commented 1 month ago

In case it helps, I discovered this bug this morning too after updating from v.1.4 to v.1.5 (but also persists in v.1.6). Took me quite some time to figure out that draft: true was the problem.

I noticed that this happens for blogs but not standalone qmd-files. Also, it seems like the preview technically "works" the second time. It's just that the resulting HTML <body> is empty. I can still navigate to the served file in my browser and it is not shown as "not found".

NicolasBoumal commented 3 weeks ago

On Windows, I face the same issue with a blog in Quarto 1.5 and (pre-release of) 1.6. No issue with 1.4.

The suggestion of @AlbertRapp, namely, setting draft = false, did not resolve the issue in my case.

mcanouil commented 3 weeks ago

@NicolasBoumal "draft" did not exist on 1.4.

AlbertRapp commented 3 weeks ago

@mcanouil The draft yaml option existed already in 1.2 (not sure if before that though). Take for example this blog post from Tom Mock from 2022 that talks about using draft. In that post, Tom uses 1.2.242

image

mcanouil commented 3 weeks ago

Edit: No, it did not.

Tom used the _ prefix trick to create a draft mode as files prefixed with _ are not rendered and not included but still there. Here we are talking about the website draft mode (which is a 1.5 feature) which allow preview and don't require de name/rename files with/without _ prefix.

AlbertRapp commented 3 weeks ago

The R function that is written in the blog post adds draft: true to the YAML header if draft R variable is true:

# add draft if draft
  if(draft){
    new_post_text <- [c](https://rdrr.io/r/base/c.html)(
      new_post_core,
      "draft: true",
      "---\n"
      )
  } else {
    new_post_text <- [c](https://rdrr.io/r/base/c.html)(
      new_post_core,
      "---\n"
    )
  }

As Tom comments, the _ prefix is redundant anyway to the YAML option. But this already acknowledges that draft: true exists and does what one expects.

image

Anyway, I've used the draft: true option for quite some time now on my blog (which I so far understood is a special case of a website due to the fact that my yaml file says project: type: website). So I'm pretty sure that it's not a new 1.5 feature. After all, I only commented that the draft preview broke for me after updating from 1.4. As far as I could tell, what's new is the cool draft banner on top of a preview now and the special docs for draft mode but draft: true has been there for some time now.

All in all, I don't really care what version this feature belongs to. Just wanted to add the information when things stopped working for me in case it helps to find out when/how that bug crept in.

NicolasBoumal commented 3 weeks ago

I only meant to confirm that for me as well the issue with web preview appears in quarto v1.5+ (no issue in v1.4), while mentioning that (in my case) draft mode seems to have no effect on that issue.