Skip to content

fix: clean up toast listeners with the hook lifecycle - #85

Open
kosciak9 wants to merge 1 commit into
srcrip:mainfrom
kosciak9:fix/toast-hook-listener-lifecycle
Open

kosciak9 wants to merge 1 commit into
srcrip:mainfrom
kosciak9:fix/toast-hook-listener-lifecycle

Conversation

@kosciak9

Copy link
Copy Markdown

Problem

createLiveToastHook installs three global listeners for each toast, but they remain registered after the hook is destroyed. A later phx:clear-flash event can therefore call pushEvent on an old view and reject with unable to push hook event. LiveView not connected; dismissal callbacks also retain removed toast instances.

Change

  • Register clear-flash and live-toast-dismiss through the native hook handleEvent API, so LiveView removes those listeners during hook cleanup.
  • Keep flash-leave on the toast element rather than window, preserving the target check and animation.
  • Extend the existing JS test helper to model LiveView-owned event cleanup and add focused regression coverage for post-destruction events and element-local flash-leave.
  • Regenerate the ESM, CJS, IIFE, minified bundle, and source maps with mix assets.build, as required by AGENTS.md.

No error suppression, connection guards, dependency updates, or public API changes. This addresses listener lifetime, not cancellation of already-running async callbacks.

Validation

  • Both new regression cases fail against the unchanged client source and pass with this change.
  • cd assets && bun test: 12 passed, 0 failed.
  • cd assets && bun run typecheck: passed.
  • mix assets.build: passed; inspected all generated formats. Both maps embed the current canonical source and have no local machine paths.
  • mix format: passed, with no unrelated formatting changes.
  • cd demo && mix test: 30 passed.
  • git diff --check: passed.

Local validation used Bun 1.4.2 and Elixir 1.20.4 / OTP 29.1.1. The existing dependency lockfiles were unchanged; older locked Elixir dependencies emitted compatibility/deprecation warnings on this runtime.

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