Skip to content

Commit

Permalink
Fix clearing query params when navigating (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwillchen authored Nov 10, 2024
1 parent 8efc807 commit 3d6028f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 1 addition & 4 deletions mesop/commands/navigate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@
from mesop.features.query_params import (
QueryParams,
)
from mesop.features.query_params import (
query_params as me_query_params,
)
from mesop.runtime import runtime
from mesop.utils.url_utils import remove_url_query_param
from mesop.warn import warn
Expand Down Expand Up @@ -35,5 +32,5 @@ def navigate(

# Clear the query params because the query params will
# either be replaced with the new query_params or emptied (in server.py).
me_query_params.clear()
runtime().context().query_params().clear()
runtime().context().navigate(cleaned_url, query_params)
18 changes: 18 additions & 0 deletions mesop/tests/e2e/query_params_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,24 @@ test('query_param: navigate to another page with query params', async ({
expect(new URL(page.url()).search).toEqual('?on_load=loaded');
});

test('query_param: back nav preserves query params', async ({page}) => {
await page.goto('/examples/query_params');
await page
.getByRole('button', {name: 'navigate to page 2 without query params'})
.click();

// Make sure navigation to page 2 has completed
await expect(page.getByText('query_params(page_2)={}')).toBeVisible();
// Navigate back to page 1
await page.goBack();

// Assert the query params are preserved.
await expect(
page.getByText(`query_params={'on_load': ['loaded']}`),
).toBeVisible();
expect(new URL(page.url()).search).toEqual('?on_load=loaded');
});

test('query_param: navigate to another page with dict', async ({page}) => {
await page.goto('/examples/query_params');
await page
Expand Down

0 comments on commit 3d6028f

Please sign in to comment.