diff --git a/reflex/app.py b/reflex/app.py index 8f388e37b..9c40db195 100644 --- a/reflex/app.py +++ b/reflex/app.py @@ -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)