Fix Overview crash on hrefless README anchors#2671
Merged
Simek merged 1 commit intoJul 20, 2026
Merged
Conversation
The `a` handler called `props.href.startsWith('#')` unconditionally, but
rehype-raw parses `<a name="...">` into an anchor node with no `href`, so
`props.href` was undefined and the whole Overview render threw a TypeError.
Use optional chaining so a hrefless anchor falls through to the existing
`<span>` fallback at the end of the handler instead of crashing.
Fixes react-native-community#2670
Simek
approved these changes
Jul 20, 2026
Simek
left a comment
Member
There was a problem hiding this comment.
Thanks for the bug report and fix! 👍
I have fixed it once in the past, but then broke this again when adding support for hash links. 😅 Need to find a way to correctly extract types for custom elements in @m2d/react-markdown/client markdown renderer, so we can avoid similar issues in the future.
Contributor
Author
|
Thanks for the quick merge! Makes sense — those custom-element types are tricky. Glad the optional-chaining fallback helps in the meantime. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #2670. The package Overview page throws a client-side exception and renders the error page when a README contains a hrefless anchor (e.g.
<a name="section"></a>).Cause
In
MarkdownRenderer.tsx, theahandler starts with:rehype-rawparses<a name="...">into an anchor node with nohref, soprops.hrefisundefinedand.startsWith()throws, which takes down the whole Overview render.Fix
The handler already ends with a
return <span>{props.children}</span>fallback, so with optional chaining a hrefless anchor falls through to that fallback instead of crashing. One-character change, no behavior change for anchors that have anhref.Reproduction
Live example before the fix: https://reactnative.directory/package/tapflow (Overview tab crashes; Code / Versions / Score are fine). Console:
Also reproduced the parse with a standard
remark -> remark-rehype (allowDangerousHtml) -> rehype-rawpipeline: a<a name>anchor yields one<a>node without anhref, which is what hits the unguarded.startsWith.