Stale cached JavaScript output after dependency file change in figwheel-main watcher
0 reputation · 09 Aug 2022, 01:12 UTC
0 reputation · 09 Aug 2022, 01:12 UTC
Goal: Determine why figwheel-main’s file‑watcher fails to trigger recompilation when a dependency file is modified, resulting in stale cached JavaScript output when using :optimizations :none.
Constraints: The watcher relies on file modification timestamps; system clock adjustments or touching a file without changing its content can leave the cache unchanged. It is unclear whether figwheel-main supplements timestamps with content‑based checks or if additional configuration (e.g., :watch-dirs, :cache-dir) can guarantee detection of genuine changes.
Uncertainty: Whether the current implementation invalidates the cache only on timestamp changes, and how to configure reliable invalidation when timestamps are not trustworthy.
Specific questions: Does figwheel-main’s watcher depend solely on modification times for dependency files? Can adjusting :watch-dirs or :cache-dir alter this behavior? What configuration or workflow ensures recompilation when timestamps cannot be trusted?
Figwheel‑main’s file‑watcher is built on Java NIO WatchService. It generates a recompilation only when it receives a file‑system event for a path it is actively watching. By default the watcher monitors only the directories listed in :source-paths. Files that live outside those directories (e.g., external dependency source files, JAR‑unpacked libs, or files in a separate lib/ folder) are not watched unless they are explicitly added to :watch-dirs. Because the watcher does not fall back to polling timestamps or content hashes, a change that does not produce a WatchEvent (or occurs in an unwatched directory) leaves the in‑memory cache unchanged, resulting in stale JavaScript output when :optimizations :none is used.
WatchService events; there is no automatic timestamp‑based polling for dependencies.:cache-dir setting only controls where intermediate build artifacts are stored and does not affect event detection.:watch-dirs extends the watcher’s scope to that path, causing events from files inside it to trigger recompilation.:watch-dirs: In your figwheel‑main build config, include the absolute or relative path to the directory containing the dependency source, e.g.,
:watch-dirs ["src" "dev-resources" "../shared-lib/src"]
:verbose true) to see which files triggered the recompilation.If the dependency file is inside a JAR or located on a filesystem where WatchService is unreliable (e.g., certain NFS mounts, Docker volumes, or Windows shared folders), events may be dropped. In that case consider:
chokidar via a custom script) as a temporary workaround.WatchService notifications.Only if you discover that the dependency files are JAR‑resident or on an unreliable mount would the recommendation change; otherwise adding the directory to :watch-dirs resolves the issue.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.