Parcourir la source

AppHarness: handle `get_state_name` for minified names

Also clear the StatefulComponent cache between AppInstance runs
Masen Furer il y a 7 mois
Parent
commit
db2b5b0320
1 fichiers modifiés avec 8 ajouts et 8 suppressions
  1. 8 8
      reflex/testing.py

+ 8 - 8
reflex/testing.py

@@ -43,6 +43,7 @@ import reflex.utils.exec
 import reflex.utils.format
 import reflex.utils.prerequisites
 import reflex.utils.processes
+from reflex.components.component import StatefulComponent
 from reflex.config import environment
 from reflex.state import (
     BaseState,
@@ -51,6 +52,7 @@ from reflex.state import (
     StateManagerDisk,
     StateManagerMemory,
     StateManagerRedis,
+    minified_state_names,
     reload_state_module,
 )
 from reflex.utils.types import override
@@ -193,17 +195,13 @@ class AppHarness:
 
         Returns:
             The state name
-
-        Raises:
-            NotImplementedError: when minified state names are enabled
         """
-        if reflex.constants.CompileVars.MINIFY_STATES():
-            raise NotImplementedError(
-                "This API is not available with minified state names."
-            )
-        return reflex.utils.format.to_snake_case(
+        state_name = reflex.utils.format.to_snake_case(
             f"{self.app_name}___{self.app_name}___" + state_cls_name
         )
+        if reflex.constants.CompileVars.MINIFY_STATES():
+            return minified_state_names.get(state_name, state_name)
+        return state_name
 
     def get_full_state_name(self, path: List[str]) -> str:
         """Get the full state name for the given state class name.
@@ -284,6 +282,8 @@ class AppHarness:
                 )
                 self.app_module_path.write_text(source_code)
         with chdir(self.app_path):
+            # Reset stateful component cache for new app
+            StatefulComponent.tag_to_stateful_component.clear()
             # ensure config and app are reloaded when testing different app
             reflex.config.get_config(reload=True)
             # Save decorated pages before importing the test app module