Khaleel Al-Adhami пре 3 недеља
родитељ
комит
cf0cc12601
2 измењених фајлова са 35 додато и 26 уклоњено
  1. 5 2
      reflex/.templates/web/utils/state.js
  2. 30 24
      tests/integration/test_client_storage.py

+ 5 - 2
reflex/.templates/web/utils/state.js

@@ -710,7 +710,10 @@ const applyClientStorageDelta = (client_storage, delta) => {
   );
   if (unqualified_states.length === 1) {
     const main_state = delta[unqualified_states[0]];
-    if (main_state.is_hydrated !== undefined && !main_state.is_hydrated) {
+    if (
+      main_state.is_hydrated_rx_state_ !== undefined &&
+      !main_state.is_hydrated_rx_state_
+    ) {
       // skip if the state is not hydrated yet, since all client storage
       // values are sent in the hydrate event
       return;
@@ -933,7 +936,7 @@ export const useEventLoop = (
     const change_start = () => {
       const main_state_dispatch = dispatch["reflex___state____state"];
       if (main_state_dispatch !== undefined) {
-        main_state_dispatch({ is_hydrated: false });
+        main_state_dispatch({ is_hydrated_rx_state_: false });
       }
     };
     const change_complete = () => addEvents(onLoadInternalEvent());

+ 30 - 24
tests/integration/test_client_storage.py

@@ -352,28 +352,28 @@ async def test_client_side_state(
     )
 
     exp_cookies = {
-        f"{sub_state_name}.c1": {
+        f"{sub_state_name}.c1" + "_rx_state_": {
             "domain": "localhost",
             "httpOnly": False,
-            "name": f"{sub_state_name}.c1",
+            "name": f"{sub_state_name}.c1" + "_rx_state_",
             "path": "/",
             "sameSite": "Lax",
             "secure": False,
             "value": "c1%20value",
         },
-        f"{sub_state_name}.c2": {
+        f"{sub_state_name}.c2" + "_rx_state_": {
             "domain": "localhost",
             "httpOnly": False,
-            "name": f"{sub_state_name}.c2",
+            "name": f"{sub_state_name}.c2" + "_rx_state_",
             "path": "/",
             "sameSite": "Lax",
             "secure": False,
             "value": "c2%20value",
         },
-        f"{sub_state_name}.c4": {
+        f"{sub_state_name}.c4" + "_rx_state_": {
             "domain": "localhost",
             "httpOnly": False,
-            "name": f"{sub_state_name}.c4",
+            "name": f"{sub_state_name}.c4" + "_rx_state_",
             "path": "/",
             "sameSite": "Strict",
             "secure": False,
@@ -388,19 +388,19 @@ async def test_client_side_state(
             "secure": False,
             "value": "c6%20value",
         },
-        f"{sub_state_name}.c7": {
+        f"{sub_state_name}.c7" + "_rx_state_": {
             "domain": "localhost",
             "httpOnly": False,
-            "name": f"{sub_state_name}.c7",
+            "name": f"{sub_state_name}.c7" + "_rx_state_",
             "path": "/",
             "sameSite": "Lax",
             "secure": False,
             "value": "c7%20value",
         },
-        f"{sub_sub_state_name}.c1s": {
+        f"{sub_sub_state_name}.c1s" + "_rx_state_": {
             "domain": "localhost",
             "httpOnly": False,
-            "name": f"{sub_sub_state_name}.c1s",
+            "name": f"{sub_sub_state_name}.c1s" + "_rx_state_",
             "path": "/",
             "sameSite": "Lax",
             "secure": False,
@@ -418,13 +418,15 @@ async def test_client_side_state(
 
     # Test cookie with expiry by itself to avoid timing flakiness
     set_sub("c3", "c3 value")
-    AppHarness._poll_for(lambda: f"{sub_state_name}.c3" in cookie_info_map(driver))
-    c3_cookie = cookie_info_map(driver)[f"{sub_state_name}.c3"]
+    AppHarness._poll_for(
+        lambda: f"{sub_state_name}.c3" + "_rx_state_" in cookie_info_map(driver)
+    )
+    c3_cookie = cookie_info_map(driver)[f"{sub_state_name}.c3" + "_rx_state_"]
     assert c3_cookie.pop("expiry") is not None
     assert c3_cookie == {
         "domain": "localhost",
         "httpOnly": False,
-        "name": f"{sub_state_name}.c3",
+        "name": f"{sub_state_name}.c3" + "_rx_state_",
         "path": "/",
         "sameSite": "Lax",
         "secure": False,
@@ -433,24 +435,26 @@ async def test_client_side_state(
     time.sleep(2)  # wait for c3 to expire
     if not isinstance(driver, Firefox):
         # Note: Firefox does not remove expired cookies Bug 576347
-        assert f"{sub_state_name}.c3" not in cookie_info_map(driver)
+        assert f"{sub_state_name}.c3_rx_state_" not in cookie_info_map(driver)
 
     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(f"{sub_state_name}.l1_rx_state_") == "l1 value"
+    assert local_storage_items.pop(f"{sub_state_name}.l2_rx_state_") == "l2 value"
     assert local_storage_items.pop("l3") == "l3 value"
-    assert local_storage_items.pop(f"{sub_state_name}.l4") == "l4 value"
-    assert local_storage_items.pop(f"{sub_sub_state_name}.l1s") == "l1s value"
+    assert local_storage_items.pop(f"{sub_state_name}.l4_rx_state_") == "l4 value"
+    assert local_storage_items.pop(f"{sub_sub_state_name}.l1s_rx_state_") == "l1s value"
     assert not local_storage_items
 
     session_storage_items = session_storage.items()
     session_storage_items.pop("token", None)
-    assert session_storage_items.pop(f"{sub_state_name}.s1") == "s1 value"
-    assert session_storage_items.pop(f"{sub_state_name}.s2") == "s2 value"
+    assert session_storage_items.pop(f"{sub_state_name}.s1_rx_state_") == "s1 value"
+    assert session_storage_items.pop(f"{sub_state_name}.s2_rx_state_") == "s2 value"
     assert session_storage_items.pop("s3") == "s3 value"
-    assert session_storage_items.pop(f"{sub_sub_state_name}.s1s") == "s1s value"
+    assert (
+        session_storage_items.pop(f"{sub_sub_state_name}.s1s_rx_state_") == "s1s value"
+    )
     assert not session_storage_items
 
     assert c1.text == "c1 value"
@@ -561,11 +565,13 @@ async def test_client_side_state(
     assert s1s.text == "s1s value"
 
     # make sure c5 cookie shows up on the `/foo` route
-    AppHarness._poll_for(lambda: f"{sub_state_name}.c5" in cookie_info_map(driver))
-    assert cookie_info_map(driver)[f"{sub_state_name}.c5"] == {
+    AppHarness._poll_for(
+        lambda: f"{sub_state_name}.c5_rx_state_" in cookie_info_map(driver)
+    )
+    assert cookie_info_map(driver)[f"{sub_state_name}.c5_rx_state_"] == {
         "domain": "localhost",
         "httpOnly": False,
-        "name": f"{sub_state_name}.c5",
+        "name": f"{sub_state_name}.c5" + "_rx_state_",
         "path": "/foo/",
         "sameSite": "Lax",
         "secure": False,