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

feat(feedback): Create async bundles and code to resolve helper integrations #11621

Merged
merged 16 commits into from
Apr 21, 2024

Conversation

ryan953
Copy link
Member

@ryan953 ryan953 commented Apr 16, 2024

This imports the various feedback bits into @sentry/browser and re-exports them as two 'built' integrations:

  • feedbackIntegration
  • feedbackAsyncIntegration

The idea is that the former includes everything already imported, and the latter will leverage lazyLoadIntegration to bring in extra code when needed. This means that Sentry users can decide which integration to import as they setup the SDK. We can decide to a favored approach when we write the docs and installation instructions, right now for npm/yarn/pnpm users both options are viable.

There is, as of this PR, no CDN or Loader bundle that leverages async loading. The CDN bundles are published with all the code included.

The bundle sizes, compressed, are currently at:

bundle name additional size from prev row code included
@sentry/browser 21.67 KB base size
@sentry/browser (incl. sendFeedback) 26.45 KB +4.78KB over the base widget depends on this, see #11428
@sentry/browser (incl. FeedbackAsync) 30.93 KB +4.48KB "incl. sendFeedback" Actor button & async bootstrapping
@sentry/browser (incl. Feedback) 37.78 KB +6.85KB over "incl. FeedbackAsync" everything

The expectation is that as we add stuff to the Feedback bundle, FeedbackAsync won't get any larger at all.

To followup:

  • What should the developer see, and what should the user see if integrations are missing and unable to be loaded in?
  • It seems like preact is not tree-shaken out of the main async bundle. Need to double check this. Running yarn site-limit --why and looking at @sentry/browser (incl. FeedbackAsync) is what I was looking at
  • Some types are unknown in the @sentry/types package, but not used outside of @sentry/feedback. These can probably be re-integrated and improved in a followup PR.

Fixes #11435

Copy link
Contributor

github-actions bot commented Apr 16, 2024

size-limit report 📦

Path Size
@sentry/browser 21.67 KB (0%)
@sentry/browser (incl. Tracing) 31.4 KB (0%)
@sentry/browser (incl. Tracing, Replay) 66.73 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 60.14 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay with Canvas) 70.57 KB (-0.01% 🔽)
@sentry/browser (incl. Tracing, Replay, Feedback) 82.96 KB (+3.14% 🔺)
@sentry/browser (incl. Feedback) 37.78 KB (+7.19% 🔺)
@sentry/browser (incl. Feedback, Feedback Modal) 0 B (removed)
@sentry/browser (incl. Feedback, Feedback Modal, Feedback Screenshot) 0 B (removed)
@sentry/browser (incl. sendFeedback) 26.45 KB (-0.05% 🔽)
@sentry/react 24.35 KB (0%)
@sentry/react (incl. Tracing) 34.31 KB (0%)
@sentry/vue 25.2 KB (0%)
@sentry/vue (incl. Tracing) 33.12 KB (0%)
@sentry/svelte 21.79 KB (0%)
CDN Bundle 23.97 KB (-0.25% 🔽)
CDN Bundle (incl. Tracing) 32.65 KB (-0.18% 🔽)
CDN Bundle (incl. Tracing, Replay) 66.31 KB (-0.09% 🔽)
CDN Bundle (incl. Tracing, Replay, Feedback) 82.09 KB (-0.58% 🔽)
CDN Bundle - uncompressed 70.62 KB (-0.32% 🔽)
CDN Bundle (incl. Tracing) - uncompressed 97.27 KB (-0.24% 🔽)
CDN Bundle (incl. Tracing, Replay) - uncompressed 206.93 KB (-0.11% 🔽)
@sentry/nextjs (client) 33.64 KB (0%)
@sentry/sveltekit (client) 31.9 KB (0%)
@sentry/node 158.85 KB (-0.01% 🔽)
@sentry/browser (incl. FeedbackAsync) 30.93 KB (added)
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 253.22 KB (added)

@ryan953 ryan953 requested review from a team and AbhiPrasad April 16, 2024 23:19
@billyvg
Copy link
Member

billyvg commented Apr 17, 2024

It looks like @sentry/browser (incl. Feedback) == @sentry/browser (incl. FeedbackAsync) -- wouldn't be expect the latter to be smaller?

@ryan953
Copy link
Member Author

ryan953 commented Apr 17, 2024

It looks like @sentry/browser (incl. Feedback) == @sentry/browser (incl. FeedbackAsync) -- wouldn't be expect the latter to be smaller?

ya, i think i need to have different entrypoints, right now it's re-using the same index.ts file.

