Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion packages/react-aria/src/overlays/ariaHideOutside.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {getOwnerDocument, getOwnerWindow} from '../utils/domHelpers';
import {nodeContains} from '../utils/shadowdom/DOMFunctions';
import {shadowDOM} from 'react-stately/private/flags/flags';

const supportsInert = typeof HTMLElement !== 'undefined' && 'inert' in HTMLElement.prototype;
const supportsInert =
typeof HTMLElement !== 'undefined' &&
HTMLElement.prototype != null &&

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When would HTMLElement exist but not HTMLElement.prototype?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Pretty sure it's a bug in Turbopack.
#10219 (comment)

'inert' in HTMLElement.prototype;

function isAlwaysVisibleNode(node: HTMLElement | SVGElement): boolean {
return node.dataset.liveAnnouncer === 'true' || node.dataset.reactAriaTopLayer !== undefined;
Expand Down
26 changes: 26 additions & 0 deletions packages/react-aria/test/overlays/ariaHideOutside.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -914,3 +914,29 @@ describe('ariaHideOutside with shadow DOM', function () {
});
});
});

describe('ariaHideOutside inert feature detection', function () {
let originalHTMLElement = global.HTMLElement;

afterEach(function () {
global.HTMLElement = originalHTMLElement;
jest.resetModules();
});

it('does not throw at import time when HTMLElement.prototype is undefined', function () {
// Simulate bundler/SSR environments where HTMLElement is defined but its prototype is not.
let FakeHTMLElement = function () {};
FakeHTMLElement.prototype = undefined;
global.HTMLElement = FakeHTMLElement;

jest.resetModules();
expect(() => require('../../src/overlays/ariaHideOutside')).not.toThrow();
});

it('does not throw at import time when HTMLElement is undefined (non-DOM SSR)', function () {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

when does this one happen?

global.HTMLElement = undefined;

jest.resetModules();
expect(() => require('../../src/overlays/ariaHideOutside')).not.toThrow();
});
});