Skip to content

v0.1.0 — Initial release

Choose a tag to compare

@marilenaRM marilenaRM released this 07 Jul 14:56

Session-free flash/toast notifications for Symfony that keep your pages HTTP-cacheable.

One addFlash() is enough to drag the session into an otherwise stateless page and make it uncacheable by Varnish or your CDN. This bundle takes the flash out of the session entirely.

Features

Two session-free transports

  • Turbo Stream$this->toast('Item saved') returns a text/vnd.turbo-stream.html response that appends the toast to the DOM. No redirect, no storage at all. Refuses to render (with an actionable LogicException) when the request does not accept Turbo Streams.
  • Cookie$this->deferToast('Welcome back!') before a classic RedirectResponse: toasts are serialized into a short-lived cookie at kernel.response time and consumed client-side on the next page load. The redirected-to page stays cacheable.

Developer experience

  • TurboToastTrait for controllers: toast(), toasts(), deferToast()
  • {{ turbo_toast_container() }} Twig function renders the container div with Stimulus values injected from the bundle configuration — PHP config and JS can never drift apart
  • Two auto-registered Stimulus controllers: toast (fade-in, auto-dismiss, click to dismiss) and toast-container (cookie consumption on initial load and every turbo:load)
  • Configurable: container id, controller name, default delay, stream template, cookie name
  • Optional minimal stylesheet

Hardening

  • Cookie: SameSite=Lax, Secure on HTTPS, ~3.8 KB budget with graceful overflow, cleared before rendering so Turbo cache restores never replay a toast, rendered with textContent only (client-modifiable input)
  • Responses carrying the cookie are forced private so the Set-Cookie never enters a shared HTTP cache
  • 5xx responses discard queued toasts instead of promising success on the next page
  • ToastStack implements ResetInterface (kernel.reset): no cross-request leak under FrankenPHP worker mode / RoadRunner / Swoole
  • Accessibility: aria-live="polite" container, role="status" / role="alert" by toast type

Requirements

PHP >= 8.3, Symfony 7.x, symfony/ux-turbo + symfony/stimulus-bundle.

Installation

composer require marilenarm/turbo-toast-bundle

See the README for the full documentation, including the honest when (not) to use it section.