Skip to content

Cancel the delayed connection notice when the connection is restored - #84

Open
RodolfoSilva wants to merge 1 commit into
srcrip:mainfrom
RodolfoSilva:fix/connection-notice-after-reconnect
Open

RodolfoSilva wants to merge 1 commit into
srcrip:mainfrom
RodolfoSilva:fix/connection-notice-after-reconnect

Conversation

@RodolfoSilva

Copy link
Copy Markdown

Fixes #83

When the LiveView connection drops and comes back within client_error_delay (3000ms by default), the show-error listener still reveals #client-error once the delay ends, after hide-error already ran. The notice then stays on screen while the page is connected, and phx-update="ignore" means no server render clears it. #server-error goes through the same listener.

The listener now keeps the pending setTimeout and hide-error clears it, so a reconnect inside the delay never shows the notice. A connection that stays down past the delay still shows it, and hide-error still hides it as before. The change touches only the two listeners in assets/js/live_toast/live_toast.ts, the rebuilt priv/static artifacts, one test in assets/test/live_toast.test.ts, and CHANGELOG.md.

Check Result
New test on main (1ef5300) 10 passed, 1 failed (the new one)
cd assets && bun test after the fix 11 passed
cd assets && bun run typecheck Exit 0
cd demo && mix test 30 passed
mix format --check-formatted Exit 0

Before / After

A single-file LiveView app with the default toast_group, a socket indicator polling liveSocket.isConnected(), and a button that runs liveSocket.disconnect(); setTimeout(() => liveSocket.connect(), 1500). Same steps in both recordings.

Before (main) After (this branch)
before.mp4
after.mp4

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.

#client-error notice stays visible when the connection is restored within client_error_delay

1 participant