Skip to content
4 changes: 4 additions & 0 deletions news/changelog-1.9.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ All changes included in 1.9:

- ([#4426](https://github.com/quarto-dev/quarto-cli/issues/4426)): New `quarto install verapdf` command installs [veraPDF](https://verapdf.org/) for PDF/A and PDF/UA validation. When verapdf is available, PDFs created with the `pdf-standard` option are automatically validated for compliance. Also supports `quarto uninstall verapdf`, `quarto update verapdf`, and `quarto tools`.

### `preview`

- ([#13804](https://github.com/quarto-dev/quarto-cli/pull/13804)): Fix intermittent preview crashes during re-renders by properly managing project context lifecycle. Resolves issues with missing temporary directories and `quarto_ipynb` files when editing notebooks and qmd files together.

## Extensions

- Metadata and brand extensions now work without a `_quarto.yml` project. (Engine extensions do too.) A temporary default project is created in memory.
Expand Down
13 changes: 10 additions & 3 deletions src/command/preview/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Copyright (C) 2020-2022 Posit Software, PBC
*/

import { info, warning } from "../../deno_ral/log.ts";
import { debug, info, warning } from "../../deno_ral/log.ts";
import {
basename,
dirname,
Expand Down Expand Up @@ -424,6 +424,15 @@ export async function renderForPreview(
pandocArgs: string[],
project?: ProjectContext,
): Promise<RenderForPreviewResult> {
// Invalidate file cache for the file being rendered so changes are picked up.
// The project context persists across re-renders in preview mode, but the
// fileInformationCache contains file content that needs to be refreshed.
// TODO(#13955): Consider adding a dedicated invalidateForFile() method on ProjectContext
if (project?.fileInformationCache) {
debug(`[renderForPreview] Invalidating file information cache for ${file}`);
project.fileInformationCache.delete(file);
}

// render
const renderResult = await render(file, {
services,
Expand Down Expand Up @@ -485,8 +494,6 @@ export async function renderForPreview(
[],
));

renderResult.context.cleanup();

return {
file,
format: renderResult.files[0].format,
Expand Down
2 changes: 2 additions & 0 deletions src/core/sass/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ class SassCache implements Cloneable<SassCache> {
// add a cleanup method to register a cleanup handler
cleanup(temp: TempContext | undefined) {
const registerCleanup = temp ? temp.onCleanup : onCleanup;
const cachePath = this.path;
registerCleanup(() => {
log.debug(`SassCache cleanup executing for ${cachePath}`);
try {
this.kv.close();
if (temp) safeRemoveIfExists(this.path);
Expand Down
Loading