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

Refactor Anchor component to correctly detect all URLs #4090

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hichemfantar
Copy link
Contributor

@hichemfantar hichemfantar commented Jan 28, 2025

Why:

correctly handles all types of links, local, anchor, external, http, https, and other kinds

use client doesn't disable ssr

What's being changed (if available, include any code snippets, screenshots, or gifs):

Check off the following:

  • I have reviewed my changes in staging, available via the View
    deployment
    link in this PR's timeline (this link will be available after
    opening the PR).

Copy link

changeset-bot bot commented Jan 28, 2025

⚠️ No Changeset found

Latest commit: d5726cc

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

Copy link

vercel bot commented Jan 28, 2025

@hichemfantar is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

Copy link

vercel bot commented Jan 28, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
nextra-v2 ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jan 28, 2025 2:21pm
1 Skipped Deployment
Name Status Preview Comments Updated (UTC)
nextra ⬜️ Ignored (Inspect) Visit Preview Jan 28, 2025 2:21pm

Copy link
Collaborator

@dimaMachina dimaMachina left a comment

Choose a reason for hiding this comment

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

I don't think we need to convert this component to client.

What is the difference of the current approach by yours for detecting external URL?

@hichemfantar
Copy link
Contributor Author

hichemfantar commented Jan 28, 2025

the current approach breaks very easily when the user passes unexpected urls that the browser can easily resolve by itself.

e.g. "/#heading" is correct, http is also viable, also what if the user passes a different protocol? you can make all these checks but there's always something you could miss and all of this is handled by the js api.

use client is no issue because the component is still rendered server side

use client doesn't disable ssr which is a common misconception

image

@dimaMachina
Copy link
Collaborator

you can make all these checks but there's always something you could miss and all of this is handled by the js API.

we don't want to check everything just https? is fine

I don't want to overcomplicate this component, I don't see convincing arguments

@hichemfantar
Copy link
Contributor Author

hichemfantar commented Jan 28, 2025

There are many variations of urls that aren’t being checked.

What if the component resolves incorrectly and the user can’t override the behavior?

If you’re sure you don’t wanna go through with this then the best solution is to get rid of the fragile auto detection and allow a prop “external” that the user can pass. This way the user isn’t stuck when the inference fails

@hichemfantar
Copy link
Contributor Author

Also what if it’s an http url that points to the same website?

@dimaMachina
Copy link
Collaborator

Also what if it’s an http url that points to the same website?

We can't handle every case, but if you want in your website - you can by passing custom a components in mdx-components and fix this case

@hichemfantar
Copy link
Contributor Author

Also what if it’s an http url that points to the same website?

We can't handle every case, but if you want in your website - you can by passing custom a components in mdx-components and fix this case

That’s exactly the point of this pr, it allows you to detect every case

you could however keep the existing implementation and add an extra prop “external” to override when needed

@hichemfantar
Copy link
Contributor Author

you can make all these checks but there's always something you could miss and all of this is handled by the js API.

we don't want to check everything just https? is fine

I don't want to overcomplicate this component, I don't see convincing arguments

The component is already complex because it has implicit undocumented behavior

@dimaMachina
Copy link
Collaborator

it was documented in blogpost https://the-guild.dev/blog/nextra-4#markdown-links-changes

@hichemfantar
Copy link
Contributor Author

hichemfantar commented Jan 28, 2025

blogs aren't documentation however, blogs are generally for old users that are looking to migrate and news. new users won't know about this, especially since it doesn't show up in search

this should be documented in the documentation itself under the link section. also migration guides should be included directly in the documentation. navigating to a blog on another website is bad ux. even i didn't know about this

example https://docusaurus.io/docs/migration/v3

@dimaMachina
Copy link
Collaborator

blogs aren't documentation however, blogs are generally for old users that are looking to migrate and news. new users won't know about this, especially since it doesn't show up in search

I can't do everything sorry, it's an Open Source project where I am a one maintainer which I maintain based on my free time

@hichemfantar
Copy link
Contributor Author

That's what my PRs are for, I'm willing to work with you but I also need to know my efforts won't be blocked when the solution is proper and doesn't cause any regressions.
If you're willing to be flexible, we can make nextra pretty good and properly compete with other established solutions.

there's nothing more frustrating than finding a limitation or hard coded behavior that can easily be made flexible.
Do reconsider

@hichemfantar
Copy link
Contributor Author

i have a lot of experience working with documentation generators, i'm willing to share my experience in form of PRs and help make nextra be on par with other established solutions

@dimaMachina dimaMachina marked this pull request as draft January 29, 2025 20:06
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.

2 participants