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

🩹(frontend) prevent runtime error when Crisp is not initialized #318

Merged
merged 2 commits into from
Jan 29, 2025

Conversation

lebaudantoine
Copy link
Collaborator

Prevents runtime error when Crisp chat hasn't initialized before component mount Previously caused crash since we assumed $crisp global was always available.

Comment on lines +10 to +12
const [isOpened, setIsOpened] = useState(() => {
return window?.$crisp?.is?.('chat:opened') || false
})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

afterthought, should we hide the toggle if crisp isn't defined. I'm scared it would cause layout shifts;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My review comment reply to this in an indirect way

Copy link
Collaborator

@NathanVss NathanVss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems it may sometimes caused by a race condition due to network speed. I do not find it nice to set it closed only because we are not waiting for $crisp to be fully loaded.

But in the same time I can't find a way to "wait for $crisp to be loaded" in the officiel doc here: https://docs.crisp.chat/guides/chatbox-sdks/web-sdk/dollar-crisp/

WDYT?

EDIT: Maybe "https://docs.crisp.chat/guides/chatbox-sdks/web-sdk/dollar-crisp/" "Session has loaded" ?

Prevents runtime error when Crisp chat hasn't initialized before component mount
Previously caused crash since we assumed $crisp global was always available.
Avoid misleading the user, if support is not enabled, as it's optional,
avoid displaying a useless control button.

Requested by Dutch counterparts.
@lebaudantoine
Copy link
Collaborator Author

It closes #321

@lebaudantoine lebaudantoine merged commit 4ae3d96 into main Jan 29, 2025
9 of 10 checks passed
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.

2 participants