Commit Graph

5 Commits

Author SHA1 Message Date
Janka Uryga ea541987d1 fix: handling of falsey values in error boundaries (#93134)
our error boundaries had a bunch of logic that set `state.error = error`
and then checked `if (state.error)`, which only works correctly if
thrown value is truthy. it breaks if something does e.g. `throw
undefined`. in this case, we would incorrectly think that no error
occurred and render children again (instead of a fallback), which can
then lead to an infinite loop if the children throw again.

the fix is to wrap the thrown value, so `state.error` is either `null`
(initial/reset) or `{ thrownValue: ... }` if something errored. i
initially considered using a separate `state.hasError` boolean, but
that's a bit annoying to type, and really we want to model this as a
discriminated union, so using a pseudo-Optional thing is nicer.
2026-04-29 17:25:56 +00:00
Jiachi Liu 303585a94e Display global-error along dev overlay during development (#75101)
### What

Display `global-error.js` along with error overlay in development. When
a runtime error occurred, you should be able to view the
`global-error.js` content by just hiding the error overlay.


### Why

Current behavior of `global-error.js` confused a lot of users that it
only renders in production build, howerver in dev it's always shows the
error overlay. This was considered "expected" before as you should focus
on fixing error in dev. But this brings a lot of inconvenience for
users, since they can't view the `global-error.js` easily in development
but production build.


#### After
The global-error content is displayed in the html with error overlay
covered

![image](https://github.com/user-attachments/assets/58fd73f8-7634-4a52-b6f8-c912cbb36fc3)

#### Before
Notice nothing displayed

![image](https://github.com/user-attachments/assets/319f3eb0-5d30-4c51-8e29-872aaec42261)


Fixes #55462
Fixes #52993
Closes NDX-694
2025-01-20 16:39:08 +01:00
Jiachi Liu 98b99e408b Fix global-error for nested routes (#60539)
## What

This fixes when the deep nested routes throws a client side error, it
can still be caught by the `global-error.js`

## How

We should always resolve global-error from root app directory instead of
current route's layout. Also fixed a bad test before where the
gloabl-error.js is not located correctly


Fixes #53756
Closes NEXT-1760
2024-01-11 23:28:17 +01:00
Jiachi Liu 99372fbedf Add test for catching metadata error in error boundaries (#53581) 2023-08-04 20:57:49 +02:00
Jiachi Liu 79227ee74a Catch layout error in global-error (#52654)
When there's a runtime error showing in root layout (server components), it should be able to catch by `global-error`.

For server components, we caught it and gonna render the error fallback components (either not-found or error page), and the response status is `200`, and since we'll display error dev overlay in developmenet mode so we only render `global-error` for production.

So that you can catch more errors with `global-error` and maybe do potential error tracking on client side.

Follow up of #52573
Closes NEXT-1442

minor refactor: move `appUsingSizeAdjust` into `Metadata` component so that we can just tune the flag as prop
2023-07-14 00:43:40 +00:00