diff --git a/reflex/app.py b/reflex/app.py index 73de8bba5..0a1963ae9 100644 --- a/reflex/app.py +++ b/reflex/app.py @@ -108,6 +108,7 @@ class App(Base): """ super().__init__(*args, **kwargs) state_subclasses = State.__subclasses__() + inferred_state = state_subclasses[-1] is_testing_env = constants.PYTEST_CURRENT_TEST in os.environ # Special case to allow test cases have multiple subclasses of rx.State. @@ -117,13 +118,14 @@ class App(Base): raise ValueError( "rx.State has been subclassed multiple times. Only one subclass is allowed" ) - if self.state != DefaultState: - console.deprecate( - "Passing the state as keyword argument to `rx.App` is deprecated. " - "The base state will automatically be inferred as the subclass of `rx.State`." - ) - self.state = state_subclasses[-1] + # verify that provided state is valid + if self.state not in [DefaultState, inferred_state]: + console.warn( + f"Using substate ({self.state.__name__}) as root state in `rx.App` is currently not supported." + f" Defaulting to root state: ({inferred_state.__name__})" + ) + self.state = inferred_state # Get the config config = get_config() diff --git a/reflex/utils/console.py b/reflex/utils/console.py index 936990b6c..b90d322bc 100644 --- a/reflex/utils/console.py +++ b/reflex/utils/console.py @@ -21,6 +21,15 @@ def deprecate(msg: str) -> None: _console.print(f"[yellow]DeprecationWarning: {msg}[/yellow]") +def warn(msg: str) -> None: + """Print a warning about bad usage in Reflex. + + Args: + msg: The warning message. + """ + _console.print(f"[orange1]UsageWarning: {msg}[/orange1]") + + def log(msg: str) -> None: """Takes a string and logs it to the console.