Skip to content

Commit

Permalink
use Bugsnag.isStarted() in gatsby example
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Skinner committed Dec 22, 2023
1 parent ba40b28 commit 969a86f
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions examples/js/gatsby/gatsby-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,22 @@ const bugsnagConfig = {
appVersion: '1.2.3',
}

/**
* With `gatsby develop` wrapRootElement is called before onClientEntry and then again afterwards.
* However, `gatsby serve` onClientEntry is called, followed by wrapRootElement. So we need this
* extra state to deal with the difference in behavior.
*/
let bugsnagStarted = false

export const onClientEntry = () => {
if (bugsnagStarted) {
/**
* With `gatsby develop` wrapRootElement is called before onClientEntry and then again afterwards.
* However, `gatsby serve` onClientEntry is called, followed by wrapRootElement. So we need this
* extra state to deal with the difference in behavior.
*/
if (Bugsnag.isStarted()) {
return
}

Bugsnag.start(bugsnagConfig)
bugsnagStarted = true
}

export const wrapRootElement = ({ element }) => {
if (!bugsnagStarted) {
if (!Bugsnag.isStarted()) {
Bugsnag.start(bugsnagConfig)
bugsnagStarted = true
}

const ErrorBoundary = Bugsnag.getPlugin('react').createErrorBoundary(React)
Expand Down

0 comments on commit 969a86f

Please sign in to comment.