diff --git a/reflex/components/core/banner.py b/reflex/components/core/banner.py index 8160faf38c5..209f099a941 100644 --- a/reflex/components/core/banner.py +++ b/reflex/components/core/banner.py @@ -16,6 +16,7 @@ from reflex.components.radix.themes.layout.flex import Flex from reflex.components.radix.themes.typography.text import Text from reflex.components.sonner.toast import ToastProps, toast_ref +from reflex.config import get_config from reflex.constants import Dirs, Hooks, Imports from reflex.constants.compiler import CompileVars from reflex.environment import environment @@ -100,9 +101,11 @@ def add_hooks(self) -> list[str | Var]: """ toast_id = "websocket-error" target_url = WebsocketTargetURL.create() + config = get_config() props = ToastProps( description=LiteralVar.create( - f"Check if server is reachable at {target_url}", + config.connection_error_message + or f"Check if server is reachable at {target_url}" ), close_button=True, duration=120000, @@ -135,6 +138,8 @@ def add_hooks(self) -> list[str | Var]: else: loading_message = Var.create( f"Cannot connect to server: {connection_error}." + if not config.connection_error_message + else "" ) toast_var = Var( f"toast?.error({loading_message!s}, {{...toast_props, onDismiss: () => setUserDismissed(true)}},)" diff --git a/reflex/config.py b/reflex/config.py index 81441ff4c5a..1940078f58d 100644 --- a/reflex/config.py +++ b/reflex/config.py @@ -262,6 +262,9 @@ class BaseConfig: _prefixes: ClassVar[list[str]] = ["REFLEX_"] + # The message to display in the frontend when a connection error occurs. + connection_error_message: str | None = None + _PLUGINS_ENABLED_BY_DEFAULT = [ SitemapPlugin,