feat(web): browser environment assertion#707
Conversation
There was a problem hiding this comment.
Pull request overview
Adds an explicit runtime assertion that EnrichedText and EnrichedTextInput only run in a real browser/DOM environment, to avoid SSR crashes and provide a clearer error, and updates web docs accordingly.
Changes:
- Introduce
assertBrowserEnvironment()and invoke it at the start ofEnrichedTextandEnrichedTextInput. - Remove silent
DOMParser-missing fallbacks from web HTML normalization helpers. - Document that the web components are client-only (SSR not supported).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/web/normalization/prepareHtmlForWeb.ts | Removes silent non-DOM fallback; relies on browser-only execution path. |
| src/web/normalization/htmlNormalizer.ts | Removes silent non-DOM fallback before using DOMParser. |
| src/web/EnrichedTextInput.tsx | Asserts browser environment before running component logic. |
| src/web/EnrichedText.tsx | Asserts browser environment before running component logic. |
| src/web/assertBrowserEnvironment.ts | Adds shared DOM availability assertion with a clearer error message. |
| docs/WEB.md | Documents client-only rendering requirement (no SSR). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/web/normalization/prepareHtmlForWeb.ts:11
prepareHtmlForWebnow relies onDOMParser(andNode.ELEMENT_NODE) without any guard. In non-DOM environments this will throw a low-levelReferenceError(DOMParser is not defined) instead of a library-specific, actionable error.
if (useHtmlNormalizer) {
html = normalizeHtml(html);
}
const parser = new DOMParser();
|
|
We've decided to move the SSR implementation to the backlog, I'm re-opening this PR for reviews. |
Summary
Both components
EnrichedTextandEnrichedTextInputare using DOM -DOMPurify,DOMParser,TipTap. An attempt of rendering them in a non-browser environment, e.g. in SSR applications, would result in a crash. OnlyDOMParseravailability check was present, but it was silent. Now we check for the browser environment before any other component logic and throw a proper error. Documentation was also updated, to explicitly point the client-only nature of the components.Compatibility
Checklist