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

Log loader/action errors in dev from default error boundary #10286

Merged
merged 2 commits into from
Apr 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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