Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
All notable changes to `dash` will be documented in this file.
This project adheres to [Semantic Versioning](https://semver.org/).

## [UNRELEASED]

### Fixed
- [#4171](https://github.com/plotly/dash/pull/4171) Hot reload no longer stops for the rest of the session when the assets watcher finds a file it cannot stat, such as a dangling symlink (an Emacs lock file) or a temp file deleted mid-scan. Fixes [#4170](https://github.com/plotly/dash/issues/4170).

## [4.5.1] - 2026-11-19

### Removed
Expand Down
8 changes: 6 additions & 2 deletions dash/_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ def walk():
continue
path = os.path.join(current, f)

info = os.stat(path)
new_time = info.st_mtime
try:
new_time = os.stat(path).st_mtime
except OSError:
# Gone since os.walk listed it, or a dangling symlink
# such as an editor lock file.
continue

if new_time > watched[path] > 0:
on_change(path, new_time, False)
Expand Down
35 changes: 35 additions & 0 deletions tests/integration/devtools/test_hot_reload.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
import sys
from time import sleep

import pytest

from dash.testing.wait import until

from dash import Dash, Input, Output, html
Expand Down Expand Up @@ -129,3 +132,35 @@ def new_text(n):
# rerenders with debug menu closed after reload
# reopen and check that server is now available
dash_duo_mp.find_element(".dash-debug-menu__button--available")


@pytest.mark.skipif(sys.platform == "win32", reason="symlinks need privileges")
def test_dvhr002_hot_reload_survives_dangling_symlink(dash_duo_mp, tmp_path):
assets = tmp_path / "assets"
assets.mkdir()
css = assets / "style.css"
css.write_text("#hot-reload-content { background-color: blue; }")

app = Dash(__name__, assets_folder=str(assets))
app.layout = html.Div("Hot reload", id="hot-reload-content")

dash_duo_mp.start_server(
app,
dev_tools_hot_reload=True,
dev_tools_hot_reload_interval=0.1,
dev_tools_hot_reload_watch_interval=0.1,
dev_tools_hot_reload_max_retry=100,
)
dash_duo_mp.wait_for_style_to_equal(
"#hot-reload-content", "background-color", "rgba(0, 0, 255, 1)"
)

# Editor lock files such as Emacs' `.#style.css` are dangling symlinks,
# so `os.stat` raises FileNotFoundError on them.
os.symlink(str(assets / "missing"), str(assets / ".#style.css"))
sleep(1) # let the watcher see it, and ensure a new mod time

css.write_text("#hot-reload-content { background-color: red; }")
dash_duo_mp.wait_for_style_to_equal(
"#hot-reload-content", "background-color", "rgba(255, 0, 0, 1)"
)