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): New feedback integration with screenshots #10590

Merged
merged 62 commits into from
Mar 14, 2024

Conversation

c298lee
Copy link
Member

@c298lee c298lee commented Feb 9, 2024

Replace the current screenshot package with a new package that has screenshots and uses Preact for better readability. It will also allow for lazy loading in the future.

Relates to: getsentry/sentry#63749

Copy link
Contributor

github-actions bot commented Feb 14, 2024

size-limit report 📦

Path Size
@sentry/browser (incl. Tracing, Replay, Feedback) - Webpack (gzipped) 84.32 KB (+9.27% 🔺)
@sentry/browser (incl. Tracing, Replay) - Webpack (gzipped) 68.43 KB (0%)
@sentry/browser (incl. Tracing, Replay with Canvas) - Webpack (gzipped) 72.34 KB (0%)
@sentry/browser (incl. Tracing, Replay) - Webpack with treeshaking flags (gzipped) 61.97 KB (0%)
@sentry/browser (incl. Tracing) - Webpack (gzipped) 32.65 KB (0%)
@sentry/browser (incl. browserTracingIntegration) - Webpack (gzipped) 32.65 KB (0%)
@sentry/browser (incl. Feedback) - Webpack (gzipped) 37.88 KB (+22.93% 🔺)
@sentry/browser (incl. sendFeedback) - Webpack (gzipped) 37.87 KB (+22.91% 🔺)
@sentry/browser - Webpack (gzipped) 22.09 KB (0%)
@sentry/browser (incl. Tracing, Replay, Feedback) - ES6 CDN Bundle (gzipped) 82.52 KB (+9.19% 🔺)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (gzipped) 67.26 KB (0%)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (gzipped) 33.09 KB (0%)
@sentry/browser - ES6 CDN Bundle (gzipped) 24.58 KB (0%)
@sentry/browser (incl. Tracing, Replay) - ES6 CDN Bundle (minified & uncompressed) 210.74 KB (0%)
@sentry/browser (incl. Tracing) - ES6 CDN Bundle (minified & uncompressed) 99.46 KB (0%)
@sentry/browser - ES6 CDN Bundle (minified & uncompressed) 73.64 KB (0%)
@sentry/browser (incl. Tracing) - ES5 CDN Bundle (gzipped) 36.16 KB (0%)
@sentry/react (incl. Tracing, Replay) - Webpack (gzipped) 68.71 KB (0%)
@sentry/react - Webpack (gzipped) 22.12 KB (0%)
@sentry/nextjs Client (incl. Tracing, Replay) - Webpack (gzipped) 85.18 KB (0%)
@sentry/nextjs Client - Webpack (gzipped) 49.52 KB (0%)
@sentry-internal/feedback - Webpack (gzipped) 24.15 KB (+41.78% 🔺)

@ryan953 ryan953 mentioned this pull request Feb 15, 2024
billyvg added a commit that referenced this pull request Feb 20, 2024
This allows you to configure Sucrase for rollup bundles.

