Skip to content

[2.x] Allow custom component on Link "as" prop in React and Vue3 #2264

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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

SuperDJ
Copy link

@SuperDJ SuperDJ commented Mar 4, 2025

This PR is based on the changes made in #1940 and so all credits should go to @guizoxxv

This has atleast been requested in: #1550, #1654, #1668 and #1746 as well.

Could also solve vuetifyjs/vuetify#11573.

@chasegiunta
Copy link

@joetannenbaum Can this be merged?

SuperDJ added 2 commits April 16, 2025 09:04
# Conflicts:
#	packages/react/src/Link.ts
#	packages/vue3/src/link.ts
@SuperDJ
Copy link
Author

SuperDJ commented Apr 16, 2025

@joetannenbaum is there anything that needs to be done before this can be merged?

@motionshots
Copy link

What's the hold up? All checks seems like have passed, why is this still not merged? It's something that is really needed. Why is this PR being ignored?

@joetannenbaum
Copy link
Contributor

Sorry for the lack of communication here, I've been thinking about this PR for a while now.

While I understand the need being addressed here, I don't think this is the way I'd like to go about solving it for two primary reasons:

  • It's a bit opaque, hard to say what props are being spread onto the custom component under the hood from looking at it
  • I can see this opening up a can of worms where we're getting a flood of issues such as "Link component doesn't work with UI library X"

I'd rather invert the solution, something like (totally theoretical, still working on this):

const asLink = useAsLink();

return (
   <MyCustomLink {...asLink('/users', { prefetch: true })} />
);

Benefits are:

  • You know exactly which props are coming from asLink and can include/exclude them as you wish
  • If there are prop collisions, you can alias them in the spread
  • Link itself can use this under the hood to ensure behavior is exactly the same

This is on my list of PRs to examine in the next two weeks.

@chasegiunta
Copy link

chasegiunta commented Jun 2, 2025

Appreciate the response @joetannenbaum . I tend to think it would operate similarly to Vue's native :is functionality where props would fall through to the custom component. In the rare scenario for a collision, the user could use a 2nd argument: eg

<Link href="/dashboard" :as="Button, { collisionProp: 'value' }">

I'm not fully confident this would be better, just giving another DX alternative that could perhaps keep the same native-feeling behavior as before, while still providing an escape hatch for the rare prop collision scenario. This would also avoid having multiple ways for overriding the Link element.

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.

4 participants