Skip to content

Conversation

@cderv
Copy link
Collaborator

@cderv cderv commented Jan 28, 2026

When re-rendering a file during quarto preview in a project, the preview crashes with BadResource: Bad resource ID from the Sass cache Deno.Kv operations.

Root Cause

This is a regression from #13804 which changed how ProjectContext is managed during preview. That PR made the project context persist across re-renders (instead of being recreated each time), but renderForPreview() still called renderResult.context.cleanup() after each render.

The cleanup closes shared resources like the SassCache Deno.Kv handle. On subsequent re-renders, the code returns the cached SassCache instance whose KV handle was already closed, causing the BadResource error when calling kv.get().

Fix

  1. Remove the cleanup() call from renderForPreview() - the project context is owned by preview() and should only be cleaned up when preview exits via onCleanup()

  2. Invalidate the fileInformationCache entry for the rendered file before each render - since cleanup() previously cleared all caches (including fileInformationCache), removing the call means stale file content would be reused. The cache entry for the specific file being rendered is now deleted so changes are picked up.

Fixes #13955

@posit-snyk-bot
Copy link
Collaborator

posit-snyk-bot commented Jan 28, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

cderv and others added 5 commits January 29, 2026 14:46
…t each render in preview mode

the project context is owned by `preview()` and cleaned up when preview exits. Calling `cleanup()`  here would close shared resources (like SassCache KV handles) causing BadResource errors on subsequent re-renders (#13955).
… ensure changes are picked up in preview mode
… cross-platform consistency

ensureFileInformationCache now normalizes file paths before using them
as cache keys. This ensures cache invalidation works correctly on Windows
where paths may have backslash separators.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This normalization is related to

Windows / Linux and Project vs Single file leads to different paths. I tried to make that works because we need to delete by key, so it is important to get the right path, but obviously this modify current behavior, and leads to failed test.

cderv added 2 commits January 29, 2026 16:55
…ache for cross-platform consistency"

This reverts commit b796ec4.
Documents the project context lifecycle fix from #13804 that resolves
intermittent preview crashes when editing notebooks and qmd files.
@cderv
Copy link
Collaborator Author

cderv commented Jan 29, 2026

😞 I tried to preview quarto-web with this PR, and I still encounter some issue with sass Kv, we may have an other issue.

@cderv
Copy link
Collaborator Author

cderv commented Jan 29, 2026

Ok so I don't manage to reproduce, maybe it was a bad state. quarto preview on quarto-web works ok to navigate;

However, as expected, change .scss file for example does trigger re-render, but the change are not shown. Though I am really not even sure this working with current 1.8 as discussed.

However, testing quarto render on a single doc, no project fails to udpate.

And I am quite convinced this is because of this normalize path key. So not good to merge yet

  • Quarto Project => quarto preview works
  • Single file => quarto preview does not show change in output file.

and add a debug log message when we do so.
@cderv
Copy link
Collaborator Author

cderv commented Jan 29, 2026

🤦 It is late for me and I spent much time of this, now this should really be non-normalized path for lookup.

I'll test tomorrow manually the behavior

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.

BadResource error during preview re-render

3 participants