From fc2b2f42a2a13550d5f9a4ff2c7a11ec96907fa3 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Tue, 28 Oct 2025 15:50:04 +1100 Subject: [PATCH] Avoid deadlock when preloading (#2236) * Fix preload deadlock * Add experimental flag --- CHANGELOG.md | 2 +- nav.go | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 19d5e8a3..d3dc1cfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,7 +25,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - A new command `cmd-menu-discard` is added to allow exiting the completion menu with completions discarded (#2146). - The `lf_mode` environment variable will now be set to `compmenu` if the completion menu is active (#2146). - A `ruler` config file is added as an alternate method for customizing the ruler (#2186). This is intended to eventually replace the existing `rulerfmt`/`statfmt` options and must be enabled using the new `rulerfile` option. **This feature is currently experimental.** -- A new option `preload` is added to enable calling the `previewer` to generate previews in advance (#2206). +- A new option `preload` is added to enable calling the `previewer` to generate previews in advance (#2206). **This feature is currently experimental.** ### Fixed diff --git a/nav.go b/nav.go index de70595e..427d0bdf 100644 --- a/nav.go +++ b/nav.go @@ -827,7 +827,10 @@ func (nav *nav) preload() { } nav.regCache[file.path] = ®{loading: true, loadTime: time.Now(), path: file.path} - nav.preloadChan <- file.path + select { + case nav.preloadChan <- file.path: + default: + } } nav.startPreview() @@ -914,7 +917,10 @@ func (nav *nav) loadReg(path string, volatile bool) *reg { nav.regCache[path] = r nav.startPreview() if gOpts.preload { - nav.preloadChan <- path + select { + case nav.preloadChan <- path: + default: + } } else { nav.previewChan <- path }