@@ -7,7 +7,6 @@ import type { DebugInfo } from './types'
77import type { DevIndicatorServerState } from '../../../server/dev/dev-indicator-server-state'
88import type { HMR_ACTION_TYPES } from '../../../server/dev/hot-reloader-types'
99import { parseStack } from './utils/parse-stack'
10- import { getComponentStack , getOwnerStack } from '../errors/stitched-error'
1110
1211type FastRefreshState =
1312 /** No refresh in progress. */
@@ -130,37 +129,6 @@ function getStackIgnoringStrictMode(stack: string | undefined) {
130129 return stack ?. split ( REACT_ERROR_STACK_BOTTOM_FRAME_REGEX ) [ 0 ]
131130}
132131
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 frames = parseStack ( ( error . stack || '' ) + getOwnerStack ( error ) || '' )
144- const pendingEvent : SupportedErrorEvent = {
145- id,
146- error,
147- frames,
148- componentStackFrames,
149- }
150- const pendingEvents = events . filter ( ( event ) => {
151- // Filter out duplicate errors
152- return (
153- ( event . error . stack !== pendingEvent . error . stack &&
154- // TODO: Let ReactDevTools control deduping instead?
155- getStackIgnoringStrictMode ( event . error . stack ) !==
156- getStackIgnoringStrictMode ( pendingEvent . error . stack ) ) ||
157- getOwnerStack ( event . error ) !== getOwnerStack ( pendingEvent . error )
158- )
159- } )
160- pendingEvents . push ( pendingEvent )
161- return pendingEvents
162- }
163-
164132const shouldDisableDevIndicator =
165133 process . env . __NEXT_DEV_INDICATOR ?. toString ( ) === 'false'
166134
@@ -198,7 +166,42 @@ function getInitialState(
198166 }
199167}
200168
201- 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 frames = parseStack ( ( error . stack || '' ) + getOwnerStack ( error ) || '' )
185+ const pendingEvent : SupportedErrorEvent = {
186+ id,
187+ error,
188+ frames,
189+ componentStackFrames,
190+ }
191+ const pendingEvents = events . filter ( ( event ) => {
192+ // Filter out duplicate errors
193+ return (
194+ ( event . error . stack !== pendingEvent . error . stack &&
195+ // TODO: Let ReactDevTools control deduping instead?
196+ getStackIgnoringStrictMode ( event . error . stack ) !==
197+ getStackIgnoringStrictMode ( pendingEvent . error . stack ) ) ||
198+ getOwnerStack ( event . error ) !== getOwnerStack ( pendingEvent . error )
199+ )
200+ } )
201+ pendingEvents . push ( pendingEvent )
202+ return pendingEvents
203+ }
204+
202205 return useReducer ( ( state : OverlayState , action : BusEvent ) : OverlayState => {
203206 switch ( action . type ) {
204207 case ACTION_DEBUG_INFO : {
0 commit comments