Skip to content

Fix book/website preview crash from reused closed SassCache KV handle - #14716

Merged
cderv merged 2 commits into
mainfrom
fix/issue-14594
Jul 21, 2026
Merged

Fix book/website preview crash from reused closed SassCache KV handle#14716
cderv merged 2 commits into
mainfrom
fix/issue-14594

Conversation

@cderv

@cderv cderv commented Jul 21, 2026

Copy link
Copy Markdown
Member

When quarto preview re-renders a book or website project, Sass compilation crashes with BadResource: Bad resource ID from Kv.get, repeating across chapter/part pages.

Root Cause

SassCache.cleanup() (src/core/sass/cache.ts:146-160) closes the instance's Deno.Kv handle but leaves the entry in the module-level _sassCache registry. sassCache(path, temp) only creates a new instance if (!_sassCache[path]), so the next call resolves the stale closed-KV instance, and any subsequent kv.get() throws.

Same root-cause family as #13955, fixed in #13967 by dropping the context.cleanup() call from the single-file preview path (renderForPreview). Book and website preview go through a different path — watchProject's refreshProjectConfig (src/project/serve/watch.ts:62-66) still calls project.cleanup() on every config refresh — so the underlying cache defect was never patched at its source.

Fix

Delete the _sassCache[path] entry inside the cleanup callback when the KV handle closes, so the next sassCache() call opens a fresh handle instead of reusing the closed one.

Also adds a manual preview test fixture (tests/docs/manual/preview/sass-cache-crash-14594/) and a Test Matrix section in tests/docs/manual/preview/README.md, since the serve/watch reload path this bug lives on isn't reachable from the unit test alone.

Test Plan

Fixes #14594

quarto preview on a book or website project crashed with
"BadResource: Bad resource ID" when re-rendering pages with a theme
plus custom CSS. #13955 fixed the single-file preview path by no longer
tearing down the project context between re-renders, but book and
website preview go through the serve/watch path, which still calls
project.cleanup() (and thus temp.cleanup()) on each config refresh.

The underlying defect was never addressed: SassCache.cleanup() closed
the Deno.Kv handle but left the stale SassCache in the _sassCache
registry, so a later resolve of the same cache path handed back an
instance whose KV handle was already closed. Dropping the registry
entry when the handle is closed makes every render path open a fresh
handle instead.

Fixes #14594.
@posit-snyk-bot

posit-snyk-bot commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

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

Status Scan Engine 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.

Book preview crashing on Sass recompile after a config-refresh cleanup
is an interactive serve/watch-path bug tests/unit/sass-cache.test.ts
can't reach. Add sass-cache-crash-14594/ (theme + custom css book) and
a Test Matrix section in tests/docs/manual/preview/README.md (T34-T36)
so /quarto-preview-test can drive the regression check, matching the
sibling #14593 brand-detection manual test.
@cderv
cderv merged commit c832d2d into main Jul 21, 2026
51 checks passed
@cderv
cderv deleted the fix/issue-14594 branch July 21, 2026 15:51
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: Bad resource ID crash during book project preview (SassCache stale Deno KV handle)

2 participants