Skip to content
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

Open
wants to merge 1 commit into
base: 2.x
Choose a base branch
from

Conversation

Fan2Shrek
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
Issues Fix #1860 I think
License MIT

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

@carsonbot carsonbot added Feature New Feature Status: Needs Review Needs to be reviewed labels Dec 12, 2024
Copy link

github-actions bot commented Dec 12, 2024

📊 Packages dist files size difference

Thanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
Please review the changes and make sure they are expected.

FileBefore (Size / Gzip)After (Size / Gzip)
Turbo
turbo_stream_controller.d.ts 562 B / 280 B 651 B+16% 📈 / 303 B+8% 📈
turbo_stream_controller.js 1.27 kB / 535 B 1.35 kB+6% 📈 / 565 B+6% 📈

@Fan2Shrek Fan2Shrek force-pushed the add-option-to-turbo-stream branch 3 times, most recently from 867707d to 06ac699 Compare December 12, 2024 22:35
src/Turbo/CHANGELOG.md Outdated Show resolved Hide resolved
unset($options['subscribe'], $options['publish'], $options['additionalClaims']);
}

return $this->turboStreamListenRenderers->get($transport)->renderTurboStreamListen($env, $topic, $options);
Copy link
Member

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.

Copy link
Contributor Author

@Fan2Shrek Fan2Shrek Dec 13, 2024

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 ?

@@ -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;
Copy link
Member

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

#2407

Copy link
Contributor Author

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 ?

@carsonbot carsonbot added Status: Needs Work Additional work is needed and removed Status: Needs Review Needs to be reviewed labels Dec 13, 2024
@Fan2Shrek Fan2Shrek force-pushed the add-option-to-turbo-stream branch from 06ac699 to abcc723 Compare December 13, 2024 18:02
@carsonbot carsonbot added Status: Needs Review Needs to be reviewed and removed Status: Needs Work Additional work is needed labels Dec 13, 2024
@Fan2Shrek Fan2Shrek force-pushed the add-option-to-turbo-stream branch from abcc723 to e95cbab Compare December 13, 2024 18:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Turbo] Add mercure() to turbo_stream_listen()
3 participants