From 6d314d10c58c21673a613c80d25d0f3b25e4b281 Mon Sep 17 00:00:00 2001 From: Masen Furer Date: Wed, 22 Jan 2025 15:30:11 -0800 Subject: [PATCH] Fix setting default color mode in dev mode (#4616) * Fix setting default color mode in dev mode Without this, the last_compiled_timestamp local storage never gets set because it's always `null` until it gets set. * test_client_storage: also pop `theme` key from next-themes --- .../components/reflex/radix_themes_color_mode_provider.js | 5 +---- tests/integration/test_client_storage.py | 2 ++ 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js b/reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js index dd7886c89..823eeea99 100644 --- a/reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js +++ b/reflex/.templates/web/components/reflex/radix_themes_color_mode_provider.js @@ -16,10 +16,7 @@ export default function RadixThemesColorModeProvider({ children }) { if (isDevMode) { const lastCompiledTimeInLocalStorage = localStorage.getItem("last_compiled_time"); - if ( - lastCompiledTimeInLocalStorage && - lastCompiledTimeInLocalStorage !== lastCompiledTimeStamp - ) { + if (lastCompiledTimeInLocalStorage !== lastCompiledTimeStamp) { // on app startup, make sure the application color mode is persisted correctly. setTheme(defaultColorMode); localStorage.setItem("last_compiled_time", lastCompiledTimeStamp); diff --git a/tests/integration/test_client_storage.py b/tests/integration/test_client_storage.py index 9273de70f..367409b1b 100644 --- a/tests/integration/test_client_storage.py +++ b/tests/integration/test_client_storage.py @@ -321,6 +321,7 @@ async def test_client_side_state( assert not driver.get_cookies() local_storage_items = local_storage.items() local_storage_items.pop("last_compiled_time", None) + local_storage_items.pop("theme", None) assert not local_storage_items # set some cookies and local storage values @@ -436,6 +437,7 @@ async def test_client_side_state( local_storage_items = local_storage.items() local_storage_items.pop("last_compiled_time", None) + local_storage_items.pop("theme", None) assert local_storage_items.pop(f"{sub_state_name}.l1") == "l1 value" assert local_storage_items.pop(f"{sub_state_name}.l2") == "l2 value" assert local_storage_items.pop("l3") == "l3 value"