Skip to content

Commit e804be2

Browse files
committed
Allow HotReload to tell client to just reload css in place
1 parent 25b5ef7 commit e804be2

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/arel/_app.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,23 @@ async def _on_changes(
3939
self, changeset: ChangeSet, *, on_reload: List[ReloadFunc]
4040
) -> None:
4141
description = ", ".join(
42-
f"file {event} at {', '.join(f'{event!r}' for event in changeset[event])}"
42+
f"file {event} at {', '.join(f'{file!r}' for file in changeset[event])}"
4343
for event in changeset
4444
)
4545
logger.warning("Detected %s. Triggering reload...", description)
4646

47+
all_files = []
48+
for event in changeset:
49+
all_files.extend(changeset[event])
50+
51+
only_css_changes = all(all_files.endswith(".css") for all_files in all_files)
52+
53+
if only_css_changes:
54+
print("Only CSS files changed")
55+
for file in all_files:
56+
await self.notify.notify_css(file)
57+
return
58+
4759
# Run server-side hooks first.
4860
for callback in on_reload:
4961
await callback()
@@ -81,8 +93,8 @@ async def _wait_client_disconnect(self, ws: WebSocket) -> None:
8193
pass # pragma: no cover
8294

8395
async def _watch_reloads(self, ws: WebSocket) -> None:
84-
async for _ in self.notify.watch():
85-
await ws.send_text("reload")
96+
async for msg in self.notify.watch():
97+
await ws.send_text(msg)
8698

8799
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
88100
assert scope["type"] == "websocket"

0 commit comments

Comments
 (0)