Skip to content

Commit efb97c8

Browse files
committed
always send on load even on going on the link
1 parent 0ba251d commit efb97c8

2 files changed

Lines changed: 14 additions & 23 deletions

File tree

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

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,30 +1022,15 @@ export const useEventLoop = (
10221022

10231023
// Route after the initial page hydration
10241024
useEffect(() => {
1025-
// This will run when the location changes
1026-
if (
1027-
location.pathname + location.search + location.hash !==
1028-
prevLocationRef.current.pathname +
1029-
prevLocationRef.current.search +
1030-
prevLocationRef.current.hash
1031-
) {
1032-
// Equivalent to routeChangeStart - runs when navigation begins
1033-
const change_start = () => {
1034-
const main_state_dispatch = dispatch["reflex___state____state"];
1035-
if (main_state_dispatch !== undefined) {
1036-
main_state_dispatch({ is_hydrated_rx_state_: false });
1037-
}
1038-
};
1039-
change_start();
1040-
1041-
// Equivalent to routeChangeComplete - runs after navigation completes
1042-
const change_complete = () => addEvents(onLoadInternalEvent());
1043-
change_complete();
1044-
1045-
// Update the ref
1046-
prevLocationRef.current = location;
1025+
// Equivalent to routeChangeStart - runs when navigation begins
1026+
const main_state_dispatch = dispatch["reflex___state____state"];
1027+
if (main_state_dispatch !== undefined) {
1028+
main_state_dispatch({ is_hydrated_rx_state_: false });
10471029
}
1048-
}, [location, dispatch, onLoadInternalEvent, addEvents]);
1030+
1031+
// Equivalent to routeChangeComplete - runs after navigation completes
1032+
addEvents(onLoadInternalEvent());
1033+
}, [location]);
10491034

10501035
return [addEvents, connectErrors];
10511036
};

tests/integration/test_dynamic_routes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,12 @@ async def test_on_load_navigate_non_dynamic(
386386
assert urlsplit(driver.current_url).path.removesuffix("/") == "/static/x"
387387
await poll_for_order(["/static/x-no page id", "/static/x-no page id"])
388388

389+
for _ in range(3):
390+
link = driver.find_element(By.ID, "link_page_x")
391+
link.click()
392+
assert urlsplit(driver.current_url).path.removesuffix("/") == "/static/x"
393+
await poll_for_order(["/static/x-no page id"] * 5)
394+
389395

390396
@pytest.mark.asyncio
391397
async def test_render_dynamic_arg(

0 commit comments

Comments
 (0)