Skip to content

fix(feedback): Inject preact from feedbackModal into feedbackScreenshot integration #12535

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

Merged
merged 3 commits into from
Jun 24, 2024

Conversation

ryan953
Copy link
Member

@ryan953 ryan953 commented Jun 18, 2024

I believe the error we're seeing in #12534 is from having preact bundled twice: once into the Modal integration, and then again into the Screenshot one.

This PR updates the Screenshot code so that it requires preact to be injected into it, which should reduce the bundle size of that integration, but also solve the bug because there will only be one instance of preact and it's state within the sdk.

Fixes #12534

@ryan953 ryan953 requested a review from a team as a code owner June 18, 2024 22:31
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.

How do we ensure this doesn't regress in the future?

@ryan953
Copy link
Member Author

ryan953 commented Jun 24, 2024

How do we ensure this doesn't regress in the future?

It'd be good to have the bundle-size check again. i expect if we're fixing the problem correctly, size will be smaller for the screenshot portion

Copy link
Contributor

size-limit report 📦

Path Size
@sentry/browser 22.22 KB (0%)
@sentry/browser (incl. Tracing) 33.31 KB (0%)
@sentry/browser (incl. Tracing, Replay) 69.09 KB (0%)
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 62.42 KB (0%)
@sentry/browser (incl. Tracing, Replay with Canvas) 73.15 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) 85.76 KB (+0.49% 🔺)
@sentry/browser (incl. Tracing, Replay, Feedback, metrics) 87.62 KB (+0.48% 🔺)
@sentry/browser (incl. metrics) 26.5 KB (0%)
@sentry/browser (incl. Feedback) 38.87 KB (+1.08% 🔺)
@sentry/browser (incl. sendFeedback) 26.85 KB (-0.02% 🔽)
@sentry/browser (incl. FeedbackAsync) 31.45 KB (-0.01% 🔽)
@sentry/react 24.97 KB (0%)
@sentry/react (incl. Tracing) 36.36 KB (0%)
@sentry/vue 26.33 KB (0%)
@sentry/vue (incl. Tracing) 35.17 KB (0%)
@sentry/svelte 22.36 KB (0%)
CDN Bundle 23.42 KB (0%)
CDN Bundle (incl. Tracing) 35.05 KB (0%)
CDN Bundle (incl. Tracing, Replay) 69.18 KB (0%)
CDN Bundle (incl. Tracing, Replay, Feedback) 74.38 KB (0%)
CDN Bundle - uncompressed 68.8 KB (0%)
CDN Bundle (incl. Tracing) - uncompressed 103.66 KB (0%)
CDN Bundle (incl. Tracing, Replay) - uncompressed 214.13 KB (0%)
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 226.79 KB (0%)
@sentry/nextjs (client) 36.24 KB (0%)
@sentry/sveltekit (client) 33.95 KB (0%)
@sentry/node 113.27 KB (+0.01% 🔺)
@sentry/node - without tracing 90.65 KB (0%)
@sentry/aws-serverless 99.74 KB (0%)

@ryan953
Copy link
Member Author

ryan953 commented Jun 24, 2024

Welp, bundle sizes are about the same, up by ~420bytes.

I guess that's the overhead of the extra variable passing? If we look at the bundled files (esm, easier to see) we can see that feedback-modal has preact inside it, and feedback-screenshot does not:
https://gist.github.com/ryan953/5f5846d894bc8d534007414ab3af3b02

See line 1206 in feedback-modal.tsx which includes var hooks = /*#__PURE__*/Object.freeze({
That should be a difference of 14kb

This is what I expected, but

@ryan953
Copy link
Member Author

ryan953 commented Jun 24, 2024

aha! We can't trust these bundle numbers because above for what we're doing here. Any bundle in the size-limit report above with "Feedback" in it will include all code. It's expected that stuff will be tree-shaken if modal & screenshots are not needed or async loaded.

I added a case to https://github.com/getsentry/sentry-javascript/blob/70e942d6426da9f8ce1ed1a267e266620e07da24/packages/feedback/rollup.bundle.config.mjs to compare the bundle sizes of all three integrations directly, ran it before and after this change.

this is the new snippet ...makeBundleConfigVariants( makeBaseBundleConfig({ bundleType: 'addon', entrypoints: ['src/core/integration.ts'], jsVersion: 'es6', licenseTitle: '@sentry-internal/feedback-core', outputFileBase: () => 'bundles/feedback-core', sucrase: { // The feedback widget is using preact so we need different pragmas and jsx runtimes jsxPragma: 'h', jsxFragmentPragma: 'Fragment', jsxRuntime: 'classic', }, }), ),

The numbers for the built files are:

Integration File Size Before (bytes) File Size After (bytes
bundles/feedback-core 58,678 58,717
bundles/feedback-modal 70,127 71,372
bundles/feedback-screenshot 20,369 17,156
delta - -1,929

So by those numbers we should be shifting some bytes from screenshots into modal, but saving 2kb overall. Assuming tree-shaking is happening. If there's no tree-shaking then folks shouldn't use the async bundle at all, they'll get the full bundle, which is represented in the size-limit report above.

@ryan953 ryan953 merged commit c49c9f3 into develop Jun 24, 2024
113 checks passed
@ryan953 ryan953 deleted the ryan953/12534-feedback-inject-preact branch June 24, 2024 22:12
ryan953 added a commit that referenced this pull request Jul 8, 2024
…12784)

This broke the `Add a screenshot` button on the user feedback, see
#12713

This has been explicitly removed in favor of injecting `h` in
#12535 but at that
point it seems to be too late to do.

Co-authored-by: Ryan Albrecht <[email protected]>
andreiborza pushed a commit that referenced this pull request Jul 9, 2024
I noticed this after
#12784, but the
`<CropCorner>` wasn't inside the `ScreenshotEditorFactory()` function.
So of course it wasn't getting access to the `h` ref that is passed in.
That variable is what the `<div>` gets transpiled into -> it becomes
`h.createElement('div')`.

So what i'm doing is moving `CropCorner` into a `CropCornerFactory` so
we can pass `h` in and hopefully not have the extra `import .. from
'preact';` in the 2nd bundle.

Related to #12535
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.

Bug Report: Screenshot Button Error in Report a Bug Form
2 participants