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

Conversation

pauldambra
Copy link
Member

relates to #1344

we're checking the presence of a method on something that could be undefined

but we don't correctly type all the lazy load stuff, so TS doesn't complain

this at least safely checks the presence and will warn instead
we're likely calling the method too early (before it has had a chance to be added to the window) this might even be safe, so we definitely shouldn't throw

Copy link

vercel bot commented Sep 5, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Sep 5, 2024 3:19pm

@pauldambra pauldambra requested a review from a team September 5, 2024 14:28
Copy link

github-actions bot commented Sep 5, 2024

Size Change: +168 B (+0.01%)

Total Size: 1.18 MB

Filename Size Change
dist/array.full.js 336 kB +42 B (+0.01%)
dist/array.js 156 kB +42 B (+0.03%)
dist/main.js 157 kB +42 B (+0.03%)
dist/module.js 156 kB +42 B (+0.03%)
ℹ️ View Unchanged
Filename Size
dist/exception-autocapture.js 10.4 kB
dist/recorder-v2.js 110 kB
dist/recorder.js 111 kB
dist/surveys-preview.js 59.8 kB
dist/surveys.js 66 kB
dist/tracing-headers.js 8.26 kB
dist/web-vitals.js 5.79 kB

compressed-size-action

Copy link
Contributor

@jurajmajerik jurajmajerik left a comment

Choose a reason for hiding this comment

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

makes sense, thanks 🙏

@pauldambra pauldambra added the bump patch Bump patch version when this PR gets merged label Sep 6, 2024
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.

Copy link
Contributor

@Phanatic Phanatic left a comment

Choose a reason for hiding this comment

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

This looks good, ship it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump patch Bump patch version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants