Skip to content

Commit

Permalink
Log loader/action errors in dev from default error boundary (#10286)
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 authored Apr 10, 2023
1 parent 6f17a30 commit 2a3c850
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/console-log-loader-error.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"react-router": patch
---

Log loader/action errors to the console in dev for easier stack trace evaluation
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {

beforeEach(() => {
jest.spyOn(console, "warn").mockImplementation(() => {});
jest.spyOn(console, "error").mockImplementation(() => {});
});

describe("A <StaticRouterProvider>", () => {
Expand Down
32 changes: 20 additions & 12 deletions packages/react-router/__tests__/data-memory-router-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1761,18 +1761,20 @@ describe("createMemoryRouter", () => {
💿 Hey developer 👋
</p>
<p>
You can provide a way better UX than this when your app throws errors by providing your own 
You can provide a way better UX than this when your app throws errors by providing your own
<code
style="padding: 2px 4px; background-color: rgba(200, 200, 200, 0.5);"
>
ErrorBoundary
</code>
prop on 
or
<code
style="padding: 2px 4px; background-color: rgba(200, 200, 200, 0.5);"
>
&lt;Route&gt;
errorElement
</code>
prop on your route.
</p>
</div>"
`);
Expand Down Expand Up @@ -1878,18 +1880,20 @@ describe("createMemoryRouter", () => {
💿 Hey developer 👋
</p>
<p>
You can provide a way better UX than this when your app throws errors by providing your own 
You can provide a way better UX than this when your app throws errors by providing your own
<code
style="padding: 2px 4px; background-color: rgba(200, 200, 200, 0.5);"
>
ErrorBoundary
</code>
prop on 
or
<code
style="padding: 2px 4px; background-color: rgba(200, 200, 200, 0.5);"
>
&lt;Route&gt;
errorElement
</code>
prop on your route.
</p>
</div>"
`);
Expand Down Expand Up @@ -2110,18 +2114,20 @@ describe("createMemoryRouter", () => {
💿 Hey developer 👋
</p>
<p>
You can provide a way better UX than this when your app throws errors by providing your own 
You can provide a way better UX than this when your app throws errors by providing your own
<code
style="padding: 2px 4px; background-color: rgba(200, 200, 200, 0.5);"
>
ErrorBoundary
</code>
prop on 
or
<code
style="padding: 2px 4px; background-color: rgba(200, 200, 200, 0.5);"
>
&lt;Route&gt;
errorElement
</code>
prop on your route.
</p>
</div>"
`);
Expand Down Expand Up @@ -2294,18 +2300,20 @@ describe("createMemoryRouter", () => {
💿 Hey developer 👋
</p>
<p>
You can provide a way better UX than this when your app throws errors by providing your own 
You can provide a way better UX than this when your app throws errors by providing your own
<code
style="padding: 2px 4px; background-color: rgba(200, 200, 200, 0.5);"
>
ErrorBoundary
</code>
prop on 
or
<code
style="padding: 2px 4px; background-color: rgba(200, 200, 200, 0.5);"
>
&lt;Route&gt;
errorElement
</code>
prop on your route.
</p>
</div>
</div>"
Expand Down
10 changes: 7 additions & 3 deletions packages/react-router/lib/hooks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -468,14 +468,18 @@ function DefaultErrorComponent() {

let devInfo = null;
if (__DEV__) {
console.error(
"Error handled by React Router default ErrorBoundary:",
error
);

devInfo = (
<>
<p>💿 Hey developer 👋</p>
<p>
You can provide a way better UX than this when your app throws errors
by providing your own&nbsp;
<code style={codeStyles}>ErrorBoundary</code> prop on&nbsp;
<code style={codeStyles}>&lt;Route&gt;</code>
by providing your own <code style={codeStyles}>ErrorBoundary</code> or{" "}
<code style={codeStyles}>errorElement</code> prop on your route.
</p>
</>
);
Expand Down

0 comments on commit 2a3c850

Please sign in to comment.