Skip to content

Connection to Mercure lost on container restart – how to handle auto-reconnect or refresh? #121

@gremo

Description

@gremo

Hi there 👋

I believe this is a fairly common issue, and I’m hoping to find some guidance here, as I couldn’t find anything relevant in the documentation.

In my application, I'm using turbo_stream_listen to establish a connection to a Mercure hub and update the page in real-time when specific events occur. Everything works great so far. The whole stack runs inside Docker Compose using FrankenPHP (and a custom Caddyfile to enable Mercure).

However, I’m running into a problem during deployment:

docker compose up -d --wait --remove-orphans

Deploy

When Docker restarts the containers, the client’s connection to the Mercure server is lost.

In a normal user-driven scenario, this wouldn’t be a big issue — as soon as the user interacts with the app again, a page load or navigation would re-establish the connection seamlessly.

But in my case, the app runs unattended on a tablet in kiosk mode. So after each deployment, the page stays open but no longer receives updates, and I’m forced to ask the client to manually refresh the page, which is not ideal.

I thought about sending a Turbo Stream to trigger a client-side refresh, but of course that doesn’t work — by the time the message is sent, the Mercure connection is already lost.

Is there a recommended way to detect a broken Mercure connection and trigger a page reload or reconnection automatically? Any idea would be greatly appreciated!

Thanks in advance 🙏

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions