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(platform-server): add styles to elements correctly #22527

Closed
wants to merge 1 commit into from

Conversation

CaerusKaru
Copy link
Member

@CaerusKaru CaerusKaru commented Mar 1, 2018

Fixes #22536

@CaerusKaru
Copy link
Member Author

CaerusKaru commented Mar 1, 2018

@vikerman @alexeagle @vicb

@CaerusKaru CaerusKaru changed the title chore: partial revert of #22263 fix(platform-server): partial revert of #22263 Mar 1, 2018
@alexeagle alexeagle requested a review from vikerman March 1, 2018 15:58
@alexeagle alexeagle added the area: server Issues related to server-side rendering label Mar 1, 2018
@vicb
Copy link
Contributor

vicb commented Mar 1, 2018

  1. What was the issue ? (could you please create a GH issue and link it from the test)
  2. could you please rephrase the commit message:
fix(platform-server): <what does this fix ?>

partial revert of #22263

@vicb vicb added the action: review The PR is still awaiting reviews from at least one requested reviewer label Mar 1, 2018
const styleMap = {};
const styleAttribute = element.getAttribute('style');
if (styleAttribute) {
const styleList = styleAttribute.split(/;+/g);
Copy link
Contributor

@vicb vicb Mar 1, 2018

Choose a reason for hiding this comment

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

nit: what about /(\s*;\s*)+/g here ?

Copy link
Contributor

Choose a reason for hiding this comment

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

oh would not work either so maybe
1- split on /;+/g
2- trim() the parts
3- ignore empty parts

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed the logic, let me know if that's what you had in mind

@CaerusKaru CaerusKaru changed the title fix(platform-server): partial revert of #22263 fix(platform-server): add styles to elements correctly Mar 1, 2018
@CaerusKaru
Copy link
Member Author

@vicb changed commit message and opened a new issue

@agustinhaller
Copy link

@vicb any updates on merging this PR?

if (styleAttribute) {
const styleList = styleAttribute.split(/;+/g);
for (let i = 0; i < styleList.length; i++) {
if (styleList[i].length > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

triming before checking the length would probably make more sense ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

if (!style) {
continue;
}
const colon = style.indexOf(':');
Copy link
Contributor

Choose a reason for hiding this comment

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

nit colon -> colonIndex

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

if (colon === -1) {
throw new Error(`Invalid CSS style: ${style}`);
}
(styleMap as any)[style.substr(0, colon).trim()] = style.substr(colon + 1).trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: extract const name = style.substr(0, colon).trim();

Copy link
Contributor

Choose a reason for hiding this comment

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

there should be as any needed here

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@@ -135,17 +135,53 @@ export class DominoAdapter extends BrowserDomAdapter {
return href;
}

/** @internal */
_readStyleAttribute(element: any) {
const styleMap = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

const styleMap: {[name: string]: string} = {} and then remove un-needed "as any"

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

@@ -135,17 +135,53 @@ export class DominoAdapter extends BrowserDomAdapter {
return href;
}

/** @internal */
_readStyleAttribute(element: any) {
Copy link
Contributor

Choose a reason for hiding this comment

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

add return type

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

setStyle(element: any, styleName: string, styleValue?: string|null) {
styleName = styleName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
element.style[styleName] = styleValue;
const styleMap = this._readStyleAttribute(element);
(styleMap as any)[styleName] = styleValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for any if types are specified upstream

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

}
getStyle(element: any, styleName: string): string {
return element.style[styleName] || element.style.getPropertyValue(styleName);
const styleMap = this._readStyleAttribute(element);
return styleMap.hasOwnProperty(styleName) ? (styleMap as any)[styleName] : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

no need for as any

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

@vicb vicb left a comment

Choose a reason for hiding this comment

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

a few nits but LGTM otherwise.
Thanks and sorry for the delay in reviewing

@vicb
Copy link
Contributor

vicb commented Mar 14, 2018

  • Typo in the commit message (complicance)
  • Was is the target: master and/or patch

@CaerusKaru
Copy link
Member Author

Should be PR target: master & patch

@vicb vicb added the target: patch This PR is targeted for the next patch release label Mar 14, 2018
setStyle(element: any, styleName: string, styleValue?: string|null) {
styleName = styleName.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
element.style[styleName] = styleValue;
const styleMap = this._readStyleAttribute(element);
styleMap[styleName] = styleValue + '';
Copy link
Contributor

Choose a reason for hiding this comment

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

do we really want "undefined" as a possible value ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

}
getStyle(element: any, styleName: string): string {
return element.style[styleName] || element.style.getPropertyValue(styleName);
const styleMap = this._readStyleAttribute(element);
return styleMap.hasOwnProperty(styleName) ? styleMap[styleName] : '';
Copy link
Contributor

Choose a reason for hiding this comment

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

return styleMap[styleName] || ''; ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed

This was referenced Mar 15, 2018
leo6104 pushed a commit to leo6104/angular that referenced this pull request Mar 25, 2018
* Partially reverts angular#22263 due to lack of total spec compliance
  on the server
* Maintains the camel-case styles fix

PR Close angular#22527
@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 13, 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: server Issues related to server-side rendering cla: yes target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug(platform-server): some styles not applying correctly
6 participants