-
Notifications
You must be signed in to change notification settings - Fork 0
feat: hybrid attribute patching for focused elements #33
Description
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
.valueand 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.