[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:
parent
772a3ef893
commit
9e1789a6c2
@ -15,6 +15,7 @@ import platform
|
|||||||
import sys
|
import sys
|
||||||
import traceback
|
import traceback
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
AsyncIterator,
|
AsyncIterator,
|
||||||
@ -1018,9 +1019,6 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
|
|
||||||
progress.advance(task)
|
progress.advance(task)
|
||||||
|
|
||||||
# Empty the .web pages directory.
|
|
||||||
compiler.purge_web_pages_dir()
|
|
||||||
|
|
||||||
progress.advance(task)
|
progress.advance(task)
|
||||||
progress.stop()
|
progress.stop()
|
||||||
|
|
||||||
@ -1038,6 +1036,19 @@ class App(MiddlewareMixin, LifespanMixin, Base):
|
|||||||
transpile_packages=transpile_packages,
|
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:
|
for output_path, code in compile_results:
|
||||||
compiler_utils.write_page(output_path, code)
|
compiler_utils.write_page(output_path, code)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user