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

Unable to use the mercure() Twig function to subscribe to two different URLs at different places #71

Closed
tamcy opened this issue Jun 23, 2022 · 4 comments

Comments

@tamcy
Copy link

tamcy commented Jun 23, 2022

Hello,

Assume that I want to subscribe to two (or more) private updates. By intuition I'd write this:

<div data-mercure-url="{{ mercure('https://example.com/user/3', { subscribe: 'https://example.com/user/3' }) }}"></div>
...
<div data-mercure-url="{{ mercure('https://example.com/books/1', { subscribe: 'https://example.com/books/1' }) }}"></div>

But doing so will cause the following exception from Symfony\Component\Mercure\Authorization::updateCookies:

An exception has been thrown during the rendering of a template ("The "mercureAuthorization" cookie for the "default hub" has already been set. You cannot set it two times during the same request.").

I am currently working around this by specifying all subscribing URLs in one of the mercure() function call:

<div data-mercure-url="{{ mercure('https://example.com/user/3', { subscribe: ['https://example.com/user/3', 'https://example.com/books/1'] }) }}"></div>
...
<div data-mercure-url="{{ mercure('https://example.com/books/1' }}"></div>

This works, but doesn't look straightforward. Is this a limitation of the current implmentation of the bundle, or am I doing it wrongly?

@frizquierdo
Copy link

Hi @tamcy, the second approach is the correct way, passing an array of topics.

@ThomasLandauer
Copy link

See symfony/symfony-docs#20574

javiereguiluz added a commit to symfony/symfony-docs that referenced this issue Jan 21, 2025
This PR was merged into the 6.4 branch.

Discussion
----------

[Mercure] Adding hint for multiple topics

Page: https://symfony.com/doc/6.4/mercure.html#subscribing

Closes #20574 Closes symfony/mercure-bundle#71 Closes symfony/mercure-bundle#82

Info is taken from #20574 (comment)

Commits
-------

3dca32e [Mercure] Adding hint for multiple topics
@ThomasLandauer
Copy link

IMO, this can be closed by symfony/symfony-docs#20580

@dunglas dunglas closed this as completed Jan 21, 2025
@dunglas
Copy link
Member

dunglas commented Jan 21, 2025

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants