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

fix: warn on unavailable lazy load not throw #1400

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/posthog-surveys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,9 @@ export class PostHogSurveys {

// this method is lazily loaded onto the window to avoid loading preact and other dependencies if surveys is not enabled
private _canActivateRepeatedly(survey: Survey) {
if (isNullish(assignableWindow.__PosthogExtensions__.canActivateRepeatedly)) {
if (isNullish(assignableWindow.__PosthogExtensions__?.canActivateRepeatedly)) {
logger.warn(LOGGER_PREFIX, 'canActivateRepeatedly is not defined, must init before calling')
return false // TODO does it make sense to have a default here?
Copy link
Member Author

Choose a reason for hiding this comment

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

@jurajmajerik @dmarticus i'm unfamiliar with this (and lazy 🤣 )

is it safe to return false here? will we accidentally disable surveys or something?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is fine.

This method is called here: https://github.com/PostHog/posthog-js/blob/fix/warn-not-throw/src/posthog-surveys.ts#L182

If you don't return false early than an error will be thrown on return.

@Phanatic can you double check please? I believe you've added this recently.

}
return assignableWindow.__PosthogExtensions__.canActivateRepeatedly(survey)
}
Expand Down
Loading