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

add gatsby example #2054

Merged
merged 7 commits into from
Jan 9, 2024
Merged

add gatsby example #2054

merged 7 commits into from
Jan 9, 2024

Conversation

djskinner
Copy link
Contributor

@djskinner djskinner commented Dec 13, 2023

Goal

To demonstrate how to integrate BugSnag with Gatsby projects

Design

Focus on browser error tracking as most of the Gatsby usage is expected to be SSG pages

Testing

gatsby develop:

  • error in dashboard from the exception in useEffect
  • error in dashboard from the Bad button handler useCallback
  • error in dashboard from the bad button error thrown during render

gatsby build && gatsby serve:

  • error in dashboard from the exception in useEffect
  • error in dashboard from the Bad button handler useCallback
  • error in dashboard with 'react' metadata tab from the bad button error thrown during render

Copy link

github-actions bot commented Dec 13, 2023

@bugsnag/browser bundle size diff

Minified Minfied + Gzipped
Before 43.67 kB 13.40 kB
After 43.67 kB 13.40 kB
± No change No change

code coverage diff

<temporarily disabled>

Generated by 🚫 dangerJS against 27d2bc0

// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
"skipLibCheck": true /* Skip type checking all .d.ts files. */
},
"include": ["./src/**/*", "./gatsby-node.ts", "./gatsby-config.ts", "./plugins/**/*", "gatsby-browser.js", "gatsby-node.js", "gatsby-ssr.js"]
Copy link
Contributor

Choose a reason for hiding this comment

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

What are gatsby-node.js and gatsby-ssr.js ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See https://www.gatsbyjs.com/docs/reference/config-files/gatsby-node/ and https://www.gatsbyjs.com/docs/reference/config-files/gatsby-ssr/ respectively

This is just the standard tsconfig that comes when starting a new Gatsby project. gatsby-node.js and gatsby-ssr.js and gatsby-browser.js are optional files

Comment on lines 12 to 25
/**
* 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) {
return
}
Bugsnag.start(bugsnagConfig)
bugsnagStarted = true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This can use Bugsnag.isStarted instead of keeping track manually

Suggested change
/**
* 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) {
return
}
Bugsnag.start(bugsnagConfig)
bugsnagStarted = true
}
export const onClientEntry = () => {
if (Bugsnag.isStarted) {
return
}
Bugsnag.start(bugsnagConfig)
}

Comment on lines 28 to 31
if (!bugsnagStarted) {
Bugsnag.start(bugsnagConfig)
bugsnagStarted = true
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if (!bugsnagStarted) {
Bugsnag.start(bugsnagConfig)
bugsnagStarted = true
}
if (!Bugsnag.isStarted) {
Bugsnag.start(bugsnagConfig)
}

@djskinner djskinner merged commit 2902080 into next Jan 9, 2024
56 of 68 checks passed
@djskinner djskinner deleted the gatsby-example branch January 9, 2024 13:18
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.

4 participants