Skip to content

Commit cf0cc12

Browse files
committed
fix is hydrated
1 parent ec07336 commit cf0cc12

2 files changed

Lines changed: 35 additions & 26 deletions

File tree

reflex/.templates/web/utils/state.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,10 @@ const applyClientStorageDelta = (client_storage, delta) => {
710710
);
711711
if (unqualified_states.length === 1) {
712712
const main_state = delta[unqualified_states[0]];
713-
if (main_state.is_hydrated !== undefined && !main_state.is_hydrated) {
713+
if (
714+
main_state.is_hydrated_rx_state_ !== undefined &&
715+
!main_state.is_hydrated_rx_state_
716+
) {
714717
// skip if the state is not hydrated yet, since all client storage
715718
// values are sent in the hydrate event
716719
return;
@@ -933,7 +936,7 @@ export const useEventLoop = (
933936
const change_start = () => {
934937
const main_state_dispatch = dispatch["reflex___state____state"];
935938
if (main_state_dispatch !== undefined) {
936-
main_state_dispatch({ is_hydrated: false });
939+
main_state_dispatch({ is_hydrated_rx_state_: false });
937940
}
938941
};
939942
const change_complete = () => addEvents(onLoadInternalEvent());

tests/integration/test_client_storage.py

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -352,28 +352,28 @@ def set_sub_sub(var: str, value: str):
352352
)
353353

354354
exp_cookies = {
355-
f"{sub_state_name}.c1": {
355+
f"{sub_state_name}.c1" + "_rx_state_": {
356356
"domain": "localhost",
357357
"httpOnly": False,
358-
"name": f"{sub_state_name}.c1",
358+
"name": f"{sub_state_name}.c1" + "_rx_state_",
359359
"path": "/",
360360
"sameSite": "Lax",
361361
"secure": False,
362362
"value": "c1%20value",
363363
},
364-
f"{sub_state_name}.c2": {
364+
f"{sub_state_name}.c2" + "_rx_state_": {
365365
"domain": "localhost",
366366
"httpOnly": False,
367-
"name": f"{sub_state_name}.c2",
367+
"name": f"{sub_state_name}.c2" + "_rx_state_",
368368
"path": "/",
369369
"sameSite": "Lax",
370370
"secure": False,
371371
"value": "c2%20value",
372372
},
373-
f"{sub_state_name}.c4": {
373+
f"{sub_state_name}.c4" + "_rx_state_": {
374374
"domain": "localhost",
375375
"httpOnly": False,
376-
"name": f"{sub_state_name}.c4",
376+
"name": f"{sub_state_name}.c4" + "_rx_state_",
377377
"path": "/",
378378
"sameSite": "Strict",
379379
"secure": False,
@@ -388,19 +388,19 @@ def set_sub_sub(var: str, value: str):
388388
"secure": False,
389389
"value": "c6%20value",
390390
},
391-
f"{sub_state_name}.c7": {
391+
f"{sub_state_name}.c7" + "_rx_state_": {
392392
"domain": "localhost",
393393
"httpOnly": False,
394-
"name": f"{sub_state_name}.c7",
394+
"name": f"{sub_state_name}.c7" + "_rx_state_",
395395
"path": "/",
396396
"sameSite": "Lax",
397397
"secure": False,
398398
"value": "c7%20value",
399399
},
400-
f"{sub_sub_state_name}.c1s": {
400+
f"{sub_sub_state_name}.c1s" + "_rx_state_": {
401401
"domain": "localhost",
402402
"httpOnly": False,
403-
"name": f"{sub_sub_state_name}.c1s",
403+
"name": f"{sub_sub_state_name}.c1s" + "_rx_state_",
404404
"path": "/",
405405
"sameSite": "Lax",
406406
"secure": False,
@@ -418,13 +418,15 @@ def set_sub_sub(var: str, value: str):
418418

419419
# Test cookie with expiry by itself to avoid timing flakiness
420420
set_sub("c3", "c3 value")
421-
AppHarness._poll_for(lambda: f"{sub_state_name}.c3" in cookie_info_map(driver))
422-
c3_cookie = cookie_info_map(driver)[f"{sub_state_name}.c3"]
421+
AppHarness._poll_for(
422+
lambda: f"{sub_state_name}.c3" + "_rx_state_" in cookie_info_map(driver)
423+
)
424+
c3_cookie = cookie_info_map(driver)[f"{sub_state_name}.c3" + "_rx_state_"]
423425
assert c3_cookie.pop("expiry") is not None
424426
assert c3_cookie == {
425427
"domain": "localhost",
426428
"httpOnly": False,
427-
"name": f"{sub_state_name}.c3",
429+
"name": f"{sub_state_name}.c3" + "_rx_state_",
428430
"path": "/",
429431
"sameSite": "Lax",
430432
"secure": False,
@@ -433,24 +435,26 @@ def set_sub_sub(var: str, value: str):
433435
time.sleep(2) # wait for c3 to expire
434436
if not isinstance(driver, Firefox):
435437
# Note: Firefox does not remove expired cookies Bug 576347
436-
assert f"{sub_state_name}.c3" not in cookie_info_map(driver)
438+
assert f"{sub_state_name}.c3_rx_state_" not in cookie_info_map(driver)
437439

438440
local_storage_items = local_storage.items()
439441
local_storage_items.pop("last_compiled_time", None)
440442
local_storage_items.pop("theme", None)
441-
assert local_storage_items.pop(f"{sub_state_name}.l1") == "l1 value"
442-
assert local_storage_items.pop(f"{sub_state_name}.l2") == "l2 value"
443+
assert local_storage_items.pop(f"{sub_state_name}.l1_rx_state_") == "l1 value"
444+
assert local_storage_items.pop(f"{sub_state_name}.l2_rx_state_") == "l2 value"
443445
assert local_storage_items.pop("l3") == "l3 value"
444-
assert local_storage_items.pop(f"{sub_state_name}.l4") == "l4 value"
445-
assert local_storage_items.pop(f"{sub_sub_state_name}.l1s") == "l1s value"
446+
assert local_storage_items.pop(f"{sub_state_name}.l4_rx_state_") == "l4 value"
447+
assert local_storage_items.pop(f"{sub_sub_state_name}.l1s_rx_state_") == "l1s value"
446448
assert not local_storage_items
447449

448450
session_storage_items = session_storage.items()
449451
session_storage_items.pop("token", None)
450-
assert session_storage_items.pop(f"{sub_state_name}.s1") == "s1 value"
451-
assert session_storage_items.pop(f"{sub_state_name}.s2") == "s2 value"
452+
assert session_storage_items.pop(f"{sub_state_name}.s1_rx_state_") == "s1 value"
453+
assert session_storage_items.pop(f"{sub_state_name}.s2_rx_state_") == "s2 value"
452454
assert session_storage_items.pop("s3") == "s3 value"
453-
assert session_storage_items.pop(f"{sub_sub_state_name}.s1s") == "s1s value"
455+
assert (
456+
session_storage_items.pop(f"{sub_sub_state_name}.s1s_rx_state_") == "s1s value"
457+
)
454458
assert not session_storage_items
455459

456460
assert c1.text == "c1 value"
@@ -561,11 +565,13 @@ def set_sub_sub(var: str, value: str):
561565
assert s1s.text == "s1s value"
562566

563567
# make sure c5 cookie shows up on the `/foo` route
564-
AppHarness._poll_for(lambda: f"{sub_state_name}.c5" in cookie_info_map(driver))
565-
assert cookie_info_map(driver)[f"{sub_state_name}.c5"] == {
568+
AppHarness._poll_for(
569+
lambda: f"{sub_state_name}.c5_rx_state_" in cookie_info_map(driver)
570+
)
571+
assert cookie_info_map(driver)[f"{sub_state_name}.c5_rx_state_"] == {
566572
"domain": "localhost",
567573
"httpOnly": False,
568-
"name": f"{sub_state_name}.c5",
574+
"name": f"{sub_state_name}.c5" + "_rx_state_",
569575
"path": "/foo/",
570576
"sameSite": "Lax",
571577
"secure": False,

0 commit comments

Comments
 (0)