Needed for our work on the Feedback screenshotting feature as we want to use Preact + JSX in the project. (ref: #10590)
c298lee and others added 9 commits February 22, 2024 00:53
This is building off a version of
#10590, specifically
working towards async loading of the Dialog component, and rewriting it
in preact in order to host and interact with the screenshot feature in
an easier way.

Setup in my test app is (gives screenshots):
```
import { feedback2Integration, feedback2ModalIntegration, feedback2ScreenshotIntegration } from "@sentry-internal/feedback2";


  integrations: [
    feedback2Integration({
      colorScheme: 'light',
      isNameRequired: false,
      isEmailRequired: false,
    }),
    feedback2ModalIntegration(),
    feedback2ScreenshotIntegration(),
  ]
```
style.textContent = `
:host {
--bottom: 1rem;
--right: 1rem;
--right: 1rem; /* this is the font-size of the page, not the shadowroot */
Copy link
Member

Choose a reason for hiding this comment

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

Is this comment in the right place?

Copy link
Member

Choose a reason for hiding this comment

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

I think it is, sorta... we don't need this comment, it's more like a TODO or 'dont forget'

The rem unit is relative to the page, so it could be set to something other than 16px and thus our modal spacing from the edge would be different as well.

Copy link
Member

Choose a reason for hiding this comment

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

let's remove this or make it a JS comment, otherwise it may just add unnecessary bytes I guess?

Comment on lines -57 to -62
position: fixed;
left: var(--left);
right: var(--right);
bottom: var(--bottom);
top: var(--top);
z-index: var(--z-index);
Copy link
Member

Choose a reason for hiding this comment

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

Are these not used?

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 has been moved into Actor.css

packages/feedback/src/modal/components/DialogContainer.tsx Outdated Show resolved Hide resolved
rules: {
'no-console': 'off',
'@sentry-internal/sdk/no-unsupported-es6-methods': 'off',
Copy link
Member

Choose a reason for hiding this comment

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

you can remove this, we have since removed this rule :)

rules: {
'@typescript-eslint/naming-convention': 'off',
'no-console': 'off',
Copy link
Member

Choose a reason for hiding this comment

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

hmm, do we really want to disable this? IMHO we should leave this on to avoid debugging stuff leaking in.

Copy link
Member

Choose a reason for hiding this comment

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

we don't even leverage that this is off. i'm removing it.

}

client.emit('beforeSendFeedback', feedbackEvent, { includeReplay: Boolean(includeReplay) });
try {
const response = await transport.send(
Copy link
Member

Choose a reason for hiding this comment

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

So instead of this, I think we can/should just use client.sendEvent(feedbackEvent). This will also take care of getsentry/sentry#66214 (comment), I believe. Or is there anything that is preventing this?

Copy link
Member

Choose a reason for hiding this comment

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

replacing this call seems to work fine, but we've got no response now, so the error messages are not going to come from this file.


if (attachments && attachments.length) {
// TODO: https://docs.sentry.io/platforms/javascript/enriching-events/attachments/
await transport.send(
Copy link
Member

Choose a reason for hiding this comment

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

See comment above, instead we can do client.sendEvent(feedbackEvent, { attachments }) to send another event with the attachments.

Copy link
Member

Choose a reason for hiding this comment

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

with either the transport.send or the client.sendEvent i'm not seeing a screenshot coming into sentry today. :(

Copy link
Member Author

Choose a reason for hiding this comment

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

yea sendEvent currently doesn't work with attachments due to our backend. If there's an attachment and a feedback within the same envelope, the screenshot doesn't come in. We have to send them in seperate envelopes, but once the backend is fixed we will be using sendEvent client.sendEvent(feedbackEvent, { attachments })


const envelope = createEventEnvelope(feedbackEvent, dsn, client.getOptions()._metadata, client.getOptions().tunnel);
// TODO (v8): we can remove this guard once transport.send's type signature doesn't include void anymore
Copy link
Member

Choose a reason for hiding this comment

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

This should already be done, so you can remove this check!

let response: TransportMakeRequestResponse;
// Require valid status codes, otherwise can assume feedback was not sent successfully
if (typeof response.statusCode === 'number' && (response.statusCode < 200 || response.statusCode >= 300)) {
throw new Error('Unable to send Feedback. Invalid response from server.');
Copy link
Member

Choose a reason for hiding this comment

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

While we are at it, or in a follow up, we could check for statusCode === 0 and show a message like:

Unable to send Feedback. This is because of network issues, or because you are using an ad-blocker.

Or something along these lines...!

@@ -0,0 +1,330 @@
// eslint-disable max-lines
Copy link
Member

Choose a reason for hiding this comment

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

This file is currently a bit long, but we will be iterating and will tidy up as we go.

@AbhiPrasad
Copy link
Member

try 1 at fixing ts3.8 integration test failure: #11088

Right now the feedback PR fails ts3.8 e2e tests. This is because of TS issues, preact types do not work well with older
TS types:

```
> @sentry-internal/ts3.8-test@ type-check /home/runner/work/sentry-javascript/sentry-javascript/dev-packages/e2e-tests/test-applications/generic-ts3.8
> tsc --project tsconfig.json

##[debug]Dropping file value '/home/runner/work/sentry-javascript/sentry-javascript/node_modules/.pnpm/[email protected]/node_modules/preact/src/jsx.d.ts'. Path does not exist
Error: node_modules/.pnpm/[email protected]/node_modules/preact/src/jsx.d.ts(1462,3): error TS2304: Cannot find name 'SubmitEvent'.
##[debug]Dropping file value '/home/runner/work/sentry-javascript/sentry-javascript/node_modules/.pnpm/[email protected]/node_modules/preact/src/jsx.d.ts'. Path does not exist
Error: node_modules/.pnpm/[email protected]/node_modules/preact/src/jsx.d.ts(1479,25): error TS2304: Cannot find name 'PictureInPictureEvent'.
##[debug]Dropping file value '/home/runner/work/sentry-javascript/sentry-javascript/node_modules/.pnpm/[email protected]/node_modules/preact/src/jsx.d.ts'. Path does not exist
Error: node_modules/.pnpm/[email protected]/node_modules/preact/src/jsx.d.ts(2549,65): error TS2304: Cannot find name 'MathMLElement'.
##[debug]Dropping file value '/home/runner/work/sentry-javascript/sentry-javascript/node_modules/.pnpm/[email protected]/node_modules/preact/src/jsx.d.ts'. Path does not exist
Error: node_modules/.pnpm/[email protected]/node_modules/preact/src/jsx.d.ts(2565,49): error TS2304: Cannot find name 'MathMLElement'.
##[debug]Dropping file value '/home/runner/work/sentry-javascript/sentry-javascript/node_modules/.pnpm/[email protected]/node_modules/preact/src/jsx.d.ts'. Path does not exist
Error: node_modules/.pnpm/[email protected]/node_modules/preact/src/jsx.d.ts(2571,52): error TS2304: Cannot find name 'MathMLElement'.
```

Essentially these types don't work on older versions and because the
feedback package is depended on by the browser package, we will break a
certain set of our users. We have to fix this before we can ship because
of the browser package dependency.

To get around this, we do a workaround with
`packages/feedback/scripts/shim-preact-export.js`. Essentially we shim
the preact type in our exports, which should change what the declaration
files themselves point to. So something like the following:

```ts
import type { ComponentChildren, VNode } from 'preact';
```

turns into

```ts
// no preact to be seen!
type ComponentChildren: any;
type VNode: any;
```
packages/feedback/scripts/shim-preact-export.js Dismissed Show dismissed Hide dismissed
packages/feedback/scripts/shim-preact-export.js Dismissed Show dismissed Hide dismissed
@AbhiPrasad
Copy link
Member

Merging this in to add to the alpha release!

@AbhiPrasad AbhiPrasad merged commit df5f44e into develop Mar 14, 2024
91 checks passed
@AbhiPrasad AbhiPrasad deleted the cl/screenshot-integration branch March 14, 2024 15:10
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.

6 participants