diff options
| author | haoyuren <13851610112@163.com> | 2026-03-15 15:52:07 -0500 |
|---|---|---|
| committer | haoyuren <13851610112@163.com> | 2026-03-15 15:52:07 -0500 |
| commit | 90abc457f29f110dbf89f98efef5d9743efee963 (patch) | |
| tree | 2b6162bfb25e02ec928dfc4380575ab7d06ddd32 | |
| parent | 72b38fed1d75fcb3420beeeeefd3dc2fc442e64b (diff) | |
Fix PDF not refreshing after recompile
setPdfPath with the same path didn't trigger re-render. Added pdfVersion
counter that increments on every setPdfPath call, used as dependency in
PdfViewer's renderPdf to force reload regardless of path equality.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
| -rw-r--r-- | src/renderer/src/App.tsx | 1 | ||||
| -rw-r--r-- | src/renderer/src/components/PdfViewer.tsx | 4 | ||||
| -rw-r--r-- | src/renderer/src/stores/appStore.ts | 5 |
3 files changed, 7 insertions, 3 deletions
diff --git a/src/renderer/src/App.tsx b/src/renderer/src/App.tsx index 1aedbd6..63be974 100644 --- a/src/renderer/src/App.tsx +++ b/src/renderer/src/App.tsx @@ -282,6 +282,7 @@ export default function App() { useAppStore.getState().appendCompileLog(result.log) } if (result.pdfPath) { + useAppStore.getState().setPdfPath(null) useAppStore.getState().setPdfPath(result.pdfPath) } useAppStore.getState().setCompiling(false) diff --git a/src/renderer/src/components/PdfViewer.tsx b/src/renderer/src/components/PdfViewer.tsx index ef37b5b..cfd34e9 100644 --- a/src/renderer/src/components/PdfViewer.tsx +++ b/src/renderer/src/components/PdfViewer.tsx @@ -127,7 +127,7 @@ function parseCompileLog(raw: string): LogEntry[] { type LogFilter = 'all' | 'error' | 'warning' export default function PdfViewer() { - const { pdfPath, compileLog, compiling } = useAppStore() + const { pdfPath, pdfVersion, compileLog, compiling } = useAppStore() const pendingPdfGoTo = useAppStore((s) => s.pendingPdfGoTo) const containerRef = useRef<HTMLDivElement>(null) // scroll viewport const wrapperRef = useRef<HTMLDivElement>(null) // inner wrapper (CSS transform target) @@ -343,7 +343,7 @@ export default function PdfViewer() { } finally { renderingRef.current = false } - }, [pdfPath, renderScale, tab]) + }, [pdfPath, pdfVersion, renderScale, tab]) // Apply CSS transform on wrapper for instant visual zoom useEffect(() => { diff --git a/src/renderer/src/stores/appStore.ts b/src/renderer/src/stores/appStore.ts index 6b3b6cd..ec9b309 100644 --- a/src/renderer/src/stores/appStore.ts +++ b/src/renderer/src/stores/appStore.ts @@ -57,6 +57,7 @@ interface AppState { // PDF pdfPath: string | null + pdfVersion: number setPdfPath: (p: string | null) => void // Compile @@ -179,7 +180,8 @@ export const useAppStore = create<AppState>((set) => ({ setMainDocument: (p) => set({ mainDocument: p }), pdfPath: null, - setPdfPath: (p) => set({ pdfPath: p }), + pdfVersion: 0, + setPdfPath: (p) => set((s) => ({ pdfPath: p, pdfVersion: s.pdfVersion + 1 })), compiling: false, setCompiling: (c) => set({ compiling: c }), @@ -254,6 +256,7 @@ export const useAppStore = create<AppState>((set) => ({ fileContents: {}, mainDocument: null, pdfPath: null, + pdfVersion: 0, compileLog: '', compiling: false, showSearch: false, |
