Switch to linkify-react for element Linkification as it handles React subtrees without exploding (#10060

* Switch to linkify-react instead of our faulty implementation

Fixes a series of soft crashes where errors include "The node to be removed is not a child of this node."

* Improve types

* Fix types

* Update snapshots

* Add test

* Fix test
This commit is contained in:
Michael Telatynski 2023-02-03 08:59:21 +00:00 committed by GitHub
parent 089557005a
commit 2bde31dcff
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 101 additions and 193 deletions

View file

@ -436,7 +436,7 @@ export default class TextualBody extends React.Component<IBodyProps, IState> {
private onBodyLinkClick = (e: MouseEvent): void => {
let target = e.target as HTMLLinkElement;
// links processed by linkifyjs have their own handler so don't handle those here
if (target.classList.contains(linkifyOpts.className)) return;
if (target.classList.contains(linkifyOpts.className as string)) return;
if (target.nodeName !== "A") {
// Jump to parent as the `<a>` may contain children, e.g. an anchor wrapping an inline code section
target = target.closest<HTMLLinkElement>("a");