|
@@ -63,6 +63,7 @@ from reflex.state import (
|
|
State,
|
|
State,
|
|
StateManager,
|
|
StateManager,
|
|
StateUpdate,
|
|
StateUpdate,
|
|
|
|
+ code_uses_state_contexts,
|
|
)
|
|
)
|
|
from reflex.utils import console, exceptions, format, prerequisites, types
|
|
from reflex.utils import console, exceptions, format, prerequisites, types
|
|
from reflex.utils.imports import ImportVar
|
|
from reflex.utils.imports import ImportVar
|
|
@@ -169,7 +170,8 @@ class App(Base):
|
|
deprecation_version="0.3.5",
|
|
deprecation_version="0.3.5",
|
|
removal_version="0.4.0",
|
|
removal_version="0.4.0",
|
|
)
|
|
)
|
|
- self.state = State
|
|
|
|
|
|
+ if len(State.class_subclasses) > 0:
|
|
|
|
+ self.state = State
|
|
# Get the config
|
|
# Get the config
|
|
config = get_config()
|
|
config = get_config()
|
|
|
|
|
|
@@ -636,7 +638,11 @@ class App(Base):
|
|
return
|
|
return
|
|
|
|
|
|
def compile_(self):
|
|
def compile_(self):
|
|
- """Compile the app and output it to the pages folder."""
|
|
|
|
|
|
+ """Compile the app and output it to the pages folder.
|
|
|
|
+
|
|
|
|
+ Raises:
|
|
|
|
+ RuntimeError: When any page uses state, but no rx.State subclass is defined.
|
|
|
|
+ """
|
|
# add the pages before the compile check so App know onload methods
|
|
# add the pages before the compile check so App know onload methods
|
|
for render, kwargs in DECORATED_PAGES:
|
|
for render, kwargs in DECORATED_PAGES:
|
|
self.add_page(render, **kwargs)
|
|
self.add_page(render, **kwargs)
|
|
@@ -701,6 +707,16 @@ class App(Base):
|
|
stateful_components_code,
|
|
stateful_components_code,
|
|
page_components,
|
|
page_components,
|
|
) = compiler.compile_stateful_components(self.pages.values())
|
|
) = compiler.compile_stateful_components(self.pages.values())
|
|
|
|
+
|
|
|
|
+ # Catch "static" apps (that do not define a rx.State subclass) which are trying to access rx.State.
|
|
|
|
+ if (
|
|
|
|
+ code_uses_state_contexts(stateful_components_code)
|
|
|
|
+ and self.state is None
|
|
|
|
+ ):
|
|
|
|
+ raise RuntimeError(
|
|
|
|
+ "To access rx.State in frontend components, at least one "
|
|
|
|
+ "subclass of rx.State must be defined in the app."
|
|
|
|
+ )
|
|
compile_results.append((stateful_components_path, stateful_components_code))
|
|
compile_results.append((stateful_components_path, stateful_components_code))
|
|
|
|
|
|
result_futures = []
|
|
result_futures = []
|