-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Dark Mode Toggle Not Working in 0.6.6 - Regression from 0.6.5 #4464
Comments
Tested locally. After further checking, it seems like the theme value is set correctly (see |
@ebonura-fastly edit: Managed to make it happens again. |
So overall it's a pretty weird issue. Here is a list of a few things I tried (all on the latest commit of main):
I added an integration tests that should be pretty exhaustive to catch those issues, and it seems to be passing, but I can't explain why it sometimes happens like that. |
After more testing, it seems like a page refresh seems to trigger the bug consistently.
Once the color mode is broken, it stay broken even with refresh. However, if you do:
I ran the test above on multiple browser: |
I added a page reload in the test above to try and catch the issue, but it doesn't, at least locally. I suspect some browser specific issue. |
While inspecting the page, I've noticed that the attributes @ebonura-fastly do you also see this attribute ? |
Thanks for checking this, @Lendemor . When switching between dark/light modes, the HTML tag only switches between: class="light" style="color-scheme: light" or class="dark" style="color-scheme: dark" I've tested this across multiple versions (0.6.5, 0.6.6, and 0.6.6.post2) on both Chrome and Safari, and don't see the I've also tried running |
@Lendemor I've double-checked the issue with Chrome incognito and Safari (no extensions installed) - it persists in both. While I do use Dark Reader, the problem seems to occur even with all extensions disabled. |
I'm running out of idea on what to test / how to find the problem. This is the app I'm using to test : import reflex as rx
from reflex.style import set_color_mode, color_mode, resolved_color_mode
app = rx.App()
@app.add_page
def index():
return (
rx.segmented_control.root(
rx.segmented_control.item(
rx.icon(tag="monitor", size=20),
value="system",
),
rx.segmented_control.item(
rx.icon(tag="sun", size=20),
value="light",
),
rx.segmented_control.item(
rx.icon(tag="moon", size=20),
value="dark",
),
on_change=set_color_mode,
variant="classic",
radius="large",
value=color_mode,
),
rx.text(rx.constants.Reflex.VERSION),
# rx.color_mode.button(allow_system=True),
rx.text(color_mode, id="current_color_mode"),
rx.text(resolved_color_mode, id="resolved_color_mode"),
rx.text(rx.color_mode_cond("LightMode", "DarkMode"), id="color_mode_cond"),
) |
Hey @Lendemor I think I found the root cause, it is related to the appearance setting in rx.theme, which in 0.6.6 will override whatever is set in the segmented control, this was not happening in previous versions. The reason why I couldn't switch is because I had the appearance set to light in my rx.theme to provide a default. Thanks for your help and patience while we debugged this! I think the issue can be closed, I'll leave it to you and your team if this is the expected behavior, I do believe it should be noted in https://reflex.dev/docs/recipes/others/dark-mode-toggle/ though, just to avoid confusion as people may not have it working as expected For reference, here's a minimal example showing the difference: import reflex as rx
from reflex.style import set_color_mode, color_mode, resolved_color_mode
def example_theme(appearance: str = None):
return rx.theme(
appearance=appearance
)
def dark_mode_toggle():
return rx.segmented_control.root(
rx.segmented_control.item(rx.icon(tag="monitor", size=20), value="system"),
rx.segmented_control.item(rx.icon(tag="sun", size=20), value="light"),
rx.segmented_control.item(rx.icon(tag="moon", size=20), value="dark"),
on_change=set_color_mode,
variant="classic",
radius="large",
value=color_mode,
)
def index():
return rx.vstack(
rx.heading("Dark Mode Demo"),
dark_mode_toggle(),
rx.text("Current mode: ", color_mode),
rx.text("Resolved mode: ", resolved_color_mode),
rx.text(rx.color_mode_cond("Light Theme", "Dark Theme")),
)
# Comment/uncomment to see difference
# app = rx.App(theme=example_theme("light"))
app = rx.App(theme=example_theme())
app.add_page(index) |
Hi @ebonura-fastly, thanks for figuring that out. Imo it's definitely a regression, the I'm not sure how to fix that bug (yet) but I'll update the test to take this use-case into account. |
Found a fix for this, added it in #4467 |
Describe the bug
The dark mode toggle functionality from the official Reflex documentation breaks in version 0.6.6. The same example works correctly in version 0.6.5.
To Reproduce
Steps to reproduce the behavior:
Code/Link to Repo: Using official documentation example from https://reflex.dev/docs/recipes/others/dark-mode-toggle/
Expected behavior
Dark mode toggle should switch between light and dark themes as demonstrated in the documentation and as functioning in Reflex 0.6.5.
Specifics
Additional context
The issue appears to be a regression as the official documentation example functions correctly in version 0.6.5 but breaks in 0.6.6. The bug is reproducible across different browsers.
The text was updated successfully, but these errors were encountered: