Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add creationStack, created when createSelector was first called #684

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/createSelectorCreator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ export function createSelectorCreator<
>
]
) => {
let creationStack: string | undefined = undefined
if (process.env.NODE_ENV !== 'production') {
try {
throw new Error()
} catch (error) {
creationStack = (error as Error).stack
}
}
let recomputations = 0
let dependencyRecomputations = 0
let lastResult: Result
Expand Down Expand Up @@ -418,7 +426,8 @@ export function createSelectorCreator<
identityFunctionCheck.run(
resultFunc as Combiner<InputSelectors, Result>,
inputSelectorResults,
lastResult
lastResult,
creationStack
)
}

Expand All @@ -432,7 +441,8 @@ export function createSelectorCreator<
inputStabilityCheck.run(
{ inputSelectorResults, inputSelectorResultsCopy },
{ memoize, memoizeOptions: finalMemoizeOptions },
arguments
arguments,
creationStack
)
}

Expand Down
5 changes: 3 additions & 2 deletions src/devModeChecks/identityFunctionCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ import type { AnyFunction } from '../types'
export const runIdentityFunctionCheck = (
resultFunc: AnyFunction,
inputSelectorsResults: unknown[],
outputSelectorResult: unknown
outputSelectorResult: unknown,
creationStack: string | undefined
) => {
if (
inputSelectorsResults.length === 1 &&
Expand All @@ -46,7 +47,7 @@ export const runIdentityFunctionCheck = (
'\n`createSelector([state => state.todos], todos => todos)`' +
'\nThis could lead to inefficient memoization and unnecessary re-renders.' +
'\nEnsure transformation logic is in the result function, and extraction logic is in the input selectors.',
{ stack }
{ stack, creationStack }
)
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/devModeChecks/inputStabilityCheck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ export const runInputStabilityCheck = (
'memoize' | 'memoizeOptions'
>
>,
inputSelectorArgs: unknown[] | IArguments
inputSelectorArgs: unknown[] | IArguments,
creationStack: string | undefined
) => {
const { memoize, memoizeOptions } = options
const { inputSelectorResults, inputSelectorResultsCopy } =
Expand All @@ -52,7 +53,8 @@ export const runInputStabilityCheck = (
arguments: inputSelectorArgs,
firstInputs: inputSelectorResults,
secondInputs: inputSelectorResultsCopy,
stack
stack,
creationStack
}
)
}
Expand Down
3 changes: 2 additions & 1 deletion test/identityFunctionCheck.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ describe('identityFunctionCheck', () => {
'The result function returned its own inputs without modification'
),
{
stack: expect.any(String)
stack: expect.any(String),
creationStack: expect.any(String)
}
)
})
Expand Down
3 changes: 2 additions & 1 deletion test/inputStabilityCheck.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ describe('inputStabilityCheck', () => {
secondInputs: expect.arrayContaining([
expect.objectContaining({ a: 1, b: 2 })
]),
stack: expect.any(String)
stack: expect.any(String),
creationStack: expect.any(String)
})
)
})
Expand Down
Loading