Skip to content

Stop requiring mercure_publish() to create FrankenPHP's built-in hub - #136

Merged
dunglas merged 2 commits into
symfony:mainfrom
guillaume-sainthillier:drop-mercure-publish-check
Nov 2, 2026
Merged

dunglas merged 2 commits into
symfony:mainfrom
guillaume-sainthillier:drop-mercure-publish-check

Conversation

@guillaume-sainthillier

Copy link
Copy Markdown
Contributor

Follow-up to symfony/mercure#145.

The bug

HubFactory throws when mercure_publish() isn't defined, but FrankenPHP only defines it when serving a request. HubRegistry creates every hub, including for code that only ever subscribes: Authorization, Discovery, and the Twig extension (eagerly built with Twig 3). So with FrankenPHP's built-in hub (no url), anything under the CLI that touches that code fails, even though it never publishes:

  • cache:warmup, as the Twig template warmer builds the Twig environment
  • a Messenger worker rendering an email template
  • Doctrine fixtures triggering Turbo broadcasts

Before #128, FrankenPhpHub was registered directly without any check, so this is a 0.6.0 regression.

The fix

symfony/mercure 0.9.0 now checks for the function in FrankenPhpHub::publish() and throws an explicit RuntimeException there (symfony/mercure#145). This requires symfony/mercure ^0.9, dropping ^0.8, and removes the creation-time check from HubFactory. Building the built-in hub now works anywhere; only publishing needs FrankenPHP.

The bundle already passes protocol_version explicitly to every class whose default changed in 0.9, so dropping 0.8 doesn't change the bundle's behavior. It does mean apps still on symfony/mercure 0.8 have to upgrade it.

Tests

HubFactoryTest no longer needs the mercure_publish() stub nor separate processes: the built-in hub is created whether or not the function exists, and a new test checks publishing without it throws symfony/mercure's exception. The stub fixture is removed.

No CHANGELOG entry, as 0.6.0 is tagged and the version to ship this in is yours to pick. Suggested entry:

  • Fix FrankenPHP's built-in hub failing to be created under the CLI (e.g. during cache:warmup), where mercure_publish() isn't defined; publishing through it there now throws an explicit exception from symfony/mercure, which is now required in ^0.9

HubFactory threw when mercure_publish() was not defined, which FrankenPHP
only does when serving a request. HubRegistry creates every hub, also
for code that only subscribes (Authorization, Discovery, the Twig
extension), so a built-in hub broke wherever that code ran under the
CLI: cache:warmup building the Twig environment, a Messenger worker
rendering an email, Doctrine fixtures triggering Turbo broadcasts.

symfony/mercure 0.9 checks for the function in FrankenPhpHub::publish()
instead (symfony/mercure#145), so require it and drop the check here:
only publishing needs FrankenPHP now.
@dunglas
dunglas merged commit 9d1a746 into symfony:main Nov 2, 2026
10 checks passed
@dunglas

dunglas commented Nov 2, 2026

Copy link
Copy Markdown
Member

Thanks!

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.

2 participants