Skip to content

Commit

Permalink
web: Ignore hydration errors caused by browser translate
Browse files Browse the repository at this point in the history
  • Loading branch information
schneefux committed Mar 20, 2024
1 parent 1c1da2b commit 9da4ba1
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
6 changes: 0 additions & 6 deletions web/renderer/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ function createApp(pageContext: PageContext) {
},
queryCache: new QueryCache({
onError(err) {
if (err.name == 'Error' && err.message.length == 0) {
// cube.js RequestError, ignore
// FIXME import it from cubejs and match the class
return
}

app.runWithContext(() => {
const sentry = useSentry()
sentry?.captureException(err)
Expand Down
20 changes: 20 additions & 0 deletions web/renderer/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,26 @@ export function initSentry(dsn: string, app: App<Element>, router?: Router) {
tracesSampleRate: 0.01,
profilesSampleRate: 0.25, // relative to tracesSampleRate
trackComponents: true,
beforeSend(event, hint) {
const error = hint.originalException as any

if (error && error.name == 'Error' && error.message.length == 0) {
// cube.js RequestError, ignore
// FIXME import it from cubejs and match the class
return null
}

if (error == 'Hydration completed but contains mismatches.') {
// ignore hydration mismatches when the page is auto-translated
const isAutoTranslated = !!document.querySelector('html.translated-ltr, head.translated-rtl, ya-tr-span, *[_msttexthash]')

if (isAutoTranslated) {
return null
}
}

return event
},
})

app.provide(SentryInjectionKey, Sentry)
Expand Down
11 changes: 11 additions & 0 deletions web/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ async function startServer() {
levels: ['error', 'assert'],
}),
],
beforeSend(event, hint) {
const error = hint.originalException as any

if (error && error.name == 'Error' && error.message.length == 0) {
// cube.js RequestError, ignore
// FIXME import it from cubejs and match the class
return null
}

return event
},
})
app.use(Sentry.Handlers.requestHandler())

Expand Down

0 comments on commit 9da4ba1

Please sign in to comment.