Skip to content

Commit

Permalink
Merge branch 'vercel:main' into rafaeltab/grouped-output
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaeltab authored Feb 22, 2023
2 parents f243ec7 + 55f7060 commit 038e51d
Show file tree
Hide file tree
Showing 170 changed files with 13,858 additions and 5,805 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 19 additions & 2 deletions crates/next-core/js/src/overlay/internal/ReactDevOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ type OverlayState = {
errors: SupportedErrorEvent[];

refreshState: RefreshState;

reactError: Error | null;
};

function pushErrorFilterDuplicates(
Expand All @@ -50,6 +52,13 @@ function pushErrorFilterDuplicates(
function reducer(state: OverlayState, ev: Bus.BusEvent): OverlayState {
switch (ev.type) {
case Bus.TYPE_BUILD_OK: {
if (state.reactError != null) {
console.warn(
"[Fast Refresh] performing full reload because your application had an unrecoverable error"
);
window.location.reload();
}

return { ...state };
}
case Bus.TYPE_TURBOPACK_ISSUES: {
Expand Down Expand Up @@ -104,6 +113,9 @@ function reducer(state: OverlayState, ev: Bus.BusEvent): OverlayState {
return state;
}
}
case Bus.TYPE_REACT_ERROR: {
return { ...state, reactError: ev.error };
}
default: {
return state;
}
Expand Down Expand Up @@ -142,6 +154,7 @@ export default function ReactDevOverlay({
refreshState: {
type: "idle",
},
reactError: null,
});

React.useEffect(() => {
Expand All @@ -152,8 +165,12 @@ export default function ReactDevOverlay({
}, [dispatch]);

const onComponentError = React.useCallback(
(_error: Error, _componentStack: string | null) => {
// TODO: special handling
(error: Error, componentStack: string | null) => {
Bus.emit({
type: Bus.TYPE_REACT_ERROR,
error,
componentStack,
});
},
[]
);
Expand Down
10 changes: 9 additions & 1 deletion crates/next-core/js/src/overlay/internal/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export const TYPE_BEFORE_REFRESH = "before-fast-refresh";
export const TYPE_REFRESH = "fast-refresh";
export const TYPE_UNHANDLED_ERROR = "unhandled-error";
export const TYPE_UNHANDLED_REJECTION = "unhandled-rejection";
export const TYPE_REACT_ERROR = "react-error";

export type BuildOk = { type: typeof TYPE_BUILD_OK };
export type TurbopackIssues = {
Expand All @@ -26,13 +27,20 @@ export type UnhandledRejection = {
reason: Error;
frames: StackFrame[];
};
export type ReactError = {
type: typeof TYPE_REACT_ERROR;
error: Error;
componentStack: string | null;
};

export type BusEvent =
| BuildOk
| TurbopackIssues
| BeforeFastRefresh
| FastRefresh
| UnhandledError
| UnhandledRejection;
| UnhandledRejection
| ReactError;

export type BusEventHandler = (ev: BusEvent) => void;

Expand Down
Loading

0 comments on commit 038e51d

Please sign in to comment.