@@ -7,7 +7,6 @@ import type { DebugInfo } from './types'
7
7
import type { DevIndicatorServerState } from '../../../server/dev/dev-indicator-server-state'
8
8
import type { HMR_ACTION_TYPES } from '../../../server/dev/hot-reloader-types'
9
9
import { parseStack } from './utils/parse-stack'
10
- import { getComponentStack , getOwnerStack } from '../errors/stitched-error'
11
10
12
11
type FastRefreshState =
13
12
/** No refresh in progress. */
@@ -130,38 +129,6 @@ function getStackIgnoringStrictMode(stack: string | undefined) {
130
129
return stack ?. split ( REACT_ERROR_STACK_BOTTOM_FRAME_REGEX ) [ 0 ]
131
130
}
132
131
133
- function pushErrorFilterDuplicates (
134
- events : SupportedErrorEvent [ ] ,
135
- id : number ,
136
- error : Error
137
- ) : SupportedErrorEvent [ ] {
138
- const componentStack = getComponentStack ( error )
139
- const componentStackFrames =
140
- componentStack === undefined
141
- ? undefined
142
- : parseComponentStack ( componentStack )
143
- const ownerStack = getOwnerStack ( error )
144
- const frames = parseStack ( ( error . stack || '' ) + ( ownerStack || '' ) )
145
- const pendingEvent : SupportedErrorEvent = {
146
- id,
147
- error,
148
- frames,
149
- componentStackFrames,
150
- }
151
- const pendingEvents = events . filter ( ( event ) => {
152
- // Filter out duplicate errors
153
- return (
154
- ( event . error . stack !== pendingEvent . error . stack &&
155
- // TODO: Let ReactDevTools control deduping instead?
156
- getStackIgnoringStrictMode ( event . error . stack ) !==
157
- getStackIgnoringStrictMode ( pendingEvent . error . stack ) ) ||
158
- getOwnerStack ( event . error ) !== getOwnerStack ( pendingEvent . error )
159
- )
160
- } )
161
- pendingEvents . push ( pendingEvent )
162
- return pendingEvents
163
- }
164
-
165
132
const shouldDisableDevIndicator =
166
133
process . env . __NEXT_DEV_INDICATOR ?. toString ( ) === 'false'
167
134
@@ -199,7 +166,43 @@ function getInitialState(
199
166
}
200
167
}
201
168
202
- export function useErrorOverlayReducer ( routerType : 'pages' | 'app' ) {
169
+ export function useErrorOverlayReducer (
170
+ routerType : 'pages' | 'app' ,
171
+ getComponentStack : ( error : Error ) => string | undefined ,
172
+ getOwnerStack : ( error : Error ) => string | null | undefined
173
+ ) {
174
+ function pushErrorFilterDuplicates (
175
+ events : SupportedErrorEvent [ ] ,
176
+ id : number ,
177
+ error : Error
178
+ ) : SupportedErrorEvent [ ] {
179
+ const componentStack = getComponentStack ( error )
180
+ const componentStackFrames =
181
+ componentStack === undefined
182
+ ? undefined
183
+ : parseComponentStack ( componentStack )
184
+ const ownerStack = getOwnerStack ( error )
185
+ const frames = parseStack ( ( error . stack || '' ) + ( ownerStack || '' ) )
186
+ const pendingEvent : SupportedErrorEvent = {
187
+ id,
188
+ error,
189
+ frames,
190
+ componentStackFrames,
191
+ }
192
+ const pendingEvents = events . filter ( ( event ) => {
193
+ // Filter out duplicate errors
194
+ return (
195
+ ( event . error . stack !== pendingEvent . error . stack &&
196
+ // TODO: Let ReactDevTools control deduping instead?
197
+ getStackIgnoringStrictMode ( event . error . stack ) !==
198
+ getStackIgnoringStrictMode ( pendingEvent . error . stack ) ) ||
199
+ getOwnerStack ( event . error ) !== getOwnerStack ( pendingEvent . error )
200
+ )
201
+ } )
202
+ pendingEvents . push ( pendingEvent )
203
+ return pendingEvents
204
+ }
205
+
203
206
return useReducer ( ( state : OverlayState , action : BusEvent ) : OverlayState => {
204
207
switch ( action . type ) {
205
208
case ACTION_DEBUG_INFO : {
0 commit comments