Skip to content

The CookieConsentService.CookiePreferencesChanged event is called two times #40

Description

@TomasMejzr

Hi,
I think there might be an issue with the CookieConsentService.CookiePreferencesChanged event:

public event EventHandler<CookiePreferences> CookiePreferencesChanged;

I use the CookieConsentHandler component in InteractiveServer render mode (without prerender).
I'm handling the CookieConsentService.CookiePreferencesChanged event, but the event fires two times. I thought, it was the issue with CookiePreferences equality check:
#39

That is a bug, but it didn't resolve the issue.

After further investigation, I found it has something to do with the CookieConsentEventHandler broadcasting the CookiePreferencesChanged event:

public async Task BroadcastCookiePreferencesChangedAsync(CookiePreferences cookiePreferences)
{
_ = Task.Run(() => CookiePreferencesChanged?.Invoke(this, cookiePreferences));
await PublishToJsAsync(JsBroadcastEventCookiePreferencesChanged,
JsonSerializer.Serialize(cookiePreferences));
}

Unlike the other events this one doesn't check _runtimeContext.RendersUserInterface.
It calls the event on the server and then publishes that event to JS towards WASM. Which in turn pops again from javascript as a second call.

As I've said, the component is in the InteractiveServer render mode.
I uderstand the intention for the component to be render mode agnostic, but in this case this doesn't seem to function correctly.

When I comment one of those callings, the event fires only once as expected.

Could You please check this scenario in InteractiveServer render mode ?

Thanks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions