Skip to content

Edge case: infinite loop/out of memory in certain situations #123

Description

@Alexnortung

In some scenarios computeds can get stuck in an infinite loop and/or cause out of memory.

Here is a minimal program that will get stuck:

import { computed, signal } from "alien-signals";

const fieldA = signal(false);
const fieldB = signal(false);

const a = computed(() => {
  return b() !== true ? fieldA() : null;
});

const b = computed((): boolean | null => {
  return a() !== true ? fieldB() : null;
});

console.log("a", a()); // false
console.log("b", b()); // false

fieldA(true);
console.log("Field A changed");

// BREAKS HERE when trying to get a
console.log("a", a());
console.log("b", b());

What I would expect:

At least that it would not get stuck in an infinite loop.
But I am not sure about the result.


I am not sure if this should be part of the core of alien-signals as the result may be a bit ambigous.

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