Skip to content

bug(core): a11yTextExtractor throws in SSR / non-browser environments #257

Closed as not planned

Description

@vamgan

Summary

a11yTextExtractor in packages/core/src/a11y.ts references the global document without guarding for SSR:

const root = el.ownerDocument ?? document;

If el.ownerDocument is null and the function is called in a non-browser environment (e.g. during SSR testing, in a Node.js test harness, or in React Native), this throws ReferenceError: document is not defined.

Every other file in core that touches the DOM guards with typeof document !== 'undefined'. This one doesn't.

Fix

const root = el.ownerDocument ?? (typeof document !== 'undefined' ? document : null);
if (!root) return el.textContent?.trim() ?? '';

Impact

Any app that passes textExtractor: a11yTextExtractor and runs any code path (e.g. tests, SSR rendering) in a non-browser environment will crash.

Activity

  1. added
    bugSomething isn't working
    area: coreCore package and cross-package runtime behavior
    on Jun 1, 2026
  2. added a commit that references this issue on Jun 1, 2026
    b4beb20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreCore package and cross-package runtime behaviorbugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions