Fix pill rendering in dev mode (#28853)

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
travis/investigate-oom
Michael Telatynski 2025-01-03 16:40:05 +00:00 committed by GitHub
parent 703149d76d
commit cf49f9e22c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 9 deletions

View File

@ -83,9 +83,8 @@ export function pillifyLinks(
</StrictMode> </StrictMode>
); );
pills.render(pill, pillContainer); pills.render(pill, pillContainer, node);
node.replaceWith(pillContainer);
node.parentNode?.replaceChild(pillContainer, node);
// Pills within pills aren't going to go well, so move on // Pills within pills aren't going to go well, so move on
pillified = true; pillified = true;
@ -147,8 +146,8 @@ export function pillifyLinks(
</StrictMode> </StrictMode>
); );
pills.render(pill, pillContainer); pills.render(pill, pillContainer, roomNotifTextNode);
roomNotifTextNode.parentNode?.replaceChild(pillContainer, roomNotifTextNode); roomNotifTextNode.replaceWith(pillContainer);
} }
// Nothing else to do for a text node (and we don't need to advance // Nothing else to do for a text node (and we don't need to advance
// the loop pointer because we did it above) // the loop pointer because we did it above)

View File

@ -15,7 +15,7 @@ import { createRoot, Root } from "react-dom/client";
export class ReactRootManager { export class ReactRootManager {
private roots: Root[] = []; private roots: Root[] = [];
private rootElements: Element[] = []; private rootElements: Element[] = [];
private revertElements: Array<null | Element> = []; private revertElements: Array<Node | null> = [];
public get elements(): Element[] { public get elements(): Element[] {
return this.rootElements; return this.rootElements;
@ -26,12 +26,13 @@ export class ReactRootManager {
* @param children the React component to render * @param children the React component to render
* @param rootElement the root element to render the component into * @param rootElement the root element to render the component into
* @param revertElement the element to replace the root element with when unmounting * @param revertElement the element to replace the root element with when unmounting
* needed to support double-rendering in React 18 Strict Dev mode
*/ */
public render(children: ReactNode, rootElement: Element, revertElement?: Element): void { public render(children: ReactNode, rootElement: Element, revertElement: Node | null): void {
const root = createRoot(rootElement); const root = createRoot(rootElement);
this.roots.push(root); this.roots.push(root);
this.rootElements.push(rootElement); this.rootElements.push(rootElement);
this.revertElements.push(revertElement ?? null); this.revertElements.push(revertElement);
root.render(children); root.render(children);
} }

View File

@ -66,7 +66,7 @@ export function tooltipifyLinks(
</StrictMode> </StrictMode>
); );
tooltips.render(tooltip, node); tooltips.render(tooltip, node, null);
} else if (node.childNodes?.length) { } else if (node.childNodes?.length) {
tooltipifyLinks(node.childNodes as NodeListOf<Element>, ignoredNodes, tooltips); tooltipifyLinks(node.childNodes as NodeListOf<Element>, ignoredNodes, tooltips);
} }