Skip to content

Portal and ErrorBoundary

Render elsewhere, and recover from errors.

Portal

Portal moves its children into another element, document.body by default. It is useful for dialogs and toasts that must escape an overflow or a stacking context. The content is removed when its owner is disposed.

html`
  ${Portal({
    children: html`<div class="toast" role="status">Saved</div>`,
  })}
`

Pass mount to pick the target element.

ErrorBoundary

ErrorBoundary catches errors thrown while its children render and shows the fallback. The fallback receives the error and a reset function that tries again. Errors in event handlers are not caught.