Skip to content

Invalidate dependent styles after focus, attribute, and tree changes #157

Backlog

Description

@cowboyd

Focus, attribute, and tree changes can change the styles of elements beyond the mutated element and its ancestors. Those dependent elements need their cached styles invalidated and their rendered output rebuilt.

This follows the review of #128 and affects stylesheet support in #138 and subtree replay from #143.

Problem

RenderApi.request() currently marks notified nodes and their ancestors as changed. Layout can reuse cached styles and replay the output of other subtrees. Notifying the previous and next focused elements addresses their own focus styles and styles applied directly to their :focus-within ancestors, but leaves other selector dependencies unmarked. For example:

button:focus + .hint { color: green; }
.panel:focus-within .status { color: green; }
section:has(:focus) > .label { color: green; }
[data-state="open"] .content { color: green; }
.selected ~ .item { color: green; }

Focus changes in the first three examples can change a different sibling or descendant's style. Attribute/class changes and insertion, removal, or movement can similarly change which elements match. A new frame alone is insufficient if those elements still reuse cached styles or replay stale output.

Expected behavior

  • Invalidate every element whose resolved style depends on changed focus state, attributes/classes, or tree relationships, including affected siblings and descendants.
  • Recompute affected styles before deciding whether their rendered subtrees can be replayed. Clear the old styles when focus or attributes are removed as well as applying new styles.
  • Preserve frame coalescing and reuse unaffected output. The invalidation strategy can be conservative initially; it must not leave stale styles or terminal output.

Upstream coverage to enable as support becomes available

These sources exist at the pinned WPT revision b719612f963a05ece9c89a7dd7598c1c59618874:

The runner needs stylesheet/computed-style support and, depending on the file, CSSOM, input automation, or rendered-reference comparison. Keep upstream tests unchanged. Also verify the actual terminal rendering path: on-demand getComputedStyle() recalculation alone could pass while frame scheduling or subtree replay remains stale.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions