Skip to content

Fix cio js client events not firing #205

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mocca102
Copy link
Contributor

@mocca102 mocca102 commented Apr 15, 2025

The bug is that currently, you can’t listen to any of the dispatched events from the ConstructorIO client. Basically, this does not work.

window.addEventListener('cio.client.autocomplete.getAutocompleteResults.completed', () => {});

This line is the reason. waitForBeacon is true by default. Because we don’t load the beacon on OS UI AC the eventDispatcher remains inactive (active = false)

// If `waitForBeacon` option is set, only enable event dispatching once event is received from beacon
if (this.waitForBeacon) {
      this.active = false;
}

To fix the bug we just need to pass this to the cio instance

const cioClient = new ConstructorIOClient({
      ...
      eventDispatcher: { waitForBeacon: false },
});

To test the changes add this anywhere

window.addEventListener('cio.client.autocomplete.getAutocompleteResults.completed', (ev) => {
     console.log('event', event)
});

@mocca102 mocca102 requested a review from a team as a code owner April 15, 2025 21:10
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

Successfully merging this pull request may close these issues.

1 participant