Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: routerized links#4628

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
jprosevear wants to merge2 commits intoheroui-inc:canary
base:canary
Choose a base branch
Loading
fromcodalio:fix/routerized-links

Conversation

jprosevear
Copy link

@jprosevearjprosevear commentedJan 23, 2025
edited by coderabbitaibot
Loading

Closes#4624

📝 Description

Use the routerized href if available for both the onClick event and the href prop on the element

⛳️ Current behavior (updates)

Currently the original href is used (ignoring the application of useHref) on the onClick and so navigate() for react-router acts on the wrong href and fails for relative links. So if you are at /blogs already and you put href="14" it will try to go to /14 instead of /blogs/14 and the href is decorate with href="14"

🚀 New behavior

navigate() for react-router works, going to /blogs/14 and the element is decorated correctly (/blogs/14) .

💣 Is this a breaking change (Yes/No):

Possible, but I don't think it worked before with relative links in RR; absolute links should still work.

📝 Additional Information

Summary by CodeRabbit

  • Improvements

    • Enhanced link component functionality with improvedhref handling.
    • Added default values forautoFocus,isExternal, andshowAnchorIcon properties.
    • Refined routing and navigation logic for link components.
  • Accessibility

    • Updated link component to better support external links and routing behavior.

@changeset-botchangeset-bot
Copy link

changeset-botbot commentedJan 23, 2025
edited
Loading

⚠️ No Changeset found

Latest commit:9f13a25

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go.If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@vercelVercel
Copy link

vercelbot commentedJan 23, 2025

@jprosevear is attempting to deploy a commit to theHeroUI Inc Team onVercel.

A member of the Team first needs toauthorize it.

@coderabbitaicoderabbitai
Copy link
Contributor

coderabbitaibot commentedJan 23, 2025
edited
Loading

Walkthrough

The pull request addresses a bug in the link component's handling of thehref property, specifically focusing on how router-based links are processed. The changes modify theuseLink anduseAriaLink functions to ensure proper preservation of thehref attribute from router-related props. The modifications aim to improve the link navigation behavior, particularly for relative links in React Router environments.

Changes

FileChange Summary
packages/components/link/src/use-link.ts- Addedhref toProps interface
- Includedhref ingetLinkProps function
- Added default values forautoFocus,isExternal, andshowAnchorIcon
packages/hooks/use-aria-link/src/index.ts- Updated navigation logic to userouterLinkProps.href
- ModifiedonClick event handler to reference router link properties

Assessment against linked issues

ObjectiveAddressedExplanation
Fix link navigation for relative links [#4624]
Preserve router-generatedhref [#4624]

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and betweeneff03db and9f13a25.

📒 Files selected for processing (2)
  • packages/components/link/src/use-link.ts (3 hunks)
  • packages/hooks/use-aria-link/src/index.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • packages/hooks/use-aria-link/src/index.ts
  • packages/components/link/src/use-link.ts

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat withCodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag@coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag@coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings togenerate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add@coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add@coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add@coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit ourDocumentation for detailed information on how to use CodeRabbit.
  • Join ourDiscord Community to get help, request features, and share feedback.
  • Follow us onX/Twitter for updates and announcements.

"data-disabled":dataAttr(originalProps.isDisabled),
"data-focus-visible":dataAttr(isFocusVisible),
// The `href` prop may be routerized by useAriaLink, so we may merge over top of it
href,
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This makes sure that the href on the is set properly

){
e.preventDefault();
router.open(e.currentTarget,e,props.href,props.routerOptions);
router.open(e.currentTarget,e,routerLinkProps.href,props.routerOptions);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This makes sure that we use the useHref'ed href for the navigation

@jprosevearjprosevear changed the titleFix/routerized links(fix): routerized linksJan 24, 2025
@jprosevearjprosevear changed the title(fix): routerized linksfix: routerized linksJan 24, 2025
@wingkwongwingkwong self-assigned thisJan 24, 2025
@wingkwongwingkwong modified the milestones:v2.6.15,v2.7.0Jan 25, 2025
@wingkwong
Copy link
Member

may revisit this PR again after#4611

@jprosevear
Copy link
Author

may revisit this PR again after#4611

Is the hope that the upgrade will fix this or something else?

@wingkwong
Copy link
Member

@jprosevear RA recently bumped their version and we are still using the second last latest version. The version diff would cause some routing issues. So I wanna double check again after syncing the versions.

@jprosevear
Copy link
Author

@jprosevear RA recently bumped their version and we are still using the second last latest version. The version diff would cause some routing issues. So I wanna double check again after syncing the versions.

Ok, but based on my patch and investigation the issue is that RA was returning the right info already, it just wasn't being used correctly in Hero.

@jprosevear
Copy link
Author

Rebased.

@wingkwong
Copy link
Member

@jprosevear do you have a simple sandbox that can reproduce the issue? I need it to test the before & after.

@jprosevear
Copy link
Author

@jprosevear do you have a simple sandbox that can reproduce the issue? I need it to test the before & after.

I do not, unless there is a good starting point for heroui / RR (or Tanstack Router, as per Discord I think it has the same problem) its probably a couple hours of work at least is my guess which is possible but painful obviously.

What is the right thing to do from a testing infrastructure standpoint long term?

Copy link
Member

@wingkwongwingkwong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

FYI, ouruse-aria-link mirrorsuseLink from@react-aria. We modified the deprecated warning part only. I think navigating torouterLinkProps.href isn't expected since it will cover the current path.

"data-disabled":dataAttr(originalProps.isDisabled),
"data-focus-visible":dataAttr(isFocusVisible),
// The `href` prop may be routerized by useAriaLink, so we may merge over top of it
href,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

href fromlinkProps in L117 will override thishref in L116 so all changes done in this file don't really do anything.

p.s.href fromlinkProps in L117 is routerized, i.e.1 ->/blogs/1, which is expected. What's the reason to put prop.href here?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

In case you are not using a routerized link you still need the original href I thought

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

href will be passed touseLinkProps, and eventually it will be inlinkProps anyway.

Copy link
Author

@jprosevearjprosevearJan 31, 2025
edited
Loading

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It still needs to be extracted from otherProps though so mergeProps doesn't overwrite the linkProps href with the otherProps href.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

the key for me is that useLinkProps canchange href

const{linkProps}=useAriaLink(
{
...otherProps,
href,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

href originally is inotherProps

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I know; see below.

){
e.preventDefault();
router.open(e.currentTarget,e,props.href,props.routerOptions);
router.open(e.currentTarget,e,routerLinkProps.href,props.routerOptions);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

by doing so, one couldn't do any absolute paths, e.g. says I'm at/blogs and if i sethref to/foo/1, I will be navigated to/blogs//foo/1 instead of/foo/1.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Why not? useHref from RR should produce /foo/1 in that case. I updatedhttps://stackblitz.com/edit/wfdcu9f2 with that case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

RRLink can navigate to/foo/1correctly. With your PR change, I got//blogs/foo/1. Note that even I'm at/blogs originally, it would still add the slash causing// at the end. You may link those components locally to play around.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

https://github.com/adobe/react-spectrum/blob/016590a4afc585eea18d5a12853c9d1e2d82a19c/packages/%40react-aria/utils/src/openLink.tsx#L174 for reference - unless the useLinkProps href is used, why call it it at all? Also, if the href is something like "https://www.heroui.com/" i believe the router.open call won't be made on it, a regular link will happen.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

RRLink can navigate to/foo/1correctly. With your PR change, I got//blogs/foo/1. Note that even I'm at/blogs originally, it would still add the slash causing// at the end. You may link those components locally to play around.

Can you give more details? All this patch really does is ensure the href produced by useLinkProps from react-aria is actually used in Hero (at least that was my intention)

@jprosevear
Copy link
Author

@jprosevear do you have a simple sandbox that can reproduce the issue? I need it to test the before & after.

I do not, unless there is a good starting point for heroui / RR (or Tanstack Router, as per Discord I think it has the same problem) its probably a couple hours of work at least is my guess which is possible but painful obviously.

What is the right thing to do from a testing infrastructure standpoint long term?

https://stackblitz.com/edit/wfdcu9f2

@wingkwong
Copy link
Member

UPD: was using the outdated stackblitz for my initial review. will take a look again.

@jprosevearjprosevear marked this pull request as draftFebruary 10, 2025 15:08
@jrgarciadevjrgarciadev modified the milestones:v2.7.0,v2.7.1Feb 11, 2025
@jprosevear
Copy link
Author

Upstream discussion:adobe/react-spectrum#7695

@jprosevear
Copy link
Author

@jrgarciadev I would not include this in 2.7.x until there is some resolution upstream

@wingkwongwingkwong removed this from thev2.7.3 milestoneFeb 19, 2025
@wingkwongwingkwong removed their assignmentFeb 19, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@wingkwongwingkwongwingkwong left review comments

@jrgarciadevjrgarciadevAwaiting requested review from jrgarciadevjrgarciadev is a code owner

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

[BUG] - useLink overwrites router-ized prop
3 participants
@jprosevear@wingkwong@jrgarciadev

[8]ページ先頭

©2009-2025 Movatter.jp