Skip to content

fix: auto-refresh c-display distance formatting - #734

Merged
ascott18 merged 6 commits into
mainfrom
ascott18-auto-update-c-display-distance
Jun 30, 2026
Merged

fix: auto-refresh c-display distance formatting#734
ascott18 merged 6 commits into
mainfrom
ascott18-auto-update-c-display-distance

Conversation

@ascott18

Copy link
Copy Markdown
Collaborator

c-display supported distance formatting (for example :format="{ distance: true }") but did not update itself over time, so relative text like "less than a minute ago" became stale unless parent components manually forced rerenders. This change makes distance displays self-updating in c-display so consumers do not need component-specific timer workarounds.

What changed

  • Added adaptive refresh scheduling in c-display for date distance formatting by checking when the rendered formatDistance(...) string would next change, then scheduling a one-shot update at that boundary.
  • Scoped this behavior to values that are already valid Date instances; if the value is not a Date, adaptive refresh is skipped.
  • Removed the manual setInterval rerender logic from c-admin-editor autosave UI because the shared c-display behavior now covers it.
  • Added/updated docs and changelog entries for the new c-display behavior.
  • Added a component test that verifies distance-formatted output updates over time.

Notes for reviewers

  • Refresh cadence is intentionally adaptive (seconds when needed, then progressively less frequent) to keep relative text accurate while avoiding unnecessary frequent updates for older timestamps.

ascott18 and others added 6 commits June 19, 2026 16:03
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Move the adaptive refresh timer and tick state into a dedicated CDistanceDisplay wrapper (mirroring CPasswordDisplay) so the timer/reactivity overhead only applies to date displays using distance formatting, not every c-display instance.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Replace the hardcoded candidate-delay probe with a binary search over formatDistance, eliminating the magic delay list and landing the refresh exactly on the change boundary (to 1s) instead of overshooting. Cap the search at 1 hour: minute/hour buckets change at most hourly so they're still caught on time, while far-off dates merely re-render hourly at negligible cost.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ascott18
ascott18 merged commit eda8f72 into main Jun 30, 2026
17 checks passed
@ascott18
ascott18 deleted the ascott18-auto-update-c-display-distance branch June 30, 2026 03:08
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