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(nextjs): Add section about custom _error.js to manual setup page #4286

Merged
merged 3 commits into from
Oct 20, 2021

Conversation

lobsterkatie
Copy link
Member

@lobsterkatie lobsterkatie commented Oct 19, 2021

In getsentry/sentry-wizard#140, we update @sentry/wizard to include a custom _error.js page, which is necessary to catch certain errors when an app is deployed to Vercel. (The contents of the page come from Vercel's example Sentry app.) This updates the manual setup docs to reflect this additional step.

@vercel
Copy link

vercel bot commented Oct 19, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/sentry/sentry-docs/GQF6EhjYwqbA7t5CCDzot7hPVpuX
✅ Preview: https://sentry-docs-git-kmclb-nextjs-auto-include-error-page.sentry.dev

Copy link
Contributor

@imatwawana imatwawana left a comment

Choose a reason for hiding this comment

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

Made a couple suggestions

src/platforms/javascript/guides/nextjs/manual-setup.mdx Outdated Show resolved Hide resolved
src/platforms/javascript/guides/nextjs/manual-setup.mdx Outdated Show resolved Hide resolved
@lobsterkatie lobsterkatie enabled auto-merge (squash) October 20, 2021 16:26
@lobsterkatie lobsterkatie merged commit a5aa94f into master Oct 20, 2021
@lobsterkatie lobsterkatie deleted the kmclb-nextjs-auto-include-_error-page branch October 20, 2021 16:28
lobsterkatie added a commit to getsentry/sentry-wizard that referenced this pull request Oct 20, 2021
This adds another file to be copied into the user's project when they run the nextjs version of the wizard, specifically the `_error.js` page which the vercel folks include in their Sentry example app[1] in order to catch more errors. As they say in the comments of that file:

```
  // Next.js will pass an err on the server if a page's data fetching methods
  // threw or returned a Promise that rejected
  //
  // Running on the client (browser), Next.js will provide an err if:
  //
  //  - a page's `getInitialProps` threw or returned a Promise that rejected
  //  - an exception was thrown somewhere in the React lifecycle (render,
  //    componentDidMount, etc) that was caught by Next.js's React Error
  //    Boundary. Read more about what types of exceptions are caught by Error
  //    Boundaries: https://reactjs.org/docs/error-boundaries.html
```

Given that `_error.js` doesn't go at the root level of the project the way the others do, and given that users can either store their page files in `pages` or `src/pages`, I had to add some logic for computing the destination of each copied file. Also, since `_error.js` already starts with an underscore, I felt like adding an underscore to the front of our copy of a file in cases where the file already exists wasn't a great scheme anymore, so I changed to adding `wizardcopy` just before the file's extension (so, for example, if `next.config.js` already exists, we'll now create `next.config.wizardcopy.js`). (This has the added advantage that the real file and our copy now alphabetize right next to one another, so it's dead simple to find them for merging.)

This change is added to the manual setup page in docs in getsentry/sentry-docs#4286.

[1] https://github.com/vercel/next.js/blob/canary/examples/with-sentry/pages/_error.js
@github-actions github-actions bot locked and limited conversation to collaborators Nov 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants