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: improve survey bundle size v2 #1759

Merged
merged 2 commits into from
Feb 22, 2025

Conversation

lucasheriques
Copy link
Contributor

@lucasheriques lucasheriques commented Feb 22, 2025

Changes

Follow up to #1665 which I'll prob close.

I realized the method we were loading lazily, getSurveyNextStep was only really used inside the Surveys file (extension/surveys.tsx).

However, we were still loading it under the posthog-core.ts, which it doesn't really need.

So, instead of trying to load it individually lazily, I just added it to the main surveys extension file, and it can be loaded directly with that.

It also allows us to remove the old sdk / no branching logic, since, once they update their survey, everything will come from the surveys extension.

@pauldambra tagged you as my local posthog-js expert, let me know if this reasoning makes sense

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Feb 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 Feb 22, 2025 4:20pm

@lucasheriques lucasheriques force-pushed the fix/improve-survey-bundle-size-v2 branch from 9d1bfd9 to 6429be9 Compare February 22, 2025 05:26
Copy link

github-actions bot commented Feb 22, 2025

Size Change: -7.08 kB (-0.21%)

Total Size: 3.32 MB

Filename Size Change
dist/all-external-dependencies.js 218 kB +1.5 kB (+0.69%)
dist/array.full.es5.js 270 kB -231 B (-0.09%)
dist/array.full.js 373 kB -209 B (-0.06%)
dist/array.full.no-external.js 372 kB -209 B (-0.06%)
dist/array.js 183 kB -1.71 kB (-0.93%)
dist/array.no-external.js 181 kB -1.71 kB (-0.93%)
dist/main.js 183 kB -2.05 kB (-1.11%)
dist/module.full.js 373 kB -209 B (-0.06%)
dist/module.full.no-external.js 372 kB -209 B (-0.06%)
dist/module.js 183 kB -1.71 kB (-0.92%)
dist/module.no-external.js 182 kB -1.71 kB (-0.93%)
dist/surveys-preview.js 70.1 kB -123 B (-0.18%)
dist/surveys.js 74.9 kB +1.49 kB (+2.03%)
ℹ️ View Unchanged
Filename Size
dist/customizations.full.js 14 kB
dist/dead-clicks-autocapture.js 14.5 kB
dist/exception-autocapture.js 9.51 kB
dist/external-scripts-loader.js 2.64 kB
dist/recorder-v2.js 115 kB
dist/recorder.js 115 kB
dist/tracing-headers.js 1.76 kB
dist/web-vitals.js 10.4 kB

compressed-size-action

@lucasheriques lucasheriques changed the title fix: improve survey bundle size fix: improve survey bundle size v2 Feb 22, 2025
@lucasheriques lucasheriques marked this pull request as ready for review February 22, 2025 05:32
@lucasheriques lucasheriques requested a review from a team as a code owner February 22, 2025 05:32
@lucasheriques lucasheriques self-assigned this Feb 22, 2025
@lucasheriques lucasheriques added feature/surveys bump patch Bump patch version when this PR gets merged labels Feb 22, 2025
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

This PR optimizes bundle size by relocating survey-related logic from core files to the surveys extension.

  • Moved getNextSurveyStep and getRatingBucketForResponseValue functions from posthog-core.ts to src/extensions/surveys.tsx
  • Updated imports in src/entrypoints/surveys-preview.es.ts to reference functions directly from surveys extension
  • Removed old SDK/branching logic since surveys will be loaded with the extension
  • Consolidated survey-specific functionality in surveys.tsx to prevent unnecessary code loading
  • Updated test imports in src/__tests__/surveys.test.ts to reflect new function locations

5 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Copy link
Member

@marandaneto marandaneto left a comment

Choose a reason for hiding this comment

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

assuming this is not breaking the frontend that depends on the next question for the survey preview, LGTM

@@ -1341,15 +1341,6 @@ export class PostHog {
this.surveys.canRenderSurvey(surveyId)
}

/** Get the next step of the survey: a question index or `end` */
getNextSurveyStep(
Copy link
Member

Choose a reason for hiding this comment

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

since this is on posthog core could someone have integrated with it? should we keep the method and replace it instead with a deprecation log message, then replace it after some time?

(you all the experts on surveys so i may be worrying unnecessarily)

because of the lazy loading we always have to consider someone with posthog-js main bundle pre-this-change and latest lazy bundle

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be fine, i checked for that! ran all e2e tests on posthog/posthog and did smoke tests for surveys extensively. didn't saw any other usage besides surveys' domain

Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

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

one comment on how to think about avoiding breaking releases here but only to make sure you've thought about it 😊

otherwise, love this kind of analysis and CI is green 🙌

@lucasheriques lucasheriques merged commit c3da349 into main Feb 22, 2025
25 checks passed
@lucasheriques lucasheriques deleted the fix/improve-survey-bundle-size-v2 branch February 22, 2025 17:09
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 feature/surveys
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants