Skip to content
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

Pass value through to PROPERTY_DID_CHANGE to avoid calling get when setting values for computed props #18854

Merged
merged 1 commit into from
Apr 1, 2020

Conversation

brendenpalmer
Copy link
Contributor

As part of trying to upgrade our application from 3.12 -> 3.16, I discovered a regression where setting a value for a computed property, then immediately retrieving that value would return undefined. In our test suite and application this causes subtle bugs and unexpected behavior. With help from @pzuraq, we were able to trace this down to PROPERTY_DID_CHANGE firing at the wrong time, specifically for computed properties.

As part of this I also removed an unused setWithSuspend method.

Note that I confirmed that this test case passes on lts-3-12.

@rwjblue
Copy link
Member

rwjblue commented Apr 1, 2020

FYI - Linting is failing:

$ yarn lint:tsc && yarn lint:tslint && yarn lint:eslint && yarn lint:docs
$ tsc --noEmit
packages/@ember/-internals/metal/lib/computed.ts(261,11): error TS6133: '_suspended' is declared but its value is never read.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

obj: object,
keyName: string,
_meta?: Meta | null,
_shouldFirePropertyDidChange = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed this with @rwjblue this morning, and we realized a better solution here would be to pass the value optionally as the last argument to notifyPropertyChange here. This way, PROPERTY_DID_CHANGE can receive the value for this use case, and otherwise lookup the value if its undefined, and we don't have to call PROPERTY_DID_CHANGE again later on and copy all that logic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! I just updated the PR to pass the value through to notifyPropertyChange, then to PROPERTY_DID_CHANGE to avoid calling get.

@brendenpalmer brendenpalmer changed the title Ensure we fire PROPERTY_DID_CHANGE after we set the last revision Pass value through to PROPERTY_DID_CHANGE to avoid calling get when setting values for computed props Apr 1, 2020
@pzuraq pzuraq merged commit 1a75fd9 into emberjs:lts-3-16 Apr 1, 2020
@pzuraq
Copy link
Contributor

pzuraq commented Apr 1, 2020

Thanks a ton @brendenpalmer! If you could cherry-pick this onto master as well that'd be super helpful!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants