Skip to content

BadResource error during preview re-render #13955

Description

@mcanouil

Bug description

When running quarto preview on a document within a project (with _quarto.yml present), editing the document triggers a re-render that crashes with "BadResource: Bad resource ID".

The error originates from the Sass cache system using Deno KV.
The _sassCache global dictionary stores SassCache instances, but when cleanup closes the Deno KV database handle between renders, it does not remove the entry from _sassCache.
On re-render, the code returns the stale instance with a closed KV handle, causing the "BadResource" error when calling kv.get().

Root cause location:

  • cleanup(temp: TempContext | undefined) {
    const registerCleanup = temp ? temp.onCleanup : onCleanup;
    registerCleanup(() => {
    try {
    this.kv.close();
    if (temp) safeRemoveIfExists(this.path);
    } catch (error) {
    log.info(
    `Error occurred during sass cache cleanup for ${this.path}: ${error}`,
    );
    }
    });
    }

The cleanup method closes this.kv but does not delete the entry from _sassCache, leaving a stale reference that subsequent renders attempt to use.

Steps to reproduce

  1. Create a minimal project with two files:

_quarto.yml:

title: "Hello"
author: "Me"

index.qmd:

---
title: "Quarto Playground"
format: html
---

This is a playground for Quarto.

{{< lipsum 1 >}}
  1. Run quarto preview index.qmd.
  2. Edit index.qmd (add a space or any character) and save.
  3. Observe the crash on re-render.

Actual behavior

The preview crashes with the following error:

ERROR: BadResource: Bad resource ID

Stack trace:

at Kv.get (ext:deno_kv/01_db.ts:57:34)
at SassCache.getFromHash (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/core/sass/cache.ts:45:34)
at SassCache.getOrSet (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/core/sass/cache.ts:131:33)
at async compileSass (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/core/sass.ts:160:18)
at async resolveSassBundles (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/command/render/pandoc-html.ts:202:17)
at async resolveExtras (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/command/render/pandoc.ts:1467:14)
at async runPandoc (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/command/render/pandoc.ts:568:20)
at async renderPandoc (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/command/render/render.ts:204:24)
at async Object.onRender (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/command/render/render-files.ts:730:30)
at async renderFileInternal (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/command/render/render-files.ts:692:9)
at async renderFiles (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/command/render/render-files.ts:330:9)
at async renderProject (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/command/render/project.ts:438:23)
at async renderForPreview (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/command/preview/preview.ts:428:24)
at async render (file:///Users/mcanouil/Projects/quarto-dev/quarto-cli/src/command/preview/preview.ts:173:22)

Expected behavior

The document should re-render successfully without errors when edited during preview mode.

Your environment

  • IDE: VS Code.
  • OS: macOS Darwin 25.2.0.

Quarto check output

Quarto 99.9.9
[✓] Checking environment information...
      Quarto cache location: /Users/mcanouil/Library/Caches/quarto
[✓] Checking versions of quarto binary dependencies...
      Pandoc version 3.8.3: OK
      Dart Sass version 1.87.0: OK
      Deno version 2.4.5: OK
      Typst version 0.14.2: OK
[✓] Checking versions of quarto dependencies......OK
[✓] Checking Quarto installation......OK
      Version: 99.9.9
      commit: f14ae36813513fb64d8c84c57e511c9321f61736
      Path: /Users/mcanouil/Projects/quarto-dev/quarto-cli/package/dist/bin

[✓] Checking tools....................OK
      TinyTeX: v2026.01
      Chromium: (not installed)
      VeraPDF: (not installed)

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

[✓] Checking Chrome Headless....................OK
      Using: Chrome found on system
      Path: /Applications/Brave Browser.app/Contents/MacOS/Brave Browser
      Source: QUARTO_CHROMIUM

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

[✓] Checking R installation...........OK
      Version: 4.5.2
      Path: /Library/Frameworks/R.framework/Resources
      LibPaths:
        - /Users/mcanouil/Projects/quarto-dev/quarto-playground/renv/library/macos/R-4.5/aarch64-apple-darwin20
        - /Users/mcanouil/Library/Caches/org.R-project.R/R/renv/sandbox/macos/R-4.5/aarch64-apple-darwin20/4cd76b74
      knitr: 1.51
      rmarkdown: 2.30

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

[✓] Checking Python 3 installation....OK
      Version: 3.14.2
      Path: /opt/homebrew/opt/python@3.14/bin/python3.14
      Jupyter: (None)

[✓] Checking Julia installation...

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingpreviewissues related to the `preview` command

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions