GithubHelp home page GithubHelp logo

Comments (3)

bjoerge avatar bjoerge commented on June 25, 2024

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.

stian-svedenborg avatar stian-svedenborg commented on June 25, 2024

@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.

bjoerge avatar bjoerge commented on June 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.