Skip to content

perf: MutationObserver on document.body fires on every DOM mutation #5

@GeneralJerel

Description

@GeneralJerel

Description

Severity: P2 — Fragility / Performance

In apps/app/src/components/explainer-cards.tsx:141, a MutationObserver is attached to document.body with { childList: true, subtree: true }, which fires on every DOM mutation in the entire app.

Failure mode

Performance degradation on pages with frequent DOM updates (e.g., during agent streaming).

Suggested fix

  • Narrow the observer scope: observe only the CopilotKit container element (e.g., [data-copilotkit]) instead of document.body
  • Add a debounce or requestIdleCallback to the callback

From self-review finding F06

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions