From f278e43e0fee9cc33529ad3bc5b22d28ed7cd701 Mon Sep 17 00:00:00 2001 From: Poh <167305720+pohlrabi404@users.noreply.github.com> Date: Thu, 28 Aug 2025 05:00:36 +0900 Subject: [PATCH] Hash page instead of frame for watch command (#6810) --- crates/typst-cli/src/compile.rs | 8 ++++---- crates/typst-library/src/layout/page.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/typst-cli/src/compile.rs b/crates/typst-cli/src/compile.rs index 30cf1473..508a08fa 100644 --- a/crates/typst-cli/src/compile.rs +++ b/crates/typst-cli/src/compile.rs @@ -15,7 +15,7 @@ use typst::diag::{ At, Severity, SourceDiagnostic, SourceResult, StrResult, Warned, bail, }; use typst::foundations::{Datetime, Smart}; -use typst::layout::{Frame, Page, PageRanges, PagedDocument}; +use typst::layout::{Page, PageRanges, PagedDocument}; use typst::syntax::{FileId, Lines, Span}; use typst_html::HtmlDocument; use typst_pdf::{PdfOptions, PdfStandards, Timestamp}; @@ -380,7 +380,7 @@ fn export_image( // If the frame is in the cache, skip it. // If the file does not exist, always create it. if config.watching - && config.export_cache.is_cached(*i, &page.frame) + && config.export_cache.is_cached(*i, page) && path.exists() { return Ok(Output::Path(path.to_path_buf())); @@ -483,8 +483,8 @@ impl ExportCache { /// Returns true if the entry is cached and appends the new hash to the /// cache (for the next compilation). - pub fn is_cached(&self, i: usize, frame: &Frame) -> bool { - let hash = typst::utils::hash128(frame); + pub fn is_cached(&self, i: usize, page: &Page) -> bool { + let hash = typst::utils::hash128(page); let mut cache = self.cache.upgradable_read(); if i >= cache.len() { diff --git a/crates/typst-library/src/layout/page.rs b/crates/typst-library/src/layout/page.rs index 461ff580..c111f550 100644 --- a/crates/typst-library/src/layout/page.rs +++ b/crates/typst-library/src/layout/page.rs @@ -462,7 +462,7 @@ pub struct PagedDocument { } /// A finished page. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Hash)] pub struct Page { /// The frame that defines the page. pub frame: Frame,