preactjs / signals

Manage state with style in every framework
https://preactjs.com/blog/introducing-signals/
MIT License
3.82k stars 95 forks source link

Nested `untracked` cause `effect` to run #536

Closed mykola-vrmchk closed 8 months ago

mykola-vrmchk commented 8 months ago

I run into a problem of infinite cycles in my project. Here is a reproduction snippet

import { effect, signal, untracked } from '@preact/signals-core';
import { expect } from 'chai';

describe('Untracked', () => {
  it('Nested `untracked` does not cause effect to run', async () => {
    const thisSignal = signal({});
    let updateCount = 0;

    untracked(() => {
      effect(() => {
        untracked(() => {
          const _ = thisSignal.value;
          thisSignal.value = {};
          updateCount++;
        });
      });
    });

    expect(updateCount).to.eq(1);
  });
});

The code above will produce an error Error: Cycle detected, it happens because nested untracked causes effect to run.

I am wondering if this is expected behavior

jviide commented 8 months ago

This was recently fixed in #512 but a new version has not yet been released.

mykola-vrmchk commented 8 months ago

@jviide could you, please, estimate when the next release will be?

JoviDeCroock commented 8 months ago

Closing as released and fixed

mykola-vrmchk commented 8 months ago

@JoviDeCroock awesome, thanks