diff --git a/reflex/config.py b/reflex/config.py index 8b961a6b88b..c9babf45e0a 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -284,6 +284,9 @@ class Config(BaseConfig): See the [configuration](https://reflex.dev/docs/getting-started/configuration/) docs for more info. """ + # Track whether the app name has already been validated for this Config instance. + _app_name_is_valid: bool = dataclasses.field(default=False, repr=False) + def _post_init(self, **kwargs): """Post-initialization method to set up the config. diff --git a/reflex/utils/prerequisites.py b/reflex/utils/prerequisites.py index 1a2c429c4f1..eb7ca99f420 100644 --- a/reflex/utils/prerequisites.py +++ b/reflex/utils/prerequisites.py @@ -165,6 +165,7 @@ def _check_app_name(config: Config): else: msg += f"Ensure app_name='{config.app_name}' in rxconfig.py matches your folder structure." raise ModuleNotFoundError(msg) + config._app_name_is_valid = True def get_app(reload: bool = False) -> ModuleType: @@ -184,7 +185,9 @@ def get_app(reload: bool = False) -> ModuleType: try: config = get_config() - _check_app_name(config) + # Avoid hitting disk when the app name has already been validated in this process. + if not config._app_name_is_valid: + _check_app_name(config) module = config.module sys.path.insert(0, str(Path.cwd()))