Skip to content

feat: hybrid attribute patching for focused elements #33

@adnaan

Description

@adnaan

Context

This follow-up task was identified during the review of PR #32.

Source PR: #32
PR Title: fix: skip patching focused form elements during DOM update
Suggested by: @claude[bot] (raised in 6 of 6 review comments)

Task Description

Currently, shouldSkipUpdate returns false from morphdom's onBeforeElUpdated for focused form elements, which skips all morphdom patching — not just value preservation. This means server-driven attribute changes (class, disabled, aria-*, readonly, aria-invalid, etc.) are silently dropped while the element has focus.

This is a deliberate tradeoff matching Phoenix LiveView's behavior, with data-lvt-force-update as an opt-out. However, a more granular approach could:

  • Preserve .value and cursor position (skip value/textContent patching)
  • Still allow non-value attribute diffs through morphdom (class, disabled, aria-*, etc.)

Example footgun with current behavior

Server disables a focused input after form submission → input stays enabled in the UI until the user tabs away.

Proposed approach

Instead of returning false from onBeforeElUpdated, manually sync non-value attributes from toEl to fromEl while preserving .value, .checked, and selection state. Then return false to prevent morphdom from touching child nodes.

Considerations

  • More complex than the current approach
  • Need to handle the attribute sync carefully to avoid triggering unwanted side effects
  • Phoenix LiveView chose the simpler "skip everything" approach for a reason — evaluate if the added complexity is worth it

This issue was automatically created from PR review comments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    follow-upFollow-up task from PR reviewfrom-reviewIssue originated from PR review

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions