Skip to content
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

Fix synthetic links not using useHref #6346

Merged
merged 2 commits into from
Jun 12, 2024

Conversation

joshuajaco
Copy link
Contributor

@joshuajaco joshuajaco commented May 8, 2024

Closes #6347

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@joshuajaco joshuajaco force-pushed the fix-synthetic-links-with-basepath branch 2 times, most recently from fba1ec8 to 33ca102 Compare May 8, 2024 14:18
@joshuajaco joshuajaco marked this pull request as ready for review May 8, 2024 14:31
@joshuajaco joshuajaco force-pushed the fix-synthetic-links-with-basepath branch 2 times, most recently from 9fc618c to c0a5c54 Compare May 10, 2024 09:36
Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

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

Thanks, this makes sense.

return {
'data-href': props.href,
'data-href': props.href ? router.useHref(props.href) : undefined,
Copy link
Member

Choose a reason for hiding this comment

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

This could cause issues due to a hook being called conditionally. If we're sure that there is always an href when this function is called, we could probably make href required in the type.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree that this can cause issues, however I directly mirrored the implementation of useLinkProps:

export function useLinkProps(props: LinkDOMProps) {
let router = useRouter();
return {
href: props?.href ? router.useHref(props?.href) : undefined,
target: props?.target,
rel: props?.rel,
download: props?.download,
ping: props?.ping,
referrerPolicy: props?.referrerPolicy
};
}

Also useSyntheticLinkProps is used in useGridListItem, where we do not always have an href.

If we want to prevent useHref from being called conditionally we would have to instead split up useGridListItem in to two hooks, one with href and one without. We'd also have to conditionally render between two components everywhere useGridListItem is used to swap between the two new hooks.

Alternatively we could call useHref with an empty string. After a quick search this seems to be a valid href according to this detailed stackoverflow comment.

Copy link
Member

Choose a reason for hiding this comment

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

ok if it was there before I guess it's probably fine for now.

@devongovett devongovett merged commit a4dee6e into adobe:main Jun 12, 2024
26 checks passed
@joshuajaco joshuajaco deleted the fix-synthetic-links-with-basepath branch June 12, 2024 06:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

useHref passed to RouterProvider not respected for synthetic links
3 participants