[Turbo] Pass EventSource options to turbo_stream_listen#2447
Conversation
📊 Packages dist files size differenceThanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
|
||||||||||||
867707d to
06ac699
Compare
06ac699 to
abcc723
Compare
abcc723 to
e95cbab
Compare
f92e643 to
e56b74c
Compare
|
Hey @smnandre, However, the last commit seems a bit off to me. Could you confirm if that's what you had in mind ? |
|
Hi seb-jean Guervyl gremo DRaichev and anyone who want to :) Well.... It’s time to lay all this out clearly! 😊 Could you share your ideal Developer Experience (DX) suggestions? Please clarify where and how you’d use this feature: Looking forward to your insights! |
583aab6 to
5b429a7
Compare
|
I adapted the code to use the Twig Mercure extension. |
Well well well ... 👼 (1/1)
Well well well .... 👼 (2/2) *
* @return string The URL of the hub with the appropriate "topic" query parameters (if any)
*/
public function mercure($topics = null, array $options = []): stringhttps://github.com/symfony/mercure[•••]src/Twig/MercureExtension.php |
Does it work ? If not, what is missing here ? How do you test? |
|
I tested it on a small app with Mercure already set up. The only problem I’m facing is how to inject I’m not sure what the 'proper' way to solve this problem is. |
ed131f3 to
a59fd33
Compare
|
Hey @smnandre, this finally looks good to me :) |
| if (isset($eventSourceOptions['withCredentials'])) { | ||
| $controllerAttributes['withCredentials'] = $eventSourceOptions['withCredentials']; | ||
| } | ||
| } catch (RuntimeError $e) { |
There was a problem hiding this comment.
This can be thrown by $this->twig->getExtension,
Should I remove it anyway?
| foreach ($container->findTaggedServiceIds('mercure.hub') as $hubId => $tag) { | ||
| $name = str_replace('mercure.hub.', '', $hubId); | ||
|
|
||
| $container->register("turbo.mercure.$name.renderer", TurboStreamListenRenderer::class) | ||
| ->addArgument(new Reference($hubId)) | ||
| ->addArgument(new Reference('turbo.mercure.stimulus_helper')) | ||
| ->addArgument(new Reference('turbo.id_accessor')) | ||
| ->addArgument(new Reference('twig')) | ||
| ->addTag('turbo.renderer.stream_listen', ['transport' => $name]); | ||
|
|
||
| if (isset($tag['default']) && $tag['default']) { | ||
| $container->getDefinition("turbo.mercure.{$name}.renderer") | ||
| ->addTag('turbo.renderer.stream_listen', ['transport' => 'default']); | ||
| } | ||
|
|
||
| $container->register("turbo.mercure.$name.broadcaster", Broadcaster::class) | ||
| ->addArgument($name) | ||
| ->addArgument(new Reference($hubId)) | ||
| ->addTag('turbo.broadcaster'); | ||
| } |
There was a problem hiding this comment.
Could we have some test here ?
It does not seem to follow the findTaggedServiceIds() doc (it returns a array of tags, not a single one)
There was a problem hiding this comment.
You're right, I've added tests :)
|
@Fan2Shrek sorry I was off ! Looks good to me, some minor (last) fixes and LGTM :) |
|
Thank you very much for your work on this @Fan2Shrek ! |
|
Can this feature be merged? |
|
There are some conflicts, I'm taking care of them |
1b5ba3f to
93ae3a2
Compare
|
Thank you @Fan2Shrek. |

This allows to pass options to the EventSource, for example
{{ turbo_stream_listen('a_topic', 'default', { withCredentials: true }) }}Or create specific auth cookie
{{ turbo_stream_listen('a_topic', 'default', { subscribe: '*' }) }}This functionality is similar to how
mercure()works