Fix book/website preview crash from reused closed SassCache KV handle - #14716
Merged
Conversation
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.
Collaborator
✅ Snyk checks have passed. No issues have been found so far.
💻 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
quarto previewre-renders a book or website project, Sass compilation crashes withBadResource: Bad resource IDfromKv.get, repeating across chapter/part pages.Root Cause
SassCache.cleanup()(src/core/sass/cache.ts:146-160) closes the instance'sDeno.Kvhandle but leaves the entry in the module-level_sassCacheregistry.sassCache(path, temp)only creates a new instanceif (!_sassCache[path]), so the next call resolves the stale closed-KV instance, and any subsequentkv.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'srefreshProjectConfig(src/project/serve/watch.ts:62-66) still callsproject.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 nextsassCache()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 intests/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
css, edit_quarto.ymlrepeatedly to trigger project reloads — noBadResourcecrashtests/docs/manual/preview/sass-cache-crash-14594/via/quarto-preview-testT34-T36Fixes #14594