-
-
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
Helper receiving arguments before being torn down #18969
Comments
Can you add some logging to |
export default helper(function mapBy([array, propertyName]) {
return array.mapBy(propertyName);
}); But it is not really tied to this - it also happens when passing it to any other helper. With a logging like this: {{log 'A' @selectedRecipesWithColor}}
{{#if @selectedRecipesWithColor}}
{{log 'B' @selectedRecipesWithColor}}
{{#let (map-by @selectedRecipesWithColor 'id') as |recipeIds|}}
{{! ... }} & export default helper(function mapBy([array, propertyName]) {
console.log('C', array);
return array.mapBy(propertyName);
}); I get the following output when first adding an item and then removing it:
|
@mydea perhaps you can create a reproduction of this in a new ember app or an ember-twiddle? I tried to recreate your issue here in 3.18.1, but it seems to work as expected: |
OK, I finally managed to get a reproduction! It's a bit tricky, but you can see it: With this example, if you add one, them remove it, you will see that the helper is called again. If I remove the |
Nice one on the reproduction. I'm seeing a similar behaviour in my app with This looks like a bug to me |
I played around with it a bit, and replace the import Helper from '@ember/component/helper';
export default class DidUpdateHelper extends Helper {
didRun = false;
compute([fn]) {
if (!this.didRun) {
this.didRun = true;
return;
}
fn();
}
} seemed to fix the issue. So it seems to somehow be connected with the modifier. |
I've also experienced this issue with a modifier deep in a component tree that shouldn't run, due to being wrapped in an if statement who's condition becomes false. This seems like a teardown bug in the VM, yeah? |
Here is my reproduction, which I think is slightly different: https://ember-twiddle.com/5a3fa797b26e8807869340792219a5ee?openFiles=components.demo%5C.hbs%2Ccomponents.demo%5C.hbs |
I can obviously hack around it by adding guards in my getter in the sub-component, but I think the condition of the if statement becoming false should prevent the getter from ever re-evaluating with invalid data? |
Made a repro repo: https://github.com/NullVoxPopuli/repro-repo-emberjs-18969 Additional notes for other readers, my issue seems to be related to modifiers. In the twiddle, if I change sub-component.hbs -<span {{data-attributes-from this.derivedData}}>{{@data.kind}}</span>
+<span>{{@data.kind}} -- {{this.derivedData}}</span> Then there is no error, and the subtree (as expected) doesn't re-render anything when the if condition becomes false. Also this bug is present in 3.16.x |
Here is the entire reproduction in a single component: https://ember-twiddle.com/5a3fa797b26e8807869340792219a5ee?openFiles=components.demo%5C.hbs%2Ccomponents.demo%5C.hbs it's weird, cause it is part of the spec (thanks @pzuraq !) https://github.com/emberjs/rfcs/blob/master/text/0373-Element-Modifier-Managers.md#destroymodifier but this is very expected (to me) 🤔 when the scenario is all self contained, I can kinda get behind the behavior, but, when you have a couple layers of misdirection or abstraction in between, it is non-obvious, imo (I like obvious errors :D ) So... I'm not sure on a path forward here. Basically, anything passed to a modifier needs to optionally chain all property accesses as there is no way to guarantee the shape of data (afaict, anyway) |
@NullVoxPopuli I think this is fixed in 3.26 with #19469 |
I have a template-only component like this (slightly simplified):
The
{{load-data-per-recipe}}
helper has an assertion thatrecipeIds
is not empty. Looking at the code, it shouldn't be possible for this assertion to happen here. However, when removing the@selectedRecipesWithColor
items until none remains, the assertion happens.The "CHECK" log never appears, but the helper receives an empty array anyhow (and breaks on the assertion).
The parent component updates the selection in a simple action like this:
It seems there is some sort of racing condition where the helper is called with new arguments when it should be torn down?
I am running 3.18.1!
The text was updated successfully, but these errors were encountered: