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

[BUGFIX beta] fix regression of clicking link-to with disabled=true #15952

Merged
merged 3 commits into from
Dec 22, 2017

Conversation

simonihmig
Copy link
Contributor

#15759 introduced a regression, allowing clicking on a {{#link-to "somewhere" disabled=true}} to still invoke the transition. This was because the default value of _isDisabled was moved to the init hook here: 8c68f5b#diff-49415576dd428811b5854523cc9b9adcR528, effectively overriding any previously set value.

The added test covers this, and was failing before the change here.

@bekzod
Copy link
Contributor

bekzod commented Dec 8, 2017

I think disabled is private in link-to, and you are supposed to use disabledWhen instead and #15780 supposed to fix it

@simonihmig
Copy link
Contributor Author

Hm, not sure...

  • even if it's private, it is supposed to work correctly, and all versions of Ember <= 2.17 do support the usage I fixed here, only beta and canary started to fail...
  • the documentation regarding this is actually a bit misleading (cc @locks), given that there is the API docs of the LinkComponent, but also the link-to helper docs (which are one and the same thing nowadays, right?):
    • the API docs of the LinkComponent mark disabled as private, but do not mention disabledWhen at all!
    • the link-to helper docs mention both disabled (though private!?) and disabledWhen
  • given that 👆, even if disabled is indeed private and mentioned by mistake in the docs, I would consider it an "intimate API" (that's how you call it, right?), i.e. should only be removed with a prior deprecation

So I would say either remove it all together (no-go IMHO), or fix the bug!?

@rwjblue
Copy link
Member

rwjblue commented Dec 8, 2017

Agreed. We should fix this. Even if we decide later to deprecate.

@simonihmig
Copy link
Contributor Author

Anything missing here? /cc @rwjblue

simonihmig and others added 3 commits December 22, 2017 09:09
The prior system was overly complicated (it still kinda is, but thats a
story for a future refactor). It relied on the fact that `_isDisabled`
was set to disable the link-to (either via hitting the `disabled` CPs
setter, or via passing `disabledWhen`) and then checked `_isDisabled`
when being invoked.

The original issue was that we were _always_ setting `_isDisabled` to
false in the constructor (done to ensure `link-to` has a consistent
shape). That was fixed by pre-sloting `_isDisabled` _before_ calling
`this._super` (yes, I know thats generally bad, but so is our
`Object.assign(instance, properties)` that runs _before_ `init`).
@rwjblue
Copy link
Member

rwjblue commented Dec 22, 2017

@simonihmig - Just updated the implementation here, mind taking another look?

@rwjblue rwjblue merged commit a7e2685 into emberjs:master Dec 22, 2017
return false;
},

set(_key: string, value: any): boolean {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated to the changes here, but the typing seems wrong. Shouldn't it be set(...): string|false?

Copy link
Member

Choose a reason for hiding this comment

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

@simonihmig - Yes, this should be typed as a string | null I believe.

any passed value to `disabled` will disable it except `undefined`.
to ensure that only `true` disable the `link-to` component you can
override the global behavior of `LinkComponent`.
any truthy value passed to `disabled` will disable it except `undefined`.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"except undefined" can be removed I think, as undefined is not truthy anyways?

Copy link
Member

Choose a reason for hiding this comment

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

GAH! Thank you

set(_key: string, value: any): boolean {
if (value !== undefined) { this.set('_isDisabled', value); }
this._isDisabled = value;
Copy link
Contributor Author

@simonihmig simonihmig Dec 22, 2017

Choose a reason for hiding this comment

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

The changes here seem right to me in general, but they do change the semantics a bit, don't they (the truthy vs. not undefined)? Could they break something for somebody?

Copy link
Member

Choose a reason for hiding this comment

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

@simonihmig if you take a look at where this._isDisabled is actually checked (in _invoke), we have been doing a truthy check there for a while so changing this to always update it just makes it simpler...

@simonihmig
Copy link
Contributor Author

@rwjblue Uh, already merged? :) I added a few comments...

@simonihmig simonihmig deleted the fix-linkto-disabled branch December 22, 2017 16:06
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