Repository navigation
Conversation
|
@aldebout is attempting to deploy a commit to the trpc Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for Git βοΈ
|
|
Current state:
|
commit: |
KATT
left a comment
There was a problem hiding this comment.
Needs
- A test that leverages the structural sharing in a test that renders a react app
- Removal of dependency
- Making it opt-in somehow (I'm guessing this is something you pass to the react query proivder?)
|
Still missing:
|
| test('stable for sets - different order is still equal', async () => { | ||
| const set = new Set([1, 2, 3]); | ||
| const oldResult = parse(stringify({ a: set })); | ||
| const newResult = parse(stringify({ a: new Set([3, 2, 1]) })); | ||
|
|
||
| expect(defaultStructuralSharingFunction(oldResult, newResult)).toBe( | ||
| oldResult, | ||
| ); | ||
| }); |
There was a problem hiding this comment.
I am wondering if this is a bug or a feature? Is this how RQ handles arrays?
| ); | ||
| }); | ||
|
|
||
| test('stable for maps - different keys are not equal', async () => { |
There was a problem hiding this comment.
Not sure if order should matter or not here?
| test('sets - different sizes are not equal', async () => { | ||
| const prev = new Set([1]); | ||
| const next = new Set([1, 2]); | ||
|
|
||
| expect(defaultStructuralSharingFunction(prev, next)).toEqual(next); | ||
| }); |
| const equalCheck = (a: unknown, b: unknown) => { | ||
| return customEqualityFunction(a, b) || defaultIsEqual(a, b); | ||
| }; | ||
| const structuralSharingFunction = (prev: any, next: any): any => { |
There was a problem hiding this comment.
renamed these to prev and next fyi
| const map = prev instanceof Map && next instanceof Map; | ||
| const set = prev instanceof Set && next instanceof Set; | ||
|
|
||
| if (array || plainObject || map) { |
There was a problem hiding this comment.
The code within here is.... horribly hard to follow
should we split it up into less DRY operations instead?
|
please re-request review or ping me on discord when you have responded etc! |
| return a.source === b.source && a.flags === b.flags; | ||
| if (a.valueOf !== Object.prototype.valueOf) | ||
| return a.valueOf() === b.valueOf(); | ||
| if (a.toString !== Object.prototype.toString) |
There was a problem hiding this comment.
This may get evaluated if a and b are arrays. In this case, a.toString === Array.prototype.toString !== Object.prototype.toString.
Maybe moving the if(equalCheck(prev, next)) statement after the array and object detections could be more in line.
-- I've been debugging this for quite some time :)
|
Anything happen with this one? |
|
This pull request has been locked because we are very unlikely to see comments on closed issues. If you think, this PR is still necessary, create a new one with the same branch. Thank you. |
Closes #6306
π― Changes
This PR introduces a new function to handle structural sharing of non-JSON-serializable results in tanstack-query.
With this feature, API endpoints that returns
Dates,Sets andMaps should now have more stable data object identity between renders.β Checklist