import React, {useState, useRef} from 'react';
import {createRoot} from 'react-dom/client';
import * as Dialog from '@radix-ui/react-dialog';
window.observed = {caught: [], globalErrors: [], requests: [], dialogTransitions: []};
window.addEventListener('error', e => window.observed.globalErrors.push(e.message));
class Boundary extends React.Component {
state = {failed: false};
static getDerivedStateFromError() { return {failed: true}; }
componentDidCatch(error) { window.observed.caught.push({boundary: this.props.name, message: error.message}); }
render() {
if (this.state.failed) return this.props.brokenFallback
? :
Region unavailable
;
return this.props.children;
}
}
function BrokenFallback() { throw new Error('fallback fault'); }
function Panel() {
const [broken, setBroken] = useState(false);
const [request, setRequest] = useState('idle');
if (broken) throw new Error('render fault');
return
{request}
;
}
function FailureFixture() {
const [clicks, setClicks] = useState(0);
const brokenFallback = new URLSearchParams(location.search).has('brokenFallback');
return
;
}
function Modal({children, title}) {
return
{title}{children}
;
}
function FocusFixture() {
const [open, setOpen] = useState(false);
const [present, setPresent] = useState(true);
const next = useRef(null);
const explicit = new URLSearchParams(location.search).has('explicit');
return
{window.observed.dialogTransitions.push({dialog: "outer", open: value}); setOpen(value);}}>
{present && Open task}
{
if (explicit && !present) {event.preventDefault(); next.current?.focus();}
}}>
Record task
window.observed.dialogTransitions.push({dialog: "inner", open: value})}>
Nested task
Close nested
Close task
;
}
createRoot(document.getElementById('root')).render(
new URLSearchParams(location.search).get('mode') === 'focus' ? :
);