-
-
Notifications
You must be signed in to change notification settings - Fork 343
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Turbo] Pass EventSource options to turbo_stream_listen
#2447
base: 2.x
Are you sure you want to change the base?
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! |
e56b74c
to
4d9f2a9
Compare
TwigComponent errors are unrelated |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Fan2Shrek it took too much time, i'm sorry for this. Thank you very much for this work.
@seb-jean & @tibobaldwin thank you for the recent pokes :)
Hey @smnandre, thanks for the help! Unfortunately, there's still a problem with the |
4d9f2a9
to
961ef08
Compare
I found that Using Mercure to create the cookies causes the tests to fail. |
I promise you I did not remember this... but now it happens it feels a bit ironic 😆 Well, let's move on :) You can try this: #2447 (comment) The only think you cannot is "configure" a service from another bundle/bridge/etc. So if you find a way to inject the service directly it's perfect (just use ignoreOnInvalid to not pollute our code if there were a problem one day) If you don't, I'll have a look later during the night 🦇 or tomorrow |
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 = []): string https://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. |
0663176
to
ed131f3
Compare
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I've added tests :)
src/Turbo/src/DependencyInjection/Compiler/RegisterMercureHubs.php
Outdated
Show resolved
Hide resolved
@Fan2Shrek sorry I was off ! Looks good to me, some minor (last) fixes and LGTM :) |
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