Repository navigation
Open
Description
🐞 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
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>
}Reacted by Boris Petrov
Activity
Allow get/set/get (lazy initialization) within same tracking frame
ef4 commentedon Apr 6, 2026
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.
krisselden commentedon Apr 8, 2026
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.