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

docs: Improve documentation/logs around PostHogProvider #1675

Merged
merged 1 commit into from
Jan 23, 2025

Conversation

rafaeelaudibert
Copy link
Member

We're now logging more reasonable logs around our PostHogProvider to help customers identify problems with their setup. We're also typing that component much better to prevent people from getting it wrong at the type level.

Inspired by #769, but not a solution

@rafaeelaudibert rafaeelaudibert requested a review from a team January 22, 2025 18:23
Copy link

vercel bot commented Jan 22, 2025

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

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Jan 22, 2025 6:53pm

Comment on lines 9 to 18
/**
* Props for the PostHogProvider component.
* This is a discriminated union type that ensures mutually exclusive props:
*
* - If `client` is provided, `apiKey` and `options` must not be provided
* - If `apiKey` is provided, `client` must not be provided, and `options` is optional
*/
type PostHogProviderProps =
| { client: PostHog; apiKey?: undefined; options?: undefined }
| { apiKey: string; options?: Partial<PostHogConfig>; client?: undefined }
Copy link
Member Author

@rafaeelaudibert rafaeelaudibert Jan 22, 2025

Choose a reason for hiding this comment

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

This is somewhat of a breaking change at the type level. I know we've had other similar type-level breaking changes in the past. This is extremely easy to fix, all onboard with a minor update?

Copy link
Member

Choose a reason for hiding this comment

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

shouldn't they be never if they aren't supposed to be provided?

will folk have to change working correct code with this change?

Copy link
Member Author

@rafaeelaudibert rafaeelaudibert Jan 22, 2025

Choose a reason for hiding this comment

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

@pauldambra

shouldn't they be never if they aren't supposed to be provided?

That would work as well. The only difference is that my code allows you to call it with client={undefined} whilst never prevents it, so that's a good change, let me do that

will folk have to change working correct code with this change?

They might need to change it, but it was wrong before, so this could be considered a bugfix. We were already logging error messages to their console (but falling back to a reasonable behavior, which I kept for JS-only users).

Copy link
Member Author

Choose a reason for hiding this comment

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

shouldn't they be never if they aren't supposed to be provided?

Done, force-pushed the change

Copy link
Member

Choose a reason for hiding this comment

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

i really wish this was bundled as @posthog/react and we could version it separately
i guess this never hits people through the html snippet?
so you have to run my-package-manager update to get the change
but then we'd be making you change code without a major upgrade... which is yucky

if we were going to be good citizens we'd add a new provider and deprecate the old one... is there a not yuck way of doing that?

Copy link
Member Author

Choose a reason for hiding this comment

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

i really wish this was bundled as @posthog/react and we could version it separately

Oh, absolutely. I might do that, and then we would keep this component as is, and add a big deprecation notice telling people to move to @posthog/react instead. Thoughts?

i guess this never hits people through the html snippet?

They're not using React if they're using the HTML snippet, so yeah, we can do slightly-more-dangerous stuff here if we want to. That's why I wouldn't be opposed to simply merging this and moving to the performance issue I'm delaying :)

but then we'd be making you change code without a major upgrade... which is yucky

Is it though? IMO, it's reasonable to expect someone would have to change the code if we had a bad bug, and I wouldn't argue for a major release. This isn't a bad bug, of course, but if anyone was using the Library in that way, it's kind of a bug.

if we were going to be good citizens we'd add a new provider and deprecate the old one... is there a not yuck way of doing that?

yuck all around, I'd be against this, I'd argue it's more painful for customers to understand why the heck do we have 2 providers vs. having to remove 2 props on a minor bump.

Copy link

github-actions bot commented Jan 22, 2025

Size Change: 0 B

Total Size: 3.27 MB

ℹ️ View Unchanged
Filename Size
dist/all-external-dependencies.js 209 kB
dist/array.full.es5.js 266 kB
dist/array.full.js 370 kB
dist/array.full.no-external.js 369 kB
dist/array.js 182 kB
dist/array.no-external.js 180 kB
dist/customizations.full.js 13.8 kB
dist/dead-clicks-autocapture.js 14.4 kB
dist/exception-autocapture.js 9.48 kB
dist/external-scripts-loader.js 2.64 kB
dist/main.js 182 kB
dist/module.full.js 370 kB
dist/module.full.no-external.js 369 kB
dist/module.js 182 kB
dist/module.no-external.js 180 kB
dist/recorder-v2.js 116 kB
dist/recorder.js 116 kB
dist/surveys-preview.js 67.5 kB
dist/surveys.js 64.2 kB
dist/tracing-headers.js 1.76 kB
dist/web-vitals.js 10.4 kB

compressed-size-action

We're now logging more reasonable logs around our PostHogProvider to help customers identify problems with their setup. We're also typing that component much better to prevent people from getting it wrong at the type level.

Inspired by #769, but not a solution
@rafaeelaudibert rafaeelaudibert force-pushed the improve-documentation-around-posthog-provider branch from ce3c250 to 9067391 Compare January 22, 2025 18:33
@rafaeelaudibert rafaeelaudibert added the bump minor Bump minor version when this PR gets merged label Jan 22, 2025
Copy link
Collaborator

@benjackwhite benjackwhite left a comment

Choose a reason for hiding this comment

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

Looks good i think?

@rafaeelaudibert rafaeelaudibert merged commit 25b28ca into main Jan 23, 2025
31 checks passed
@rafaeelaudibert rafaeelaudibert deleted the improve-documentation-around-posthog-provider branch January 23, 2025 15:03
@tiagoskaneta
Copy link

tiagoskaneta commented Jan 24, 2025

Quick note here that this was definitely a breaking change. As the typescript definition changed we caught this during build so we never saw the warning and had to investigate it. The fix is trivial but at least a note in the release note would have been appreciated.

That said, it's a nice change ;)

@pauldambra
Copy link
Member

hey @tiagoskaneta thanks for the feedback 💖 we want to get to a place where we can version posthog/react and posthog/web separately... the changelog is auto-generated, but we could have edited it.

out of interest since the setup before allowed technically "incorrect" setup... how did this manifest for you? is it better now?

@tiagoskaneta
Copy link

out of interest since the setup before allowed technically "incorrect" setup... how did this manifest for you? is it better now?

We were using the <PostHogProvider> without any argument, which I understand now to be an "incorrect" setup. After the change, during typescript checking (triggered by a dependabot bump) we caught the breaking change. As no significant change was flagged in the release notes, I checked the repo and got to this PR.
In our case, we were already instantiating and initializing posthog, so the fix was just to add client={posthog}, so simple enough and no harm done 😃

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

Successfully merging this pull request may close these issues.

4 participants