-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[BUGFIX][Tracked Properties] Prevents autotracking ArrayProxy creation
This PR prevents an issue with inifinite rerendering that is fundamentally caused by creating an array proxy and returning it from a getter. This is commonly done with _promise arrays_, which proxy to content that is fulfilled at a later point in time: ```js export default CountrySelectComponent extends Component { @service store; get options() { return this.store.findAll('country'); } } ``` While it likely makes sense to memoize these types of requests, even in that case, the cache will be busted by autotracking because the _creation_ of the array proxy causes it's content to be tracked. When the content is updated later, it will then invalidate the cache, causing the value to be thrown away before it can even be used, and a new value to be fetched. This loops infinitely. To get around this, we realized that array proxies do not need to add observers until they have been _interacted_ with in some way. We set the `CONSUMED` flag on the proxy to indicate that this has happened, and only add/remove observers if it has. Since this happens lazily, it is _generally_ guaranteed to happen after the getter has returned, since it usually doesn't make sense to both create a value and access it in the same getter.
- Loading branch information
Chris Garrett
committed
Apr 2, 2019
1 parent
e2c828d
commit 6d3fd43
Showing
5 changed files
with
75 additions
and
15 deletions.
There are no files selected for viewing
23 changes: 22 additions & 1 deletion
23
packages/@ember/-internals/extension-support/lib/data_adapter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters