-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
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
feat(core): make broken link checker detect broken anchors - add onBrokenAnchors
config
#9528
Conversation
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
I don't particularly like this solution, because many other things can create anchors without using the Heading component. Since we only run the checker after a build anyway, why don't we read the HTML file and find all IDs? On a related note @slorber do you know why our broken link checker uses the Link component to find valid links and the SPA routes data to find valid targets, instead of using the build output as the source-of-truth? Here's the checker I built for MDN: https://github.com/jc-verse/mdn-checker/blob/master/packages/mdn-checker/src/rules/anchor-links.ts |
I understand the concern, although most achors will usually be created through the heading component. For remaining cases we'll expose a core API to report usage of links and anchors. The API is not designed yet but ideally users should be able to create their own link/anchor componennts and have it work nicely with the broken link checker.
We could also do that to check links too, not just anchors. IMHO users appreciate the fact that we provide an integrated solution for link checking. And I have good hope to someday be able to do some fancy things with the graph we collect, and have heuristics to report most broken links in dev mode thanks to those new APIs and a bit of caching.
That's an initial implementation detail, but it turns out it wasn't a bad one IMHO since it works nicely and is quite robust. And this gives the opportunity to have something more opinionated in the future. We probably only want to double check html files emitted through the Docusaurus SPA. Not 100% sure it's our responsibility to report broken links on Let's also not forget that regular non-SPA links are real HTML navigations and you can't know the redirects set up at the CDN/server level: this can lead to false positives. For these reasons I'd like for now to pursue in the current direction. I wish it didn't require introducing a new core API for it, but it's not too bad IMHO. |
Okay, that makes sense to me. I have an existing use case with a remark plugin that emits DLs with |
Great I don't think we'll expose a core React component but only a hook. Now you can decide to create your own component that uses the hook and emit it if it makes things simpler to integrate for your use-case |
Motivation
Previously it could only report broken paths.
siteConfig.onBrokenAnchors
option, defaults towarn
for v3.x retro-compatibility, no breaking change.useBrokenLinks()
core hook to collect page links and anchors (for advanced cases and plugin authors only)Fix #3321
Fix #9057
Test Plan
unit tests + dogfood
Test links
Preview: https://deploy-preview-9528--docusaurus-2.netlify.app/
Docs: