Skip to content

Nested untracked cause effect to run #536

Closed
@mykola-vrmchk

Description

@mykola-vrmchk

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions