-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Allow custom toast message in production mode by adding optional connection_error_message arg in rx.config #6060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
2d14f28
5993ed4
9fefbc8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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,13 @@ def add_hooks(self) -> list[str | Var]: | |
| """ | ||
| toast_id = "websocket-error" | ||
| target_url = WebsocketTargetURL.create() | ||
| config = get_config() | ||
| is_dev_mode = environment.REFLEX_ENV_MODE.get().value == constants.Env.DEV | ||
| props = ToastProps( | ||
| description=LiteralVar.create( | ||
| f"Check if server is reachable at {target_url}", | ||
| f"Check if server is reachable at {target_url}" | ||
| if is_dev_mode or not config.connection_error_message | ||
| else config.connection_error_message | ||
| ), | ||
| close_button=True, | ||
| duration=120000, | ||
|
|
@@ -135,6 +140,8 @@ def add_hooks(self) -> list[str | Var]: | |
| else: | ||
| loading_message = Var.create( | ||
| f"Cannot connect to server: {connection_error}." | ||
| if is_dev_mode or not config.connection_error_message | ||
| else "" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shouldn't it be connection error message?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That would duplicate the error message. The connection error toast has two parts, title and description, but since I'm setting one error message in rxconfig I figured just pass the message in the title and leave the description empty. |
||
| ) | ||
| toast_var = Var( | ||
| f"toast?.error({loading_message!s}, {{...toast_props, onDismiss: () => setUserDismissed(true)}},)" | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't it be simpler to change the responsibility of providing this to the config provider? meaning, in rxconfig you only provide connection error message when on prod
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, added new commit removing those env mode checks