Skip to content

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

@vamgan

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

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

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions