-
-
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
Further refine the error messages around allowing normal JavaScript property gets #16148
Comments
An example of the non resilient probing code is |
I'm seeing this error get triggered by code we don't control in chai.js
This is the line of test code that triggers this, where
|
@Dhaulagiri - That specific issue should have been addressed in emberjs/data#5340 (which was released in [email protected]). However, I do still believe there are some changes that we could make to reduce (and avoid the DS.Errors like issue). IMHO we should update the assertion system to allow ember.js/packages/ember-runtime/lib/system/core_object.js Lines 128 to 130 in 2c1f9bf
|
@rwjblue sure enough, using ED 3.1 seems to fix it. Sadly we have been trapped on ED 2.12 for a long time so that fix won't be of immediate help to us as we try to upgrade ember itself, so I may explore your second suggestion. |
@Dhaulagiri - FWIW, many/most of the ember-data upgrade blocking issues that happened in the 2.12 era have been addressed in [email protected]. Might be worth a try... |
@cibernox |
@denzo - Seems like a bug report should be filed in ember-power-select, no? |
@huberts I was not. What is wrong exactly with |
There is an open PR in the works (over in #16560) to prevent the proxy assertion from applying to functions. This fixes a large number of the existing reported issues (e.g. the ember-power-select probing for |
Just to clarify: with this change, are we still supposed to be able to use ember-metal functions on Proxy objects? I am getting this assertion triggered in testing when I call isEmpty on a Proxy object: https://github.com/emberjs/ember.js/blob/master/packages/ember-metal/lib/is_empty.js#L45
|
…2>). Since Ember 3.1, this is usually fine as you no longer need to use `.get()` to access computed properties. However, in this case, the object in question is a special kind of Ember object (a proxy). Therefore, it is still necessary to use `.get('length')` in this case. If you encountered this error because of third-party code that you don't control, there is more information at emberjs/ember.js#16148, and you can help us improve this error message by telling us more about what happened in this situation."
@wycats do you know if any effort has been done to further refine the errors? Sounds like we need to provide a good warning message for the scenario where dot access was attempted for a proxy object ?
Also need to be sure this is well understood ^ Thanks @yininge for pointing out we need to revisit this one :) Perhaps instead of Per the 3.1 blog post we have instruction on when to use
My best guess is that the last item for a |
…2>). Since Ember 3.1, this is usually fine as you no longer need to use `.get()` to access computed properties. However, in this case, the object in question is a special kind of Ember object (a proxy). Therefore, it is still necessary to use `.get('length')` in this case. If you encountered this error because of third-party code that you don't control, there is more information at emberjs/ember.js#16148, and you can help us improve this error message by telling us more about what happened in this situation."
…2>). Since Ember 3.1, this is usually fine as you no longer need to use `.get()` to access computed properties. However, in this case, the object in question is a special kind of Ember object (a proxy). Therefore, it is still necessary to use `.get('length')` in this case. If you encountered this error because of third-party code that you don't control, there is more information at emberjs/ember.js#16148, and you can help us improve this error message by telling us more about what happened in this situation."
…2>). (#1148) Since Ember 3.1, this is usually fine as you no longer need to use `.get()` to access computed properties. However, in this case, the object in question is a special kind of Ember object (a proxy). Therefore, it is still necessary to use `.get('length')` in this case. If you encountered this error because of third-party code that you don't control, there is more information at emberjs/ember.js#16148, and you can help us improve this error message by telling us more about what happened in this situation."
* Resolves typo. (cibernox#1055) * Added another addon: https://github.com/IliasDeros/ember-data-power-select * v2.0.0-beta.1 * Fix but by bumping minimum version of ember-basic-dropdown * selectedItemComponent into beforeOptionsComponent (cibernox#1060) Make `selectedItemComponent` available in `beforeOptionsComponent`. This will allow for a persistent header showing the overall selected items inside of `power-select-multiple`. This matters in the case where the list ends up scrolling. * v2.0.0-beta.2 * Fix sandboxing * Add extra params for trigger (cibernox#1062) * Add factoryFor in 2.10 ember-try scenario (cibernox#1063) * Improve test-helpers import path (cibernox#1067) * Improve test-helpers import path * Still use ember-native-dom-helpers for find and findAll * Document new import path * v2.0.0-beta.3 * Fix bad code sample * `horizontalPosition` property api reference update (cibernox#1071) * Update how-to-use-it.hbs (cibernox#1080) typo * Update installation.hbs (cibernox#1078) small typo * Update installation.hbs (cibernox#1079) this might be a typo as well * Update action-handling.hbs (cibernox#1081) Sorry to submit several PRs. I create them as I encounter typos. I tried compile only one for action-handling.hbs this time tough ;-) * stop click propagation added to the docs (cibernox#1087) * stop click propagation added to the docs * added more info about stop click propagation in the docs * Update addon to 3.1 (cibernox#1088) * Update addon to 3.1 * Smarter way to decide wether or not we want to load jquery * Modernize test suite part 1 (cibernox#1089) * Modernize test suite part 2 (cibernox#1090) * Modernize test suite part 3 (cibernox#1091) * Modernize test suite part 4 (cibernox#1092) * Modernize test suite part 5 (cibernox#1093) * Remove more usages of ember-native-dom-helpers * Add more qunit-dom * fixes cibernox#1094 (cibernox#1097) * qunit-dom is almost everywhere (cibernox#1096) * v2.0.0-beta.4 * Simplify tests a bit more * Penultimate test refactor (cibernox#1098) * Remove all traces of find/findAll from ember-native-dom-helpers * Changed self.window to window and self.document to document (cibernox#1099) * v2.0.0-beta.5 * Pre-render docs site at build time (cibernox#1102) This PR enables Fastboot pre-rendering of the entire docs site using [prember[(https://github.com/ef4/prember). For URL discovery, it's using the newly-published [prember-crawler](https://github.com/ef4/prember-crawler) I tested the `_redirects` on netlify to confirm it will work, and it does. By default, prember outputs an `_empty.html` file that contains your original (empty) index.html content, since your pre-rendered index.html file will have actual content in it. * Making helpers more async (cibernox#1100) * Fix last set of tests * Add two more tests * Improve component's behavior in beta (cibernox#1104) * Fix typo * Remove native dom helpers (cibernox#1105) * Remove dependency on ember-native-dom-helpers * Not used any more * Update changelog * v2.0.0 * Update ember-concurrency to fix bug in beta and canary (cibernox#1106) * Drop node 4 * Add extra params for `selectedItemComponent` on trigger (power-select-multiple) (cibernox#1111) * Fix: add extra hash to power-select-multiple selectedItemComponent * Test: Add a couple missing tests for power-select-multiple with custom components * Test: Update to use new `qunit-dom` test syntax * v2.0.1 * Remove direct access to then (cibernox#1116) * v2.0.2 * Remove console-log from test helper (cibernox#1119) * typo (cibernox#1118) * Remove console.log from test support (cibernox#1108) * v2.0.3 * Bind title to the trigger (cibernox#1126) * Fix tests failing due to new assertion in triggerKeyEvent (cibernox#1129) * Replaced return value of maybePlaceholder for IE to undefined (cibernox#1128) * v2.0.4 * Update to ember-cli 3.2 (cibernox#1132) * Update to 3.3 (cibernox#1137) * 2.X is not in beta * guard against destroying hook when calling deactivate (cibernox#1144) * 2.0.5 * Update to ember-cli 3.4 (cibernox#1149) * Update to ember-cli 3.4 * Fix template-lint errors * Update ember-data to 3.4 (cibernox#1150) * Test and possible fix for cibernox#1147 (cibernox#1151) * v2.0.6 * Only load polyfill when not in FastBoot environment (cibernox#1155) fixes cibernox#1154 * v2.0.7 * v2.0.7 * fix: typeof returns string, broke polyfill when necessary (cibernox#1157) * v2.0.8 * Fix typo in api-reference.hbs (cibernox#1158) * use .set() to avoid assertion failure under Ember 3.4 (cibernox#1162) * Add animationEnabled to be passed down to ember-basic-dropdown (cibernox#1165) * Add highlightOnHoverEnabled to be used in options.js (cibernox#1166) * Add highlightOnHoverEnabled to be used in options.js When false, will disable automatically highlighting an option when hovered over with the mouse. This will prevent unintentionally selecting a new value when tabbing through a form with an EPS field while the user's mouse is where the list will appear when the EPS gains and then looses focus. * Renamed highlightOnHoverEnabled to highlightOnHover * v2.0.9 * Change slack for discord (cibernox#1169) * close -> clone (cibernox#1176) * close -> clone 'clone' is the intended word in the context, and the spelling error 'close' may cause some confusion to the reader * spelling error fixes close -> clone debounding -> debouncing just two small mistakes, can be confusing in context for the reader * Fix build error (cibernox#1178) * User active-voice instead of passive-voice * Document using a computed property for the selected property * Fix build error due to missing rel='noopener' * Improve documentation (cibernox#1177) * User active-voice instead of passive-voice * Document using a computed property for the selected property * Fix build error due to missing rel='noopener' * minor typos * Changed npm and bower for yarn Changed instructions for contributing from `npm install` and `bower install` to `yarn install` as per cibernox#1179 to reflect updated build tools. * Fix typo * Allow select to open with click (cibernox#1181) * v2.0.10 * v2.0.11 * Fix inconsistent focus of the input in single selects (cibernox#1180) * v2.0.12 * v2.0.13 * v2.0.14 * v2.0.15 * Fix npm audit warnings (1 critical, 2 high) (cibernox#1183) * Allow direct imports from node_modules (cibernox#1182) * v2.1.0 * v2.2.0 (cibernox#1185) * [BUGFIX] Allow test helpers to work with EBD >=1.0.5 (cibernox#1190) In EBD 1.0.5 a fix for better a11y was introduced. It makes aria-owns to only be present on the trigger when the dropdown is open. Test helpers in EPS relied in that property being there all the time, but now they work both ways. * v2.2.1 * Specify that only strings are searchable * Update all dependencies December 2018 (cibernox#1194) * Update all dependencies December 2018 * Fix sass complaint * Fix tests * Replace ember-cli-eslint with plain eslint (cibernox#1195) * "You attempted to access the `length` property (of <(unknown):ember712>). (cibernox#1148) Since Ember 3.1, this is usually fine as you no longer need to use `.get()` to access computed properties. However, in this case, the object in question is a special kind of Ember object (a proxy). Therefore, it is still necessary to use `.get('length')` in this case. If you encountered this error because of third-party code that you don't control, there is more information at emberjs/ember.js#16148, and you can help us improve this error message by telling us more about what happened in this situation."
Closing this for now. Happy to reopen, but these messages have been around for quite a long time now and we aren't working on changing them. |
This issue is tracking problems that come up due to allowing normal JavaScript property lookup to work with computed properties.
Context
We are in the process of landing a change that will allow you to use normal property lookups to get properties defined as computed properties in Ember.
In practice, what this means is that, in most cases (more later) you will be able to drop
.get('key')
and replace it with.key
.However, there are a handful of small historical issues that could make the transition a little more messy. If you landed on this issue, chances are you encountered a warning from Ember that you encountered one of these historical issues.
Computed Properties used to be directly on the prototype
Until Ember 3.0, internal implementation details of Ember caused computed properties to be directly present on objects, so if you didn't use
.get()
, you would see the internal "Ember descriptor" representing the computed property (a private API).This internal implementation detail was never intended to be a public (or even intimate) API.
This internal implementation detail has now changed and the (still private) "descriptor" object has been relocated to the object's "meta" (also a private API). This allows us to make normal property lookup work, and in general, very few people were relying on the presence of this internal descriptor.
If you encountered an error related to this problem, you are probably using an addon that relies on this now-defunct private implementation detail, and your best bet is to follow the instructions in the error message (and ask for help in #dev-ember).
Ember Proxies are tricky
Secondly, since the new behavior relies on using
defineProperty
, it does not allow users of Ember proxies to stop using.get()
.Previously, since all Ember objects required you to use
.get()
to access properties, you could uniformly use.get()
in your code and never need to worry about whether an object was an Ember proxy.However, now that you can use normal property access for computed properties, Ember proxies are special. If an object is implemented using an Ember proxy, it should advertise itself as requiring
.get()
to access its proxied properties.This is analogous to other libraries in the JavaScript ecosystem, such as
immutable.js
, that expose an API that is different from normal JS property access patterns.Since proxies are relatively rare in Ember compared to property access on other Ember objects, emberjs/rfcs#281 (now merged) felt that the cost of losing consistent property access (everyone types
.get()
everywhere, so you don't need to know when an object is "special") was worth the benefit of normally not needing to use.get()
.During the transition, we are worried that people will accidentally migrate some
.get()
s on Ember proxies to regular property access, so we added an assertion to the code that fires if:unknownProperty
returns a value other than undefined(this development-mode assertion is implemented using ES2015 proxies, which are not yet present on all supported browsers, but will cover the browsers people typically use for development)
For the most part, this avoids the vast majority of mistakes but it does introduce a possible problem with code that "probes" objects to discover whether they implement protocols.
Here's what I mean by "probing" code:
A more resilient way to write this code would be:
Unfortunately, apps are not always in control of the probing code (which could come from test frameworks, generic serialization logic, etc.).
Notably, "probing" code is only a problem if:
toString
, which is usually a real property of the Ember proxy itself)unknownProperty
returns something other thanundefined
It's definitely possible that an Ember proxy could return some object for every possible property, and that some probing code checks for a protocol that's not usually present on the wrapper object (like
toString
), which would trigger the assertion inappropriately.This problem comes up now because probing code previously would only look at properties of the wrapper proxy object, but now, in order to provide good errors for people accidentally removing
.get()
that they shouldn't have, normal property accesses on Ember proxies become sensitive to the behavior ofunknownProperty
.Again, the correct mental model going forward is that these objects (most notably the values returned from relationships in Ember Data) are now special objects and require a non-standard API, but the process of migration introduces this ambiguity.
If you got this error and didn't expect it, please reply to this issue with information about what happened so we have help improve the error message with more further advice and workarounds.
The text was updated successfully, but these errors were encountered: