-
-
Notifications
You must be signed in to change notification settings - Fork 324
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
Add 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
src/Turbo/src/Twig/TwigExtension.php
Outdated
unset($options['subscribe'], $options['publish'], $options['additionalClaims']); | ||
} | ||
|
||
return $this->turboStreamListenRenderers->get($transport)->renderTurboStreamListen($env, $topic, $options); |
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 cannot pass options as third parameter, as the interface only declare "options" in docblock.
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.
I'm not really sure how to do that, could you explain it to me ?
src/Turbo/src/Twig/TwigExtension.php
Outdated
@@ -12,19 +12,24 @@ | |||
namespace Symfony\UX\Turbo\Twig; | |||
|
|||
use Psr\Container\ContainerInterface; | |||
use Symfony\Component\HttpFoundation\RequestStack; | |||
use Symfony\Component\Mercure\Authorization; | |||
use Symfony\UX\Turbo\Bridge\Mercure\TopicSet; |
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.
I think you could/should probably use TopicSet here, as it's specific to Mercure and would keep things properly typed / isolated.
Or any strategy that does not impact users using a different solution than Mercure.
You should look at this PR and the discussion, as most challenges are identical
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.
I don't see where I could use this object, could you add more details ?
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.
I did not mean "use this one", but if you read the PR linked and the discussion, you will see how it relates to yours.
We decided to introduce a new object to bypass these BC questions.
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 ? |
$this->authorization->setCookie( | ||
$request, | ||
$eventSourceOptions['subscribe'] ?? [], | ||
$eventSourceOptions['publish'] ?? [], | ||
$eventSourceOptions['additionalClaims'] ?? [], | ||
$eventSourceOptions['transport'] ?? null, | ||
); |
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 will throw if the method is called twice during the render of the page.
What are the goal of the various options here ?
Or, say differently, why not use the mercure extension here ? (real question i'm not sure to get)
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.
Do you mean the Mercure Twig extension?
If so, it doesn't seem to work 😅. The dependency isn't being resolved, and to be honest, I'm not sure why.
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! |
@norkunas as i think you are one of the (if not the) person knowing this most, and having experience with this BC problematic... i'd love to have your input on this. @Fan2Shrek I've opened a meta-issue to see how we can make changes in a more generic way first, to ease the development of this specific need, but also others after. --> #2460 |
Hi, This feature would be interesting for me: I would use it with #327. Let's take the example of GitHub notifications. I have a // src/Entity/Notification.php
namespace App\Entity;
use Symfony\UX\Turbo\Attribute\Broadcast;
#[Broadcast(topics: ['@="notifications_list_" ~ entity.getUser().getId()'], private: true)]
class Notification
{
// ...
} With each creation, a notification will be automatically added with the Broadcast system. A user can then view their own notifications with The generated code will be as follows: <div data-controller="symfony--ux-turbo--mercure-turbo-stream" data-symfony--ux-turbo--mercure-turbo-stream-hub-value="https://symfony.com/.well-known/mercure" data-symfony--ux-turbo--mercure-turbo-stream-topic-value="notifications_list_1"></div> Unfortunately, this is not secure because a malicious person will be able to change the value of the Here I talked about notifications, but it could also be valid for instant messaging for example. The idea would then be to secure the |
Let's add this to the conversatioon about stream sources : #2460 I'd like to keep talking about generic implementation first (but based on your specific need, it's a rich source of feedback / irl usage!) |
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