Comments (3)
Hi, thanks for the thorough investigation and the proposed fix @sarahsvedenborg! Unfortunately your proposed fix breaks one of our unit tests, so we need to spend a bit more time on understanding why this happens for you. This is the first time I hear about this beging an issue, so suspect it might be something about your particular setup that triggers this.
I understand that it's difficult to create a minimal reproducible case, but any more details about your schema/setup would be of great help and also allows us to capture your case in a unit test to make sure we don't regress. Feel free to relay any details through support channels.
from sanity.
@sarahsvedenborg is working on producing a minimal test-case, but I have a question regarding the failing unit test.
Are you sure the unit test is working as intended?
The proposed fix has one functional difference to the existing reconcile, namely that it continues to reconcile objects within loops, the old version does not and will give up on reconciling objects or arrays encountered in the second iteration of a loop and simply pick "next" even if subobjects of next could still be reconciled, could this be the reason for the failing unit test?
To illustrate:
const objectCreator = (differentiator) => {
const root = { id: "root" } // will be different if differentiator is different
const a = { id: "a" } // will be different if differentiator is different
const b = { id: "b", diff: differentiator } // will be different if differentiator is different
const c = { id: "c" } // will never be different
root.a = a;
root.a.b = b
root.a.b.a = a; // loop
root.a.b.c = c;
return root
}
const previous = objectCreator("previous")
const next = objectCreator("next")
const reconciledOld = immutableReconcileOld(previous, next)
const reconciledNew = immutableReconcileNew(previous, next)
// Current Behaviour
assertNotSame(previous, reconciledOld)
assertNotSame(next, reconciledOld)
assertSame(previous.a.b.c, reconciledOld.a.b.c)
assertNotSame(previous.a.b.a.b.c, reconciledOld.a.b.a.b.c) // (Suboptimal) Equal objects nested within loops are not retained in the second iteration of the loop.
assertNotSame(reconciledOld.a, reconciledOld.a.b.a) // Loops inside reconciled objects are not retained.
assertSame(next.a.b.c, reconciledOld.a.b.a.b.c) // This is because the old reconcile always picks "next" when hitting a node that it is already resolving.
// Proposed behaviour
assertNotSame(previous, reconciledNew)
assertNotSame(next, reconciledNew)
assertNotSame(next.a, reconciledNew.a) // A sub object of root has changed, creating new object
assertNotSame(next.a.b, reconciledNew.a.b) // A sub-object of root.a has changed, creating new object
assertNotSame(next.a.b.c, reconciledNew.a.b.c) // root.a.b.c is has not changed, therefore reuse.
assertSame(previous.a.b.c, reconciledNew.a.b.c)
assertSame(previous.a.b.a.b.c, reconciledNew.a.b.a.b.c) // The new reconcile will retain reconcilable objects also within loops.
assertSame(reconciledNew.a, reconciledNew.a.b.a) // This is because it retains the loop.
assertSame(previous.a.b.c, reconciledNew.a.b.a.b.c)
If this is the reason for the failing unit-test I would propose changing the test, as the new reconcile will be both faster and reconcile more objects.
from sanity.
Great observations @stian-svedenborg – Think you're absolutely right here. I'll set aside some time today to integrate your proposed unit test into our test suite and make a PR based on @sarahsvedenborg's fix. Thanks again for digging into this.
from sanity.
Related Issues (20)
- Mark selected menu item doesn't work as it works for default menu items HOT 1
- TypeGen does not generate correct type when querying an array containing multiple references types HOT 1
- Opening one collapsible column field causes it's neighbor to disappear because they are bottom aligned. HOT 1
- Pasting in PTE not working on Firefox HOT 1
- Cannot delete documents from a migration script HOT 1
- Automatically infer types of queries using groq and @sanity/codegen HOT 1
- error cannot read properties of null (reading 'scrollTop') HOT 2
- Text isn't pasted into Portable Text Editor in Firefox HOT 1
- Limiting documents in document pane to 2000 HOT 1
- Type generation incompatible with Astro
- Documents are appearing in Gatsby / Gatsby's GraphQL browser / the Vision tool / CLI, but missing in Studio HOT 2
- [urgent] Webhook deleted but still pinging the middleware at Vercel HOT 1
- Unprotected use of process.env. SANITY_INTERNAL_ENV breaks Studio when it's created from client, as in @sanity/astro HOT 2
- Insert menu for portable text editor blocks
- Bug when using compnent in adocument
- Possible ESM issue when running sanity typegen extract
- "Select" button no longer appears in image field HOT 4
- Sanity's dependency on `@sentry/react` should not exist - devDependency instead HOT 1
- Peer deps issue when running `npx sainty init` in fresh nextjs app
- More async callbacks in defineConfig
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanity.