-
-
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
[Bug] Computed property smashing regression on 3.21.3 #19179
Comments
@ef4 I'm not sure what changed here exactly, but I believe TypeScript users should be using |
Yeah, I agree the usage isn’t great. I was just surprised to see the behavior change in a patch release. |
So looking at the code for model in particular, it hasn't changed in about a year: https://github.com/emberjs/ember.js/blame/master/packages/%40ember/controller/lib/controller_mixin.js#L48-L56 I don't believe we modified anything about this in particular recently. Is the Ember patch version the only thing that changed? |
I don't think this is specific to |
@ef4 oh interesting, I think this may have actually been another more subtle bug that actually was fixed by that PR. What would have been happening before is:
Now, it's being set on the descriptor, but the getter/setter that access the descriptor are still shadowed. I wonder if we can assert if the accessors are shadowed like this? |
Also, we should try to get a failing test case PR up based on @ef4's demo above so we can confirm any potential fixes work properly. |
@ef4 based on the description I gave above, do you agree that the previous behavior was actually buggy, and even though this "broke" more visibly we probably cannot actually fix it? |
Can we confirm your theory with a test? If it's true that there was missed autotracking before, that's a pretty convincing reason to keep things the way they are now. |
I would guess that many apps haven't tried 3.21.3 yet, given the prevalence of lockfiles and the six-week cycle. So I don't have a sense for how common this bug will be in the wild. I'm going to try to loop in some of our typescript experts to answer the following question: Ping @chriskrycho, @dfreeman, @mike-north, @jamescdavis, @chancancode! Do people use this pattern a lot? Specifically, declaring a type for a computed property that comes from your base class like: export default class Application extends Controller {
model: Whatever;
} (not necessarily just for It breaks in ember 3.21.3. Do you have typescript codebases where you can look for this problem? |
@ef4 right, but the real issue is that even if it appears to work at first, the next time the I don't think we can fix this bug in a way that would not cause the bug in the twiddle to resurface. Edit: Ah, I only saw your most recent comment, not the one right before it. I think the twiddle demonstrates the missing autotracking behavior, I think we definitely should add this as a test. |
I expect it’s going to be extremely common in existing TypeScript codebases. While the We have also been telling people for the better part of a year that the pre- (I’m also going to include this in the list of kinds of specific things we need to mitigate as I’m working on the design for publishing types officially.) |
I think what we should do here is have |
I think we would probably have used declare here. The reason we didn't is either because the code was written before we were able to use declare, or in this case, it was because the code is in a JavaScript file which the declare syntax is not available. I guess I would be more worried about the JS case since it seems quite common to use the field syntax for documentation purposes. Anyway I agree as typescript users this seems like the kind of thing that we fix pretty regularly so it's not a super big deal as long as it's easy to figure out where/why things broke. |
I suppose one valid case where shadowing may make sense is if you wanted to add a getter/setter to overwrite a computed in a subclass, for instance. This could also technically work for tracked properties, but it feels much sketchier to do that. If shadowing is valid in some cases, is there a way to warn users when they are doing in unintentionally, e.g. for documentation purposes? |
I'm not sure I correctly follow that issue but we're on the latest Ember (I tend to upgrade all the time) and we have a bunch of |
You should! That’s the correct way to define a type with these class field semantics (that is, defined by an external-to-the-class caller). We used and recommended the other approach because it’s all we had, but the |
We discussed this, and the solution we're planning to implement is to assert when this occurs in general to let users know that something may be being shadowed when they didn't realize it. It seems like this is pretty rare in general (especially given the only failure reported so far was due to type definitions, and not legitimate shadowing via inheritance) and it's also problematic as we were not applying it consistently previously - We do also plan to restore the previous behavior on release however, to minimize disruption for now and also stabilize the underlying fixes so they can be backported to LTS. We don't want this change to cause issues in a patch release there. |
I'd like to understand what is actually causing the I tried this snippet: class Parent {
@tracked foo = "whatever";
}
class Child extends Parent {
foo: string;
} And in both Babel Playground and Typescript Playground result in: class Child extends Parent {
} As far as I can tell that will not cause the bug reported here. @ef4 - What transpilation were you using? What version of |
@rwjblue - on the TypeScript playground that you gave, click |
@rwjblue I shared a complete minimalist reproduction above. The line that causes trouble is here: The app is using ember-cli-babel 7.22.1 and ember-cli-typescript 4.0.0, the full yarn.lock is here. |
This was fixed in #19197 and included in 3.22.1. |
🐞 Describe the Bug
In an app using ember-cli-typescript, a controller can declare the type of its
model
like this:This works fine in 3.21.2. But using ember-source 3.21.3, it causes
this.model
to be undefined.🔬 Minimal Reproduction
Run this app and see it crash: https://github.com/ef4/--bug-repro
Switch the app to use ember-source 3.21.2 and see it not crash.
Or comment out the type declaration for
model
inapp/controllers/application.ts
and see it not crash.😕 Actual Behavior
The
model
computed property appears to be getting smashed by typescript's compiler output (which emits something likeObject.defineProperty(this, 'model', void 0)
in the constructor).🤔 Expected Behavior
Should behave the same as in ember 3.21.2.
The text was updated successfully, but these errors were encountered: