Skip to content

feat(web): browser environment assertion#707

Open
hejsztynx wants to merge 3 commits into
@ksienkiewicz/feat-html-sanitizationfrom
@ksienkiewicz/feat-web-non-browser-errors
Open

feat(web): browser environment assertion#707
hejsztynx wants to merge 3 commits into
@ksienkiewicz/feat-html-sanitizationfrom
@ksienkiewicz/feat-web-non-browser-errors

Conversation

@hejsztynx

Copy link
Copy Markdown
Collaborator

Summary

Both components EnrichedText and EnrichedTextInput are 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. Only DOMParser availability 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

OS Implemented
iOS
Android
Web

Checklist

  • E2E tests are passing
  • Required E2E tests have been added (if applicable)

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 of EnrichedText and EnrichedTextInput.
  • 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.

Comment thread src/web/assertBrowserEnvironment.ts
Comment thread src/web/assertBrowserEnvironment.ts
@hejsztynx
hejsztynx marked this pull request as draft July 17, 2026 08:58

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Comment thread src/web/assertBrowserEnvironment.ts
Comment thread src/web/__tests__/assertBrowserEnvironment.test.ts Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • prepareHtmlForWeb now relies on DOMParser (and Node.ELEMENT_NODE) without any guard. In non-DOM environments this will throw a low-level ReferenceError (DOMParser is not defined) instead of a library-specific, actionable error.
  if (useHtmlNormalizer) {
    html = normalizeHtml(html);
  }

  const parser = new DOMParser();

Comment thread src/web/assertBrowserEnvironment.ts
Comment thread src/web/normalization/htmlNormalizer.ts
@hejsztynx
hejsztynx marked this pull request as ready for review July 17, 2026 10:03
@exploIF

exploIF commented Jul 17, 2026

Copy link
Copy Markdown
Collaborator

TipTap works SSR, why our input cannot work there as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants