Skip to content

Commit 36665c1

Browse files
committed
try stuff with prerender
1 parent 1209e12 commit 36665c1

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

reflex/.templates/web/app/routes.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { flatRoutes } from "@react-router/fs-routes";
33

44
export default [
55
route("*", "routes/[404]_._index.js"),
6+
route("404", "routes/[404]_._index.js", { id: "404" }),
67
...(await flatRoutes({
78
ignoredRouteFiles: ["routes/\\[404\\]_._index.js"],
89
})),

reflex/testing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@ def _run_frontend(self):
957957
/ reflex.constants.Dirs.STATIC
958958
)
959959
error_page_map = {
960-
404: web_root / "404.html",
960+
404: web_root / "404" / "index.html",
961961
}
962962
with Subdir404TCPServer(
963963
("", 0),

reflex/utils/prerequisites.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,6 +1101,7 @@ def _update_react_router_config(config: Config, export: bool = False):
11011101
"unstable_optimizeDeps": True,
11021102
},
11031103
"ssr": False,
1104+
"prerender": True,
11041105
}
11051106

11061107
if export:

tests/integration/test_dynamic_routes.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ async def test_on_load_navigate(
273273
link.click()
274274
assert urlsplit(driver.current_url).path == f"/page/{ix}"
275275

276-
link = driver.find_element(By.ID, "link_page_next")
276+
link = dynamic_route.poll_for_result(
277+
lambda: driver.find_element(By.ID, "link_page_next")
278+
)
277279
page_id_input = driver.find_element(By.ID, "page_id")
278280
raw_path_input = driver.find_element(By.ID, "raw_path")
279281

@@ -283,7 +285,7 @@ async def test_on_load_navigate(
283285
assert dynamic_route.poll_for_value(
284286
page_id_input, exp_not_equal=str(ix - 1)
285287
) == str(ix)
286-
assert dynamic_route.poll_for_value(raw_path_input) == f"/page/{ix}/"
288+
assert dynamic_route.poll_for_value(raw_path_input) == f"/page/{ix}"
287289
await poll_for_order(exp_order)
288290

289291
# manually load the next page to trigger client side routing in prod mode
@@ -341,7 +343,7 @@ async def test_on_load_navigate(
341343
driver.get(f"{dynamic_route.frontend_url}/redirect-page/0/?foo=bar")
342344
await poll_for_order(exp_order)
343345
# should have redirected back to page 0
344-
assert urlsplit(driver.current_url).path == "/page/0/"
346+
assert urlsplit(driver.current_url).path.removesuffix("/") == "/page/0"
345347

346348

347349
@pytest.mark.asyncio
@@ -370,12 +372,12 @@ async def test_on_load_navigate_non_dynamic(
370372
link = driver.find_element(By.ID, "link_index")
371373
with poll_for_navigation(driver):
372374
link.click()
373-
assert urlsplit(driver.current_url).path == "/"
375+
assert urlsplit(driver.current_url).path.removesuffix("/") == ""
374376

375377
link = driver.find_element(By.ID, "link_page_x")
376378
with poll_for_navigation(driver):
377379
link.click()
378-
assert urlsplit(driver.current_url).path == "/static/x/"
380+
assert urlsplit(driver.current_url).path.removesuffix("/") == "/static/x"
379381
await poll_for_order(["/static/x-no page id", "/static/x-no page id"])
380382

381383

@@ -422,11 +424,11 @@ def assert_content(expected: str, expect_not: str):
422424
assert next_page_link
423425
with poll_for_navigation(driver):
424426
next_page_link.click()
425-
assert driver.current_url == f"{dynamic_route.frontend_url}/arg/1/"
427+
assert driver.current_url.removesuffix("/") == f"{dynamic_route.frontend_url}/arg/1"
426428
assert_content("1", "0")
427429
next_page_link = driver.find_element(By.ID, "next-page")
428430
assert next_page_link
429431
with poll_for_navigation(driver):
430432
next_page_link.click()
431-
assert driver.current_url == f"{dynamic_route.frontend_url}/arg/2/"
433+
assert driver.current_url.removesuffix("/") == f"{dynamic_route.frontend_url}/arg/2"
432434
assert_content("2", "1")

0 commit comments

Comments
 (0)