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

fix(core): allow undefined value for renderer setElement(…) #17065

Closed
wants to merge 1 commit into from

Conversation

Manduro
Copy link
Contributor

@Manduro Manduro commented May 27, 2017

Please check if the PR fulfills these requirements

What kind of change does this PR introduce? (check one with "x")

[x] Bugfix
[ ] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Other... Please describe:

What is the current behavior? (You can also link to an open issue here)
Renderer (V1) issue #13686, which has been closed but not fixed.

What is the new behavior?
Using Renderer’s setElementAttribute or setElementStyle with a null or undefined value removes the
corresponding attribute or style. The argument type now allows this when using strictNullChecks.

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[x] No

Other information:

@IgorMinar IgorMinar added area: core Issues related to the framework runtime action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 11, 2017
@chuckjaz
Copy link
Contributor

Note this is a breaking change and should be held until the first v5 beta.

It is not breaking for callers of callers of the render API but it is breaking for the implementors as they need now need to change the type of the third parameter to a union with undefined.

@chuckjaz
Copy link
Contributor

Consider changing the commit message to fix(core): allow undefined value for renderer setElement(…) as making a parameter adds undefined to the type not null.

@chuckjaz chuckjaz added type: bug/fix and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Jul 12, 2017
@Manduro Manduro changed the title fix(core): allow null value for renderer setElement(…) fix(core): allow undefined value for renderer setElement(…) Jul 12, 2017
@Manduro
Copy link
Contributor Author

Manduro commented Jul 12, 2017

@chuckjaz I'm not sure if this really is a breaking change. Can you provide an example where existing code would break?

Both functions where I'm changing the signature have checks for null/undefined's: here and here.
The problem is that when using strictNullChecks it does not allow that last parameter to be undefined. So imo this actually adds back functionality, instead of breaking anything.

@chuckjaz
Copy link
Contributor

chuckjaz commented Jul 12, 2017

@Manduro I removed the breaking change tag. It turns out that TypeScript is tolerant of incorrectly typed overrides.

The issue I had is with implementations of Renderer. Consider the following:

abstract class Base {
  abstract setElementAttribute(renderElement: any, attributeName: string, attributeValue: string): void;
}

class Derived extends Base {
  setElementAttribute(renderElement: any, attributeName: string, attributeValue: string): void { }
}

Changing attributeValue to be attributeValue?: string in the Base class changes the contract on what Derived can be called with. For example, the following type-checks:

const b: Base = new Derived();
b.setElementAttribute(1, 'attr');

which will pass undefined as attributeValue to Deriveds setElementAttribute even though it declared attributeValue to be a non-nullable string. Correctly typed overrides would require that all derived types of Base (hence Renderer) would need to be updated.

It appears that TypeScript is tolerant of this kind of incorrect override declaration so this doesn't break and we can take this change because all implementation were written prior to strict null checking and wouldn't have relied on attributeValue always being a string.

@Manduro
Copy link
Contributor Author

Manduro commented Jul 12, 2017

Ah yes, hadn't considered that. Glad it's not a problem.

I'm not touching Renderer2 by the way, to be clear. It has separate methods for adding and removing attributes and styles.

@chuckjaz
Copy link
Contributor

RE: Renderer2, updated my comment above to change Renderer2 to Renderer.

@splincode
Copy link
Contributor

@Manduro what is the status of your pull request? is it still relevant?

@Manduro
Copy link
Contributor Author

Manduro commented Mar 16, 2018

@splincode I guess it is as renderer v1 is still in the codebase, although it might not be long before it's removed. Don't know why this was never merged.

@mhevery mhevery self-assigned this Oct 11, 2018
@mhevery
Copy link
Contributor

mhevery commented Oct 11, 2018

@mhevery mhevery added the action: merge The PR is ready for merge by the caretaker label Oct 11, 2018
@mhevery mhevery added the target: major This PR is targeted for the next major release label Oct 12, 2018
Using Renderer’s setElementAttribute or setElementStyle with a null or undefined value removes the
corresponding attribute or style. The argument type should allow this when using strictNullChecks.

Closes angular#13686
@mhevery mhevery closed this in ff15043 Oct 12, 2018
FrederikSchlemmer pushed a commit to FrederikSchlemmer/angular that referenced this pull request Jan 3, 2019
Using Renderer’s setElementAttribute or setElementStyle with a null or undefined value removes the
corresponding attribute or style. The argument type should allow this when using strictNullChecks.

Closes angular#13686

PR Close angular#17065
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime cla: yes target: major This PR is targeted for the next major release type: bug/fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants