-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
[BREAKING BUGFIX beta] Adds autotracking transaction #18554
Conversation
Adds a more strict assertion for autotracking, which prevents users from accidentally using and then mutating an tracked property in the same autotracking frame. This throws an error in most cases, except when using `get` and `set` to inside a class based helper. Since that API has been around for quite some time, it's likely that autotracking being enabled now will cause some issues in the ecosystem if we begin asserting, even though it may make sense to do so.
fe615b0
to
d610c63
Compare
d610c63
to
c1ee6d1
Compare
packages/@ember/-internals/glimmer/tests/integration/application/rendering-test.js
Outdated
Show resolved
Hide resolved
packages/@ember/-internals/glimmer/tests/integration/helpers/unbound-test.js
Show resolved
Hide resolved
Thanks for continuing to work on this, sorry for all the nit-picky reviews! From my perspective this seems like a non-trivial shift and could reasonably be considered a breaking change given that Can you also include information in the PR description explaining the motivation for this change? The current info does a good job of explaining what this PR does, but doesn't really explain why we'd want to do that. I think that would be a decent start to ensuring we can justify things and that we are all on the same page. |
packages/@ember/-internals/glimmer/tests/integration/helpers/custom-helper-test.js
Outdated
Show resolved
Hide resolved
062feee
to
36d211b
Compare
36d211b
to
b69e6f7
Compare
b69e6f7
to
255bd28
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some inline comments, looking much better from my perspective.
Can you include a sample of the expected assertion/deprecation messages in the PR description?
packages/@ember/-internals/glimmer/lib/component-managers/curly.ts
Outdated
Show resolved
Hide resolved
@@ -338,6 +339,23 @@ if (EMBER_METAL_TRACKED_PROPERTIES) { | |||
'invalid after setting a property on the object' | |||
); | |||
} | |||
|
|||
['@test gives helpful assertion when a tracked property is mutated after access in with an autotracking transaction']() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
['@test gives helpful assertion when a tracked property is mutated after access in with an autotracking transaction']() { | |
['@test gives helpful assertion when a tracked property is mutated after access in an autotracking transaction']() { |
62b1fce
to
6282a74
Compare
The What
Adds a more strict assertion for autotracking, which prevents users from accidentally using and then mutating a tracked property in the same autotracking frame.
This throws an error in most cases, except when using
get
andset
to mutate inside a class based helper. Since that API has been around for quite some time, it's likely that autotracking being enabled now will cause some issues in the ecosystem if we begin asserting, even though it may make sense to do so.The Why
Let's look at a small example component:
Today, this would work, and it would have worked in the past if we modeled the same logic using ComputedProperty. However, we are dangerously close to triggering a number of problematic edge cases.
isLoading
). If we were to flip the order of the invocations in the template, we would definitely run into issues, since the template would be out of date as soon as we updated the value:This would trigger the backflow-rerender assertion that has existed in Ember for quite some time now. Without this assertion, it would be very difficult to know for sure if your template would be correct by the end of the render, and you could easily end up in infinite-invalidation cycles.
We can tell that it has a bug, because the
sum
we calculated intotal
doesn't take into account the fact thatitems
has changed. This is also a relatively small and isolated occurrence, but in a much larger system this could get very difficult to reason about.The new assertion, like the previous backtracking-rerender assertion is designed to prevent incorrect usage in this way. Instead, local state and untracked fields/properties can be used when needed for internal state, ensuring that tracked state is always used consistently:
Notes
debugStack
in favor of thedebugRenderTree
env
to many of the RootReferences. This is necessary to get thedebugRenderTree
and log the current render stack when the refs are actually created.debugRenderTree
. Helper references need a bit of a refactor, and I wanted to do it after we land the VM upgrade. Modifiers run after render, so I'm actually unsure how to get them the correct logging info.ember-observers
tests against this change, without the warning logic for helpers, and they were green. The warning helper is really extra precaution, since some of our tests were failing.