but i also noticed that feedbackAsyncIntegration() doesn't work in npm land because the window.Sentry member is not set. So i've been looking at that.

@ryan953 ryan953 marked this pull request as ready for review April 17, 2024 21:14
@ryan953
Copy link
Member Author

ryan953 commented Apr 18, 2024

@mydea can you take another look at the async loader helper function? It seems to me that it only works when the SDK is loaded via CDN and window.Sentry exists.
In npm builds we either have to have the code bundled or else it won't work.

Also, I was surprised the sizes are the same even though imports are different for the Feedback and FeedbackAsync variants that the CI posted above and Billy pointed out.

@mydea
Copy link
Member

mydea commented Apr 18, 2024

@mydea can you take another look at the async loader helper function? It seems to me that it only works when the SDK is loaded via CDN and window.Sentry exists. In npm builds we either have to have the code bundled or else it won't work.

Also, I was surprised the sizes are the same even though imports are different for the Feedback and FeedbackAsync variants that the CI posted above and Billy pointed out.

Hopefully fixed here: #11673

@ryan953 ryan953 force-pushed the ryan953/async-bundles branch from f2f0d83 to 55500be Compare April 18, 2024 16:49
@ryan953
Copy link
Member Author

ryan953 commented Apr 18, 2024

@billyvg following up, i expected that the size for @sentry/browser (incl. FeedbackAsync) would be 30.94KB and the full incl. Feedback bundle 38.26KB.

Once that's sorted we should be all set imo

@ryan953 ryan953 force-pushed the ryan953/async-bundles branch from 5c5130a to 55500be Compare April 18, 2024 18:39
Copy link
Member Author

Choose a reason for hiding this comment

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

The bundler seemed like it wasn't tree-shaking properly when this file was combined with src/feedback.ts. Splitting them apart resulted in the bundle-sizes I expected

feedbackScreenshotIntegration,
getFeedback,
} from '@sentry-internal/feedback';
export { feedbackIntegration } from './feedback';
Copy link
Member Author

@ryan953 ryan953 Apr 19, 2024

Choose a reason for hiding this comment

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

Note that we're using feedbackIntegration as the default here, not feedbackAsyncIntegration. (same in the othe bundle configs)
So CDN users, by default, won't have async loading.

This is something we can talk about and change outside this PR


// This is for users who want to have a lazy-loaded feedback widget
export const feedbackAsyncIntegration = buildFeedbackIntegration({
lazyLoadIntegration,
Copy link
Member Author

Choose a reason for hiding this comment

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

This whole buildFeedbackIntegration exists, and is called from inside the browser package, so that we can inject lazyLoadIntegration instead of creating a circular dependency between @sentry/browser and @sentry/feedback.

Copy link
Member

@billyvg billyvg left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +42 to +44
// The type here should be `keyof typeof LazyLoadableIntegrations`, but that'll cause a cicrular
// dependency with @sentry/core
lazyLoadIntegration: (name: 'feedbackModalIntegration' | 'feedbackScreenshotIntegration') => Promise<IntegrationFn>;
Copy link
Member

Choose a reason for hiding this comment

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

not for this PR, but should this type be moved to @sentry/types?

Copy link
Member Author

@ryan953 ryan953 Apr 19, 2024

Choose a reason for hiding this comment

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

ya, we can do that in a followup. It depends on a list of strings, keyof so might need some copy+paste too.

packages/feedback/src/core/integration.ts Outdated Show resolved Hide resolved
]);
if (!modalIntegration || (showScreenshot && !screenshotIntegration)) {
// trouble!
throw new Error('Missing feedback helper integration!');
Copy link
Member

Choose a reason for hiding this comment

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

Do we know how an integration could be missing? Would be helpful to provide a potential solution or a link to one

Copy link
Member Author

Choose a reason for hiding this comment

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

Idk if we strictly know what was supposed to be setup and failed. Certainly if either is missing then the async loading didn't work.

That could easily happen on purpose if the site relies on async loading but the user is offline right now, for example.

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 updated the comment with a TODO. We can for sure add help for the developer so they can make any adjustments, but user-facing i'm not sure where to go with it.

@ryan953 ryan953 merged commit a6e7324 into develop Apr 21, 2024
96 checks passed
@ryan953 ryan953 deleted the ryan953/async-bundles branch April 21, 2024 23:32
mydea added a commit that referenced this pull request Apr 23, 2024
As noticed by @ryan953 here:
#11621 (comment),
this was not actually working properly in NPM-mode. I added a proper
test for this and fixed this, so hopefully should be all good now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Lazy load feedback screenshot
3 participants