Allow navigate component to accept integers for go back/forward#56
Merged
Conversation
The `navigate()` component now accepts `str | int` for the `to` parameter. When an integer is provided, the JS-side uses `history.go(to)` to perform relative navigation in the browser's history stack (e.g. `navigate(-1)` to go back, `navigate(1)` to go forward). Key changes: - Python: `navigate(to: str | int, ...)` — integer paths bypass path-matching logic and always render the JS Navigate component - JS: `Navigate` component checks `typeof to === "number"` and calls `window.history.go(to)`; the resulting popstate event is handled by the existing History component - JS: `NavigateProps.to` type updated to `string | number` - Tests: Added `test_navigate_component_go_back` and `test_navigate_component_go_forward` E2E tests Closes #52
…utton content When navigate() was rendered as a child of html.button(), the Navigate component's JS null-render left the button with empty text. Changed tests to return navigate() at the component level instead.
Python's bool is a subclass of int, so isinstance(True, int) is True. Add explicit not isinstance(to, bool) guard to prevent booleans from being misinterpreted as relative history navigation.
Pyright correctly flags that `isinstance(to, bool)` doesn't narrow the `str | int` union since `bool` is a subclass of `int`. Use `type(to) is int` for a strict exact-type check that both satisfies the type checker and correctly excludes booleans.
Pyright cannot narrow to str after isinstance(to, int) since bool is a subclass of int. Wrapping the string-only code path in an explicit isinstance(to, str) check resolves the type error.
Archmonger
marked this pull request as ready for review
July 21, 2026 12:35
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Allow the
navigatecomponent to accept integers for thetoparameter, enabling relative navigation in the browser's history stack — e.g.,navigate(-1)to go back,navigate(1)to go forward.This works by:
toparameter typed asstr | int. When an integer is received, the path-matching comparison is skipped (since an integer has no path to compare), and the JS-side Navigate component is always rendered.Navigatecomponent checkstypeof to === "number"and callswindow.history.go(to). The resultingpopstateevent is handled by the existingHistorycomponent, which already updates the server-side location state — so no duplicate callback is needed.NavigateProps.toupdated tostring | number.Checklist
Closes #52
By submitting this pull request I agree that all contributions comply with this project's open source license(s).