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)[AGE-1418]: Improve posthog initialization to reduce load on bundle size #2357

Merged

Conversation

ardaerzin
Copy link
Contributor

@ardaerzin ardaerzin commented Dec 9, 2024

closes AGE-1418

posthog library import &/ usePosthog hook is a 50kb direct addition to our first loaded JS.

What has changed?

  • load & init posthog-js dynamically from a custom provider component
  • store initialized posthog instance in a Jotai atom
    • due to large import size of the usePostHog hook and provider imported from posthog-js/react package.
    • didn't want to trigger an additional rendering cycle in all components once posthog is loaded dynamically [atom vs context]
  • update and relocate usePostHogAg to be closer to the analytics files.

Suggestions for testing

  • check data transferred to posthog for completeness

Copy link

vercel bot commented Dec 9, 2024

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

Name Status Preview Comments Updated (UTC)
agenta ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 16, 2024 0:03am
agenta-documentation ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 16, 2024 0:03am

Copy link

sentry-io bot commented Dec 9, 2024

🔍 Existing Issues For Review

Your pull request is modifying functions with the following pre-existing issues:

📄 File: agenta-web/src/pages/_app.tsx

Function Unhandled Issue
App TypeError: Cannot destructure property 'Component' of 'undefined' as it is undefined. GET /apps/0193ab06-13...
Event Count: 1 Affected Users: 0

Did you find this useful? React with a 👍 or 👎

@ardaerzin ardaerzin changed the title (frontend)[AGE-1414]: Improve posthog initialization to reduce load on bundle size (frontend)[AGE-1418]: Improve posthog initialization to reduce load on bundle size Dec 10, 2024
@mmabrouk mmabrouk changed the base branch from main to dev December 11, 2024 12:01
Copy link
Member

@bekossy bekossy left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @ardaerzin. LGTM

@ardaerzin ardaerzin requested a review from bekossy December 11, 2024 15:02
@ardaerzin
Copy link
Contributor Author

Thanks for the PR @ardaerzin. LGTM

had to bring useIsomorphicLayoutEffect here as the old hook was gone in this branch

@mmabrouk mmabrouk merged commit a74e95e into dev Dec 17, 2024
6 checks passed
@mmabrouk mmabrouk deleted the AGE-1414/improve-posthog-imports-to-reduce-initial-bundle-size branch December 17, 2024 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frontend lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants