-
-
Notifications
You must be signed in to change notification settings - Fork 1
Out-of-box SSR support #246
Comments
Hey @kachkaev. This is on our radar for sure. I was trying to configure a Gatsby app on friday and this is one of the issues I hit as well. We'll bump the priority and work to get you unblocked! |
Guard @sentry/replay setup if `window` is not defined. **Test Notes:** I setup replays on my gatsby test app and was able to recreate the issue: The config: ```typescript #gatsby-config.ts const config: GatsbyConfig = { ... plugins: [ { resolve: "@sentry/gatsby", }, ], }; export default config; ``` ```typescript #sentry.config.ts import * as Sentry from '@sentry/gatsby'; import { Replay } from "@sentry/replay"; Sentry.init({ dsn: "https://[email protected]/6622945", sampleRate: 1.0, // Adjust this value in production integrations: [ new Replay(), ], }); ``` The failing output: ```bash There was an error compiling the html.js component for the development server. See our docs page on debugging HTML builds for help https://gatsby.dev/debug-html ReferenceError: window is not defined 1226 | var _this = this; 1227 | // XXX: See method comments above > 1228 | window.setTimeout(function () { return _this.start(); }); | ^ 1229 | }; 1230 | /** 1231 | * Initializes the plugin. WebpackError: ReferenceError: window is not defined ``` After the fix we're able to build and run the app, and record replays! | Test App | Replay | | --- | --- | | <img width="1156" alt="Screen Shot 2022-10-18 at 5 38 11 PM" src="https://user-images.githubusercontent.com/187460/196570601-daf68ea5-25e4-4804-9365-9dab03ddf3a1.png"> | <img width="438" alt="Screen Shot 2022-10-18 at 5 37 09 PM" src="https://user-images.githubusercontent.com/187460/196570323-85e7d204-b445-4457-aa2b-8af8ea613688.png"> | In a gatsby app, or most of these other frameworks, it is possible to have a node-only or browser-only config. With atsby, for example, as a work around I would remove `new Replay()` from `sentry.config.ts` and instead create `gatsby-browser.tsx` with the following content which will to manually start the replay session: ```typescript # gatsby-browser.tsx const { Replay } = require("@sentry/replay"); exports.wrapRootElement = ({ element, props }) => { const replay = new Replay({ blockAllMedia: false, maskAllText: false, }); replay.start(); return element; }; ``` Fixes #246
I just upgraded from |
@kachkaev I just published |
Thanks folks! I tried |
I tried
Pointing here: sentry-replay/src/util/isInternal.ts Lines 5 to 7 in 8b805f2
|
Yeah damnit. I quickly added a check to cover that spot: #253 I'm going to see if we can change the tsconfig and eslint to not allow browser api calls like this, and then we can opt-in each time. That way we'll have a chance to add these guards |
hashintel/hash#1232 is using 0.6.6, if that PR merges & deploys without issue i'll close this too. |
I tried 0.6.6 in blockprotocol/blockprotocol#698 but had to bring back If
|
I'm glad it's a new error! I'll spin up a nextjs app and dig into why it's instantiating the class twice. There could be implications for our regular sdk as well. |
So my basic nextjs site seems to work fine with the shared config across I tried checking out [email protected]:blockprotocol/blockprotocol.git and running the app. After setting up everything and running
Checking out this branch I reproduced the issue. Seems like next.js imports the config all the time, so we're going to work on some possible solutions ranging from 'really naive' to 'too crazy'. |
Thanks for trying out our repo @ryan953! I bumped Itβs great that |
β¦eplay#248) Guard @sentry/replay setup if `window` is not defined. **Test Notes:** I setup replays on my gatsby test app and was able to recreate the issue: The config: ```typescript getsentry/sentry-replay#gatsby-config.ts const config: GatsbyConfig = { ... plugins: [ { resolve: "@sentry/gatsby", }, ], }; export default config; ``` ```typescript getsentry/sentry-replay#sentry.config.ts import * as Sentry from '@sentry/gatsby'; import { Replay } from "@sentry/replay"; Sentry.init({ dsn: "https://[email protected]/6622945", sampleRate: 1.0, // Adjust this value in production integrations: [ new Replay(), ], }); ``` The failing output: ```bash There was an error compiling the html.js component for the development server. See our docs page on debugging HTML builds for help https://gatsby.dev/debug-html ReferenceError: window is not defined 1226 | var _this = this; 1227 | // XXX: See method comments above > 1228 | window.setTimeout(function () { return _this.start(); }); | ^ 1229 | }; 1230 | /** 1231 | * Initializes the plugin. WebpackError: ReferenceError: window is not defined ``` After the fix we're able to build and run the app, and record replays! | Test App | Replay | | --- | --- | | <img width="1156" alt="Screen Shot 2022-10-18 at 5 38 11 PM" src="https://user-images.githubusercontent.com/187460/196570601-daf68ea5-25e4-4804-9365-9dab03ddf3a1.png"> | <img width="438" alt="Screen Shot 2022-10-18 at 5 37 09 PM" src="https://user-images.githubusercontent.com/187460/196570323-85e7d204-b445-4457-aa2b-8af8ea613688.png"> | In a gatsby app, or most of these other frameworks, it is possible to have a node-only or browser-only config. With atsby, for example, as a work around I would remove `new Replay()` from `sentry.config.ts` and instead create `gatsby-browser.tsx` with the following content which will to manually start the replay session: ```typescript getsentry/sentry-replay# gatsby-browser.tsx const { Replay } = require("@sentry/replay"); exports.wrapRootElement = ({ element, props }) => { const replay = new Replay({ blockAllMedia: false, maskAllText: false, }); replay.start(); return element; }; ``` Fixes getsentry/sentry-replay#246
π folks! Alfa tester here π§βπ¬ Curious to hear your thoughts on this one!
Environment
"@sentry/replay": "0.6.4-0"
"next": "12.3.1"
Steps to Reproduce
Configure Sentry in a Next.js app using a wizard
Reuse one
sentryConfig
insentry.client.ts
andsentry.server.ts
for simplicity (e.g. by importingsentryConfig
fromsentry.client.ts
tosentry.server.ts
)Add
new Replay()
to a shared configTry
next dev
ornext build
Expected Result
It just worksβ’, i.e.
new Replay()
is a noop on the serverActual Result
π₯
Workaround
Do not reuse Sentry config, thus ensuring that
new Replay()
is only called in the client bundle. E.g.:Iβm fiddling with
sentry-replay
in blockprotocol/blockprotocol#682 β any tips welcome!The text was updated successfully, but these errors were encountered: