diff --git a/extension/src/pageScript/api/index.ts b/extension/src/pageScript/api/index.ts index ed062fe9..391946ba 100644 --- a/extension/src/pageScript/api/index.ts +++ b/extension/src/pageScript/api/index.ts @@ -222,10 +222,11 @@ function post>( function getStackTrace( config: Config, - toExcludeFromTrace: Function | undefined + toExcludeFromTrace: Function | undefined, + action: Action ) { if (!config.trace) return undefined; - if (typeof config.trace === 'function') return config.trace(); + if (typeof config.trace === 'function') return config.trace(action); let stack; let extraFrames = 0; @@ -268,16 +269,33 @@ function amendActionType>( toExcludeFromTrace: Function | undefined ): StructuralPerformAction { let timestamp = Date.now(); - let stack = getStackTrace(config, toExcludeFromTrace); if (typeof action === 'string') { - return { action: { type: action } as A, timestamp, stack }; + const amendedAction = { type: action } as A; + return { + action: amendedAction, + timestamp, + stack: getStackTrace(config, toExcludeFromTrace, amendedAction), + }; } - if (!(action as A).type) - return { action: { type: 'update' } as A, timestamp, stack }; - if ((action as StructuralPerformAction).action) + if (!(action as A).type) { + const amendedAction = { type: 'update' } as A; + return { + action: amendedAction, + timestamp, + stack: getStackTrace(config, toExcludeFromTrace, amendedAction), + }; + } + if ((action as StructuralPerformAction).action) { + const stack = getStackTrace( + config, + toExcludeFromTrace, + (action as StructuralPerformAction).action + ); return ( stack ? { stack, ...action } : action ) as StructuralPerformAction; + } + const stack = getStackTrace(config, toExcludeFromTrace, action as A); return { action, timestamp, stack } as StructuralPerformAction; } diff --git a/extension/src/pageScript/index.ts b/extension/src/pageScript/index.ts index fef17af1..29468147 100644 --- a/extension/src/pageScript/index.ts +++ b/extension/src/pageScript/index.ts @@ -112,7 +112,9 @@ export interface ConfigWithExpandedMaxAge { currentLiftedAction: LiftedAction, previousLiftedState: LiftedState | undefined ) => number); - readonly trace?: boolean | (() => string | undefined); + readonly trace?: + | boolean + | (>(action: A) => string | undefined); readonly traceLimit?: number; readonly shouldCatchErrors?: boolean; readonly shouldHotReload?: boolean; diff --git a/packages/redux-devtools-utils/src/index.ts b/packages/redux-devtools-utils/src/index.ts index a62c8882..617139f8 100644 --- a/packages/redux-devtools-utils/src/index.ts +++ b/packages/redux-devtools-utils/src/index.ts @@ -216,14 +216,15 @@ export function getSeralizeParameter( return value; } -export function getStackTrace( +export function getStackTrace>( // eslint-disable-next-line @typescript-eslint/ban-types - config: { trace?: () => {}; traceLimit: number }, + config: { trace?: (action?: A) => {}; traceLimit: number }, // eslint-disable-next-line @typescript-eslint/ban-types - toExcludeFromTrace?: Function | undefined + toExcludeFromTrace?: Function | undefined, + action?: A ) { if (!config.trace) return undefined; - if (typeof config.trace === 'function') return config.trace(); + if (typeof config.trace === 'function') return config.trace(action); let stack; let extraFrames = 0;