Skip to content

Commit

Permalink
Fix pill rendering in dev mode (#28853)
Browse files Browse the repository at this point in the history
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
  • Loading branch information
t3chguy authored Jan 3, 2025
1 parent 703149d commit cf49f9e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
9 changes: 4 additions & 5 deletions src/utils/pillify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,8 @@ export function pillifyLinks(
</StrictMode>
);

pills.render(pill, pillContainer);

node.parentNode?.replaceChild(pillContainer, node);
pills.render(pill, pillContainer, node);
node.replaceWith(pillContainer);
// Pills within pills aren't going to go well, so move on
pillified = true;

Expand Down Expand Up @@ -147,8 +146,8 @@ export function pillifyLinks(
</StrictMode>
);

pills.render(pill, pillContainer);
roomNotifTextNode.parentNode?.replaceChild(pillContainer, roomNotifTextNode);
pills.render(pill, pillContainer, roomNotifTextNode);
roomNotifTextNode.replaceWith(pillContainer);
}
// Nothing else to do for a text node (and we don't need to advance
// the loop pointer because we did it above)
Expand Down
7 changes: 4 additions & 3 deletions src/utils/react.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { createRoot, Root } from "react-dom/client";
export class ReactRootManager {
private roots: Root[] = [];
private rootElements: Element[] = [];
private revertElements: Array<null | Element> = [];
private revertElements: Array<Node | null> = [];

public get elements(): Element[] {
return this.rootElements;
Expand All @@ -26,12 +26,13 @@ export class ReactRootManager {
* @param children the React component to render
* @param rootElement the root element to render the component into
* @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);
this.roots.push(root);
this.rootElements.push(rootElement);
this.revertElements.push(revertElement ?? null);
this.revertElements.push(revertElement);
root.render(children);
}

Expand Down
2 changes: 1 addition & 1 deletion src/utils/tooltipify.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function tooltipifyLinks(
</StrictMode>
);

tooltips.render(tooltip, node);
tooltips.render(tooltip, node, null);
} else if (node.childNodes?.length) {
tooltipifyLinks(node.childNodes as NodeListOf<Element>, ignoredNodes, tooltips);
}
Expand Down

0 comments on commit cf49f9e

Please sign in to comment.