Skip to content

get/set/get should be supported #21225

Open

Description

@NullVoxPopuli

🐞 Describe the Bug

get/set/get should work -- this is also known as lazy initialization, and is a very nice user convenience -- and I don't think we need we to error in this case and can instead error after a get after the set.

🔬 Minimal Reproduction

Here is get/set/get working in solidjs: https://playground.solidjs.com/anonymous/fa7ab1b1-cbab-4a5a-b838-89d1b26c6140

Here is the repro of the error:
https://limber.glimdown.com/edit?c=JYWwDg9gTgLgBAYQuCA7Apq%2BAzKy4DkAAgOYA2oI6UA9AMbKQZYEDcAUKJLHAN5wwoAQzoBrdABM4AXzi58xcpWo1BI0cFQk2nFD35oZcvCEJF0IAEYqQECcGzBqO9ugAe3eBPTYhAVzJ4OjIhAGdQuAAJdDIyCAB1aDIpdxhMCQikFGZ4XnY4OCI1MUk4Bj8sDny4EnQYAGU6gHE6uABeOAAKAEp2gD4%2BaoKyVrp2gQALYFCAOnLK9iGytFCIEZm4kk7%2BMelujgKCvMPDhy6AQjpemCnZ%2BfgOgCYDw%2Bkqk4ZUVfXNzpvpuYQCowfZLKB1PxQVCTAH3F5vRYFTR0cFULDjHr9GF3IHogDUHQAjO84AAeNLgEJpPpLUlgPoATSBcAmQgAbugyhQSlIbpzLH4YDBDLxeH9bjNag1mnVutJZDBQOhZqSaPTEYdSQKhYYYABPMDoNoAIm1wtQxr4vEMxuCwDElv%2Bs2RqMwMHlfQQ3NEqrNaBpBVVFLAVPQNOk7CAA&format=gjs

Assertion Failed: You attempted to update `count` on `HelloWorld`, but it had already been used previously in the same computation.  Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.

`count` was first used:

- While rendering:
  {ROOT}
    (result of a `unknown` helper)
      (result of a `(helper function getSetGet)` helper)

Stack trace for the update: (see console)

code:

import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { on } from '@ember/modifier';

export default class HelloWorld extends Component {
  @tracked count;

  getSetGet = () => {
    let c = this.count;

    console.log({ c });
    {
      if (!c) this.count = 2;
    };

    console.log(this.count);
    return this.count;
  };

  increment = () => this.count += 1;

  <template>
    <p>You have clicked the button {{(this.getSetGet)}} times.</p>

    <button type="button" {{on "click" this.increment}}>Click</button>
  </template>
}

Activity

  1. added a commit that references this issue on Mar 19, 2026
    24f5256
  2. ef4 commented on Apr 6, 2026

    @ef4
    Contributor

    This needs design and an RFC. It's not as simple as just allowing this case. If we allow this case, we accidentally allow other cases that should error in order to prevent infinite invalidation or other expensive multi-render situations.

  3. krisselden commented on Apr 8, 2026

    @krisselden
    Contributor

    You should at least make a less contrived use case, as it is I highly doubt allowing reads you immediately invalidate is worth it. A counter has no reason to be lazy. Generally lazy is derived state so you are more talking about a cache/memoize not tracked which is more root primitive state. The whole reason tracking works is the idea of one version per derived output, if you allow multiple versions to be seen you have to guarantee that the only one of those versions made it into the derived state. In rust, they have a similar issue with mutability and lazy initial value and they made a primitive around it called OnceCell. This is if this is a lazy default that is your motivating use case, I'm not certain because the example is contrived. I'll just echo @ef4, it isn't a bug and needs an RFC.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions