-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: optimize
useAtomSelector
for React 19 (#106)
@affects atoms, react
- Loading branch information
Showing
13 changed files
with
243 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Debug Tests", | ||
"type": "node", | ||
"request": "launch", | ||
"runtimeExecutable": "yarn", | ||
"args": ["jest", "--runInBand"], | ||
"console": "integratedTerminal", | ||
"cwd": "${workspaceRoot}", | ||
"internalConsoleOptions": "neverOpen" | ||
}, | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,36 @@ | ||
import '@testing-library/jest-dom/extend-expect' | ||
|
||
let callstacks: Record<string, string> = {} | ||
let id = 0 | ||
|
||
afterEach(() => { | ||
callstacks = {} | ||
id = 0 | ||
}) | ||
|
||
const generateId = () => { | ||
const stack = | ||
(new Error().stack || '') | ||
.split('\n') | ||
.find(line => /\.test\.tsx:/.test(line)) || '' | ||
|
||
return (callstacks[stack] ||= `:r${id++}:`) | ||
} | ||
|
||
jest.mock('react', () => ({ | ||
...jest.requireActual('react'), | ||
useId: generateId, | ||
})) | ||
|
||
// React's `useId` gives new ids in the same callstack when a component tree is | ||
// destroyed/unmounted. Call this to manually force ids to be recreated in tests | ||
// to mimic React's behavior. | ||
;(globalThis as any).clearUseIdEntry = (idNum: number) => { | ||
const key = Object.keys(callstacks).find( | ||
key => callstacks[key] === `:r${idNum}:` | ||
) | ||
|
||
if (key) { | ||
delete callstacks[key] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.