signaldb icon indicating copy to clipboard operation
signaldb copied to clipboard

Using $set on an array to modified an object/item inline doesn't trigger the SyncManager

Open ankemp opened this issue 8 months ago • 3 comments

As title mentions, the following code will not trigger SyncManager properly.

It does seem to cause a pull to happen, but nothing ever gets pushed, am I doing something wrong here or perhaps this is a bug?

  updateTimer(task: Task, timerIndex: number, timer: TaskTimer) {
    this.updateOne(
      { id: task.id },
      {
        $set: {
          [`timers.${timerIndex}`]: timer,
        },
      },
    );
  }

ankemp avatar Apr 06 '25 22:04 ankemp

Your code looks okay. Could you provide a minimal reproduction repo?

maxnowack avatar Apr 07 '25 06:04 maxnowack

I have similar problems, it seems like if I use either dot-notation or nested objects as $set value, the sync manager does not pick up the changes. I created a stackblitz to reproduce the issue, but there it works like a charm:

https://stackblitz.com/edit/signaldb-playground?file=main.js

maxfriedmann avatar Apr 25 '25 18:04 maxfriedmann

stackblitz.com/edit/signaldb-playground?file=main.js

I updated the stackblitz, it now reproduces the issue. If the nested object already exists and you want to modify it via dot.notation it won't trigger a sync since computeChanges does not find the change.

maxfriedmann avatar Apr 25 '25 19:04 maxfriedmann

Thanks @maxfriedmann for your analysis and reproduction. I've included new tests and fixed this issue in #1689 🙂

maxnowack avatar May 02 '25 07:05 maxnowack

Fix released in @signaldb/[email protected] 🎉

maxnowack avatar May 02 '25 07:05 maxnowack