Description
inline-mention-editor.tsx statically imports react-dom/server (line 13) to use renderToString for creating two small DOM elements (a connector icon and an X close button in mention chips). This pulls the entire server rendering runtime into the client-side JavaScript bundle.
This module is imported by thread.tsx, which is the main chat component — so react-dom/server is loaded on every chat page load.
File to change
surfsense_web/components/assistant-ui/inline-mention-editor.tsx
Current code
Line 13 (import):
import ReactDOMServer from "react-dom/server";
Lines 216-218 (connector icon):
iconSpan.innerHTML = ReactDOMServer.renderToString(
getConnectorIcon(doc.document_type ?? "UNKNOWN", "h-3 w-3")
);
Lines 225-227 (close button X icon):
removeBtn.innerHTML = ReactDOMServer.renderToString(
createElement(X, { className: "h-3 w-3", strokeWidth: 2.5 })
);
What to do
Replace ReactDOMServer.renderToString with client-side rendering. A safe approach:
import { createRoot } from "react-dom/client";
import { flushSync } from "react-dom";
function renderToHTML(element: React.ReactElement): string {
const container = document.createElement("div");
const root = createRoot(container);
flushSync(() => root.render(element));
const html = container.innerHTML;
root.unmount();
return html;
}
Then replace both usages:
iconSpan.innerHTML = renderToHTML(
getConnectorIcon(doc.document_type ?? "UNKNOWN", "h-3 w-3")
);
removeBtn.innerHTML = renderToHTML(
createElement(X, { className: "h-3 w-3", strokeWidth: 2.5 })
);
react-dom and react-dom/client are already in the client bundle (used by React itself), so createRoot + flushSync add zero new bundle weight.
Important: After making changes, test that:
- Mention chips display the correct connector icon
- The X close button appears on hover
- Clicking X removes the chip
- All connector types show correct icons
Acceptance criteria
react-dom/server is NOT imported anywhere in inline-mention-editor.tsx
- Mention chip icons still render correctly
- Chip remove (X) button still works
next build succeeds
Description
inline-mention-editor.tsxstatically importsreact-dom/server(line 13) to userenderToStringfor creating two small DOM elements (a connector icon and an X close button in mention chips). This pulls the entire server rendering runtime into the client-side JavaScript bundle.This module is imported by
thread.tsx, which is the main chat component — soreact-dom/serveris loaded on every chat page load.File to change
surfsense_web/components/assistant-ui/inline-mention-editor.tsxCurrent code
Line 13 (import):
Lines 216-218 (connector icon):
Lines 225-227 (close button X icon):
What to do
Replace
ReactDOMServer.renderToStringwith client-side rendering. A safe approach:Then replace both usages:
react-domandreact-dom/clientare already in the client bundle (used by React itself), socreateRoot+flushSyncadd zero new bundle weight.Important: After making changes, test that:
Acceptance criteria
react-dom/serveris NOT imported anywhere ininline-mention-editor.tsxnext buildsucceeds