Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum call stack size exceeded when disposing reaction in many onBecomeUnobservable #3954

Open
upsuper opened this issue Oct 31, 2024 · 0 comments
Labels

Comments

@upsuper
Copy link
Contributor

upsuper commented Oct 31, 2024

Test the following code:

  function create() {
    const array = mobx.observable.array();
    let dispose: (() => void) | undefined;
    mobx.onBecomeObserved(array, () => {
      dispose = mobx.reaction(() => {}, () => {});
    });
    mobx.onBecomeUnobserved(array, () => {
      dispose?.();
    });
    return array;
  }

  const arrays = Array.from({ length: 10_000 }, () => create());
  const dispose = mobx.reaction(() => arrays.flat(), () => {});
  dispose();

Intended outcome:

It should not trigger any error.

Actual outcome:

It triggers "Maximum call stack size exceeded" error.

How to reproduce the issue:

CodeSandbox for the code above: https://codesandbox.io/p/sandbox/currying-cache-v2n9yx

Versions

I can reproduce it on at least 6.12.5 and 6.13.5. Haven't tested other versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant