Prechádzať zdrojové kódy

reload config on __post_init__ (#5064)

* reload config on __call__

* maybe

* move get config after app
Khaleel Al-Adhami 1 mesiac pred
rodič
commit
6afcaf60bd

+ 2 - 0
reflex/app.py

@@ -443,6 +443,8 @@ class App(MiddlewareMixin, LifespanMixin):
                 "rx.BaseState cannot be subclassed directly. Use rx.State instead"
             )
 
+        get_config(reload=True)
+
         if "breakpoints" in self.style:
             set_breakpoints(self.style.pop("breakpoints"))
 

+ 12 - 3
reflex/utils/codespaces.py

@@ -11,8 +11,17 @@ from reflex.components.component import Component
 from reflex.components.core.banner import has_connection_errors
 from reflex.components.core.cond import cond
 from reflex.constants import Endpoint
+from reflex.utils.decorator import once
 
-redirect_script = """
+
+@once
+def redirect_script() -> str:
+    """Get the redirect script for Github Codespaces.
+
+    Returns:
+        The redirect script as a string.
+    """
+    return """
 const thisUrl = new URL(window.location.href);
 const params = new URLSearchParams(thisUrl.search)
 
@@ -61,7 +70,7 @@ def codespaces_auto_redirect() -> list[Component]:
         A list containing the conditional redirect component, or empty list.
     """
     if is_running_in_codespaces():
-        return [cond(has_connection_errors, Script.create(redirect_script))]
+        return [cond(has_connection_errors, Script.create(redirect_script()))]
     return []
 
 
@@ -87,5 +96,5 @@ async def auth_codespace() -> HTMLResponse:
         </body>
     </html>
     """
-        % redirect_script
+        % redirect_script()
     )

+ 1 - 2
tests/integration/test_extra_overlay_function.py

@@ -11,8 +11,6 @@ from reflex.testing import AppHarness, WebDriver
 def ExtraOverlay():
     import reflex as rx
 
-    rx.config.get_config().extra_overlay_function = "reflex.components.moment.moment"
-
     def index():
         return rx.vstack(
             rx.el.input(
@@ -26,6 +24,7 @@ def ExtraOverlay():
         )
 
     app = rx.App()
+    rx.config.get_config().extra_overlay_function = "reflex.components.moment.moment"
     app.add_page(index)