Skip to content

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

@tamcy

Description

@tamcy

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions