import { type ComponentType, StrictMode } from 'react'; import { createRoot } from 'react-dom/client'; import * as ComponentModule from './Component.js'; import { RenderHarness } from './setup.js'; type AnyComponent = ComponentType; // React's exotic components (memo/forwardRef/lazy) are objects carrying a // `$$typeof` marker, not functions — so a `typeof === 'function'` gate rejects // `export default memo(Page)` and reports "no component found" on a file that // plainly has one. That surfaces as a runtime error and exit 1 on valid input, // which is the false-failure class an agent fix-loop then tries to "repair". const isComponentLike = (v: unknown): boolean => typeof v === 'function' || (typeof v === 'object' && v !== null && '$$typeof' in v); const findComponent = ( mod: Record ): AnyComponent | undefined => { if (isComponentLike(mod.default)) return mod.default as AnyComponent; if (isComponentLike(mod.App)) return mod.App as AnyComponent; return undefined; }; const rootElement = document.getElementById('root'); if (!rootElement) { throw new Error('No #root element found in harness HTML.'); } const Component = findComponent( ComponentModule as unknown as Record ); const root = createRoot(rootElement); if (!Component) { const w = window as Window & { __marigoldValidateRenderErrors?: Array<{ message: string; stack?: string; componentStack?: string; }>; }; w.__marigoldValidateRenderErrors = [ { message: 'No component found. The file must have a default export or a named export called "App".', }, ]; root.render(
No component export found in target file.
); rootElement.setAttribute('data-validation-root', 'ready'); } else { root.render( ); // The root attribute is what Playwright waits on. A microtask fires before // React 18's async commit paints and before react-aria's post-layout // measurement settles, so the first bounding-box/overflow read can race a // not-yet-laid-out tree and produce nondeterministic spatial findings. Two // requestAnimationFrame ticks guarantee a committed paint plus one settle // frame — the same idiom the spatial checkers use to wait for layout (see // responsive.ts/text-spacing.ts/keyboard.ts waitForLayout). requestAnimationFrame(() => { requestAnimationFrame(() => { rootElement.setAttribute('data-validation-root', 'ready'); }); }); }