-
-
Notifications
You must be signed in to change notification settings - Fork 356
[Turbo] add options to EventSource Mercure #1774
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
Conversation
But I think the |
You have right @tibobaldwin for the first call, but after the Turbo takes over. |
But then, how do I add the |
Great, this PR is very interesting :). |
Sorry @tibobaldwin & @seb-jean, but I think it's not the place for these questions. Check the issue or the documentation? But an example: {% block javascripts %}
<script>
const eventSource = new EventSource("{{ mercure('https://example.com/books/1', { subscribe: ['https://example.com/books/1'] })|escape('js') }}", {
withCredentials: true
});
</script>
{% endblock %}
{% block content %}
<div id="messages" {{ turbo_stream_listen('https://example.com/books/1', eventSourceOptions = {withCredentials: true}) }}
Content
</div>
{% endblock %} Without this PR, you need to create your own turbo stream controller and call like this: ...
{% block content %}
<div id="messages" data-controller="turbo-stream" data-turbo-stream-topic-value="https://example.com/books/1" data-turbo-stream-hub-value="{{ mercure() }}"
Content
</div>
{% endblock %} |
Thanks. This is mainly to set the cookie in fact. |
Why this isn't merged yet? Seems totally fine to me, and very helpful. |
*/ | ||
public function renderTurboStreamListen(Environment $env, $topic): string; | ||
public function renderTurboStreamListen(Environment $env, $topic, array $eventSourceOptions = []): string; |
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 add parameter on an interface, even with default values, without breaking existing implementation.
interface FooInterface
{
public function bar(string $a, array $eventSourceOptions = []): string;
}
class AppFoo implements FooInterface
{
// existing method matching previous interface
public function bar(string $a): string
{
return $a;
}
}
This throws a PHP Fatal error as a the concrete implementation is not compatible anymore (see here).
Fatal error: Declaration of AppFoo::bar(string $a): string must be compatible with FooInterface::bar(string $a, array $eventSourceOptions = []): string in php-wasm run script on line 11
So to make this change in a BC way, you need:
- to comment the new argument in the interface
- to use func_get_args to fetch the value in the concrete class
You can see here a recent example of Symfony PR with similar BC layer: symfony/symfony#54531
Poke me if you need a hand here!
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 very sorry @ytilotti i must have missed the re-review request.
I just made a comment about the BC break and how to solve it.
Also, could you add a test here ?
I think we will be good for the next release :)
Indeed closing here as the feature is now implemented |
To prevent 401 with Mercure & Turbo stream on different domain, add an options for EventSource is required.
Exemple of code: