Troubleshooting Common mccDeliveryCountdown Issues
1. Countdown not starting
- Cause: Initialization code runs before DOM or required resources are ready.
- Fix: Ensure initialization runs after DOMContentLoaded or in a mounted hook. Example:
javascript
document.addEventListener(‘DOMContentLoaded’, () => { mccDeliveryCountdown.init({…});});
2. Timer shows incorrect remaining time
- Cause: Timezone or server-client time mismatch, or wrong end timestamp format.
- Fix: Use UTC timestamps and compute deltas on the client:
javascript
const endTs = Date.parse(‘2026-05-20T15:00:00Z’); // UTC ISO 8601const now = Date.now();const remaining = Math.max(0, endTs - now);
Also verify the API returns ISO 8601 or epoch milliseconds as documented.
3. Timer jumps or skips seconds
- Cause: Using setInterval with heavy UI work, repeated re-renders, or relying on Date objects updated incorrectly.
- Fix: Use requestAnimationFrame or compute remaining from absolute timestamps each tick; throttle DOM updates:
javascript
function tick(endTs){ const remaining = Math.max(0, endTs - Date.now()); updateDisplay(remaining); if (remaining > 0) requestAnimationFrame(() => tick(endTs));}
4. Multiple timers on the same page conflict
- Cause: Global state or non-scoped event listeners/interval IDs.
- Fix: Encapsulate each countdown instance in a class or factory and keep instance-specific IDs:
javascript
class DeliveryCountdown { constructor(endTs, el){ this.endTs = endTs; this.el = el; this.raf = null; } start(){ this.tick(); } tick(){ /compute, update, set raf */ } stop(){ cancelAnimationFrame(this.raf); }}
5. Formatting or localization issues
- Cause: Hardcoded labels, incorrect pluralization, or locale-unaware formatting.
- Fix: Use Intl APIs and provide i18n strings:
javascript
const days = Math.floor(ms / 86400000);const formatter = new Intl.RelativeTimeFormat(‘en’, {numeric: ‘auto’});// or format numeric parts manually and localize labels
6. Performance degradation on mobile
- Cause: Frequent DOM updates, heavy animations, or running many intervals.
- Fix: Reduce update frequency to once per second, avoid layout-thrashing, and pause timers when page is hidden:
javascript
document.addEventListener(‘visibilitychange’, () => { if (document.hidden) countdown.stop(); else countdown.start();});
7. End-of-countdown behavior not firing
- Cause: Relying on exact millisecond match or not checking for <= 0.
- Fix: Trigger end action when remaining <= 0 and ensure it runs once:
javascript
if (remaining <= 0 && !this.ended){ this.ended = true; onComplete(); }
8. Animations out of sync with timer
- Cause: CSS animations not tied to clock or using transition delays.
- Fix: Drive animations from JS state or use CSS variables updated each tick for smooth sync.
9. Accessibility problems
- Cause: Dynamic updates not announced to assistive tech; poor focus management.
- Fix: Provide ARIA live region and accessible labels:
html
Delivery in 10 minutes
Update that region text on each visible change and avoid excessive announcements.
10. Integration issues with frameworks (React/Vue/Angular)
- Cause: Conflicts between framework reactivity and external timers; memory leaks on unmount.
- Fix: Hook into lifecycle methods to
Leave a Reply