[REF-3076] Do not purge .web/pages in dev mode (#3592)

* [REF-3067] Do not purge .web/pages in dev mode

Avoid race condition in hot reload that occurs when pages are removed before
they are recreated.

Fix #3416

* use constants instead of hardcoded string
This commit is contained in:
Masen Furer 2024-07-08 20:17:38 -07:00 committed by GitHub
parent 772a3ef893
commit 9e1789a6c2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,6 +15,7 @@ import platform
import sys
import traceback
from datetime import datetime
from pathlib import Path
from typing import (
Any,
AsyncIterator,
@ -1018,9 +1019,6 @@ class App(MiddlewareMixin, LifespanMixin, Base):
progress.advance(task)
# Empty the .web pages directory.
compiler.purge_web_pages_dir()
progress.advance(task)
progress.stop()
@ -1038,6 +1036,19 @@ class App(MiddlewareMixin, LifespanMixin, Base):
transpile_packages=transpile_packages,
)
if is_prod_mode():
# Empty the .web pages directory.
compiler.purge_web_pages_dir()
else:
# In dev mode, delete removed pages and update existing pages.
keep_files = [Path(output_path) for output_path, _ in compile_results]
for p in Path(prerequisites.get_web_dir() / constants.Dirs.PAGES).rglob(
"*"
):
if p.is_file() and p not in keep_files:
# Remove pages that are no longer in the app.
p.unlink()
for output_path, code in compile_results:
compiler_utils.write_page(output_path, code)