Skip to content

fix(chore): Reduce combobox and date-picker re-render#47

Merged
karim-semmoud merged 3 commits into
mainfrom
perf/combobox-datepicker-render
Jun 1, 2026
Merged

fix(chore): Reduce combobox and date-picker re-render#47
karim-semmoud merged 3 commits into
mainfrom
perf/combobox-datepicker-render

Conversation

@karim-semmoud
Copy link
Copy Markdown
Member

Summary

Reduces DOM churn in combobox and date-picker re-renders. Both components subscribe to Zag machine updates and call render() on every state change; previously they tore down and rebuilt large parts of the list/calendar on each pass.

Changes

assets/components/combobox.ts

  • Replaced full list teardown (remove() all items/groups, re-clone from templates) with incremental sync:
    • Flat lists: reuse existing items by data-value, clone only missing ones, reorder with insertBefore, drop filtered-out items
    • Grouped lists: reuse group shells and nested items the same way
    • Empty state: show/hide empty part without touching unrelated DOM when possible
  • Fixed grouped mode cleanup: only direct list-level items are removed before sync (nested group items were incorrectly wiped every render via querySelectorAll)

assets/components/date-picker.ts

  • Day/month/year calendar tables now reuse <tr>/<td> nodes instead of tbody.innerHTML = ""
  • Cells keyed with data-date-cell (day: YYYY-M-D, month: {year}-{month}, year: {year})
  • Updates Zag props and text in place; creates nodes only when structure changes
  • Day table header row is reused when weekday column count is unchanged

Tests

  • assets/test/component/combobox.test.ts: flat reuse, filter removal, grouped reuse
  • assets/test/component/date-picker.test.ts: day cell and header reuse on repeated render

Why

On every LiveView patch or Zag state update (filter, open, select, navigate month), the old code destroyed and recreated every list item or calendar cell. That added layout cost, broke focus/hover stability, and scaled poorly with large option lists or open calendars.

@karim-semmoud karim-semmoud self-assigned this Jun 1, 2026
@karim-semmoud karim-semmoud changed the title Reduce combobox and date-picker re-render fix(chore): Reduce combobox and date-picker re-render Jun 1, 2026
@karim-semmoud karim-semmoud merged commit e1e794a into main Jun 1, 2026
14 checks passed
@karim-semmoud karim-semmoud deleted the perf/combobox-datepicker-render branch June 1, 2026 15:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant