Skip to content

bug(core): observe() ignores an annotated root element #370

Description

@vamgan

Summary

ctx.observe(rootElement) does not attach interaction listeners when rootElement itself has data-askable. Only annotated descendants are attached, so clicking/focusing the annotated root leaves context focus empty.

Root cause

packages/core/src/observer.ts resolves the root and calls:

rootEl.querySelectorAll<HTMLElement>('[data-askable]').forEach((el) => this.attach(el));

querySelectorAll() only returns descendants, not rootEl itself.

Verified reproduction

Against main at 40a3374:

  1. Create a button with data-askable='{"id":"root"}'.
  2. Call ctx.observe(button, { events: ['click'] }).
  3. Click the button.
  4. ctx.getFocus() remains null.

Observed output:

{"focus":null}

Proposed fix

When the root is an HTMLElement, attach it first if it has data-askable, then scan descendants. Preserve the existing Document behavior.

Also verify attribute mutation behavior when an observed root gains or loses data-askable after observation.

Acceptance criteria

  • An annotated HTMLElement passed directly to observe() is interactive
  • Annotated descendants continue to work
  • An unannotated root does not produce focus
  • Adding/removing data-askable on the observed root updates listener state
  • unobserve() detaches the root listener
  • Unit and browser E2E regression coverage is added

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: coreCore package and cross-package runtime behaviorbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions