Skip to content

Rule · Lint

unload event listener

lint/unload-listenerwarnvoid lintupdated

Why it matters

An unload handler makes the page ineligible for the back/forward cache in most browsers, so every back navigation reloads the page instead of restoring it instantly. The event is also unreliable on mobile.

How to fix it

Use pagehide (or visibilitychange for analytics beacons). Only add beforeunload while there are unsaved changes.

Example

ts
addEventListener('pagehide', () => navigator.sendBeacon('/log', data))

References

void lint reports 67 rules in this category. Static source checks with no browser: Tailwind v4 silent failures, Next.js 16 API traps, React render-body bugs, accessibility markup, SEO files and motion hygiene.