-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ENG-6503: use react-router Link instead of rx.el.a #5529
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2bd91ca
ENG-6503: use react-router Link instead of rx.el.a
masenf 21f316a
Lazily resolve imports to avoid circular dependency
masenf e77f9ae
Update test expectations "a" -> ReactRouterLink
masenf 2104fc5
Update ReactRouterLink _invalid_children
masenf 6450957
update pyi_hashes.json
masenf 34c4d7c
Merge remote-tracking branch 'origin/main' into masenf/react-router-link
masenf a62d5ad
Merge branch 'main' into masenf/react-router-link
masenf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,6 +14,7 @@ | |
| "plotly", | ||
| "radix", | ||
| "react_player", | ||
| "react_router", | ||
| "sonner", | ||
| "el", | ||
| "base", | ||
|
|
||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| """React-router internal components.""" | ||
|
|
||
| from .dom import ReactRouterLink | ||
|
|
||
| link = ReactRouterLink.create | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| """Components for client side navigation within React Router applications.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from typing import ClassVar, Literal, TypedDict | ||
|
|
||
| from reflex.components.el.elements.inline import A | ||
| from reflex.vars.base import Var | ||
|
|
||
| LiteralLinkDiscover = Literal["none", "render"] | ||
|
|
||
|
|
||
| class To(TypedDict): | ||
| """Structured object for navigating via the `to` prop.""" | ||
|
|
||
| # A URL pathname, beginning with a / | ||
| pathname: str | ||
|
|
||
| # A URL search string, beginning with a ?. | ||
| search: str | ||
|
|
||
| # A URL fragment identifier, beginning with a #. | ||
| hash: str | ||
|
|
||
|
|
||
| class ReactRouterLink(A): | ||
| """Links are accessible elements used primarily for navigation. This component is styled to resemble a hyperlink and semantically renders an <a>.""" | ||
|
|
||
| library = "react-router" | ||
|
|
||
| tag = "Link" | ||
|
|
||
| alias = "ReactRouterLink" | ||
|
|
||
| # The page to link to. | ||
| to: Var[str | To] | ||
|
|
||
| # Replaces the current entry in the history stack instead of pushing a new one onto it. | ||
| replace: Var[bool] | ||
|
|
||
| # Will use document navigation instead of client side routing when the link is clicked: the browser will handle the transition normally (as if it were an <a href>). | ||
| reload_document: Var[bool] | ||
|
|
||
| # Prevents the scroll position from being reset to the top of the window when the link is clicked and the app is using ScrollRestoration. This only prevents new locations resetting scroll to the top, scroll position will be restored for back/forward button navigation. | ||
| prevent_scroll_reset: Var[bool] | ||
|
|
||
| # Defines the link discovery behavior | ||
| discover: Var[LiteralLinkDiscover] | ||
|
|
||
| # Enables a View Transition for this navigation. | ||
| view_transition: Var[bool] | ||
|
|
||
| @classmethod | ||
| def create(cls, *children, **props): | ||
| """Create a ReactRouterLink component for client-side navigation. | ||
|
|
||
| Args: | ||
| *children: The children of the component. | ||
| **props: The props of the component. | ||
|
|
||
| Returns: | ||
| The ReactRouterLink component. | ||
| """ | ||
| # React Router special behavior is triggered on the `to` prop, not href. | ||
| if "to" not in props and "href" in props: | ||
| props["to"] = props.pop("href") | ||
| return super().create(*children, **props) | ||
|
|
||
| _invalid_children: ClassVar[list[str]] = ["A", "ReactRouterLink"] |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: Consider adding type hints here for better IDE support and type safety:
link: Callable[..., Component] = ReactRouterLink.create