// Base UI chooses useLayoutEffect only when `document` already exists at module // load. Sheet and menu portals never attach if that check runs in bare Node. // This module has to be the first import of any test that mounts those portals. // The placeholder is only for that check and for libraries that inject a style // tag while loading. The lifecycle harness replaces it before rendering. if (typeof globalThis.document === "undefined") { type Placeholder = { nodeType: number; tagName?: string; childNodes: Placeholder[]; parentNode: Placeholder | null; style: Record; textContent: string; appendChild: (child: Placeholder) => Placeholder; }; const make = (tag: string): Placeholder => { const node: Placeholder = { nodeType: 1, tagName: tag.toUpperCase(), childNodes: [], parentNode: null, style: {}, textContent: "", appendChild(child) { child.parentNode = node; node.childNodes.push(child); return child; }, }; return node; }; const head = make("head"); const body = make("body"); const documentElement = make("html"); const document = { nodeType: 9, head, body, documentElement, defaultView: null as unknown, createElement: (tag: string) => make(tag), createTextNode: (text: string) => ({ nodeType: 3, textContent: text, childNodes: [], parentNode: null, style: {}, appendChild(child: Placeholder) { return child; } }), getElementsByTagName: () => [], }; Object.defineProperty(globalThis, "document", { value: document, writable: true, configurable: true }); }