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

Excessive invalidation in ArrowFunctionExpression results in infinite loop #2748

Closed
timhall opened this issue May 13, 2019 · 5 comments
Closed
Labels

Comments

@timhall
Copy link
Contributor

timhall commented May 13, 2019

Bit of strange one, but here is a repro: https://svelte.dev/repl/67a7fb3e15fb4991916b9f6947c1e82a?version=3.2.2 (Note: will likely cause an infinite loop)

Here is the input:

<script>
  const a = Promise.resolve('a');
  let b = Promise.resolve('b');
	
  let a_value, b_value;
  $: a.then(value => a_value = value);
  $: b.then(value => b_value = value);
  $: b.then(value => { b_value = value });
</script>

and here is the relevant output:

function instance($$self, $$props, $$invalidate) {
  const a = Promise.resolve('a');
  let b = Promise.resolve('b');
	
  let a_value, b_value;

  $$self.$$.update = ($$dirty = { b: 1 }) => {
    if ($$dirty.b) { b.then(value => { const $$result = b_value = value; $$invalidate('b_value', b_value), $$invalidate('b', b); return $$result; }); }
    // Note the extra invalidate of b here ----------------------------------------------------------------^
    if ($$dirty.b) { b.then(value => { $$invalidate('b_value', b_value = value) }); }
  };

  a.then(value => { const $$result = a_value = value; $$invalidate('a_value', a_value); return $$result; });

  return {};
}

My guess is something related to mutation tracking (possibly tangentially related to #2728)

@Conduitry
Copy link
Member

Before I realized there was already an issue for this, I had explored a little more into what seemed to be causing this in #2873.

@timhall timhall changed the title let promise + arrow function + no braces = infinite loop Excessive invalidation in ArrowFunctionExpression results in infinite loop May 28, 2019
@Panya
Copy link
Contributor

Panya commented Jun 20, 2019

It was fixed in 3.4.4 and above.

@Conduitry
Copy link
Member

This is not fixed. Svelte will now no longer include invalidations if the variables are not referenced anywhere else, but if you add {b_value} to the template, you'll see the invalidations for both b_value and b.

@Conduitry
Copy link
Member

It looks like this would also be fixed by #3533.

@Conduitry
Copy link
Member

Fixed in 3.10.1.

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

3 participants