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): fix get/set title for parse5 adapter #14965

Merged
merged 1 commit into from
Mar 13, 2017

Conversation

FrozenPandaz
Copy link
Contributor

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)

Fixes #14936

Currently, setting and getting the title on platform-server is broken and untested.

What is the new behavior?

Getting and setting the title will function and be tested

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

[ ] Yes
[x] No

@FrozenPandaz
Copy link
Contributor Author

I'm planning a change which will cache the document's title the first time its retrieved so we dont have to query every time.

@DzmitryShylovich
Copy link
Contributor

They are moving away from parse5 #14939

@FrozenPandaz
Copy link
Contributor Author

@DzmitryShylovich It's an on going discussion

@DzmitryShylovich
Copy link
Contributor

41 file have been changed. doesn't look like a discussion :)

@vikerman
Copy link
Contributor

vikerman commented Mar 6, 2017

Hey @DzmitryShylovich - I've been in sync with @FrozenPandaz and asked him to submit this PR. The PR to move to jsdom is still experimental. We still have to figure out whether it is performant enough. Thanks.

@vikerman vikerman self-requested a review March 6, 2017 23:02
@vikerman vikerman added the action: review The PR is still awaiting reviews from at least one requested reviewer label Mar 6, 2017
Copy link
Contributor

@vikerman vikerman left a comment

Choose a reason for hiding this comment

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

Please fix the commit message to fix(platform-server):...

@@ -592,6 +596,16 @@ export class Parse5DomAdapter extends DomAdapter {
getCookie(name: string): string { throw new Error('not implemented'); }
setCookie(name: string, value: string) { throw new Error('not implemented'); }
animate(element: any, keyframes: any[], options: any): any { throw new Error('not implemented'); }
private getTitleNode(doc: any) {
let title = this.querySelector(doc, 'head title');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you just query doc.head for title?

}

title = this.createElement('title');
this.appendChild(this.querySelector(doc, 'head'), title);
Copy link
Contributor

Choose a reason for hiding this comment

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

doc.head should already be set to the head element

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought so too.. but i was having trouble.. i will double check

getDOM().setTitle(doc, 'Test');
const title = getDOM().querySelector(doc, 'head title');
expect(title).toBeTruthy();
expect(getDOM().getText(title)).toContain('Test');
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you make it stricter to .toBe('Test') ?

}));
}));

it('adds title to the document', async(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this integration test!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Then it'll never happen again :)

const title = getDOM().querySelector(doc, 'head title');
expect(title).toBeTruthy();
expect(getDOM().getText(title)).toContain('Test');
});
Copy link
Contributor

Choose a reason for hiding this comment

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

For a more end to end check we should do a PlatformState.renderToString() and make sure the title is rendered

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good idea, i think i'll make it a separate it() so we know the difference

}]);
platform.bootstrapModule(ExampleModule).then(ref => {
const doc = ref.injector.get(DOCUMENT);
getDOM().setTitle(doc, 'Test');
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use the Title service in the test. That's how we want end users to set the title.

@FrozenPandaz FrozenPandaz changed the title fix(@angular/platform-server): fix get/set title for parse5 adapter fix(platform-server): fix get/set title for parse5 adapter Mar 7, 2017
@@ -145,6 +155,33 @@ export function main() {
});
}));

it('adds title to the document', async(() => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you remove this test? We just want to test public API in the integration test.

@vikerman vikerman added action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Mar 7, 2017
@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.

@googlebot
Copy link

CLAs look good, thanks!

@@ -30,7 +30,7 @@ function _notImplemented(methodName: string) {
/**
* Parses a document string to a Document object.
*/
export function parseDocument(html: string) {
export function parseDocument(html: string): Document {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please leave the return type as any - since it's a parse5 Document and not the standard TS Document interface,

@@ -43,6 +43,7 @@ export function parseDocument(html: string) {
* can introduce XSS risks.
*/
export class Parse5DomAdapter extends DomAdapter {
private title: HTMLTitleElement;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please leave the type of this as any - This is a parse5 Element and not an actual HTMLTitleElement.

@vikerman vikerman added action: merge The PR is ready for merge by the caretaker and removed action: cleanup The PR is in need of cleanup, either due to needing a rebase or in response to comments from reviews labels Mar 7, 2017
@chuckjaz
Copy link
Contributor

This PR needs to be rebased.

@FrozenPandaz
Copy link
Contributor Author

rebased

@chuckjaz chuckjaz merged commit 018e5c9 into angular:master Mar 13, 2017
@FrozenPandaz FrozenPandaz deleted the title branch March 14, 2017 22:40
SamVerschueren pushed a commit to SamVerschueren/angular that referenced this pull request Mar 18, 2017
asnowwolf pushed a commit to asnowwolf/angular that referenced this pull request Aug 11, 2017
juleskremer pushed a commit to juleskremer/angular that referenced this pull request Aug 28, 2017
@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 11, 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 cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[platform-server]: Unable to set Title
5 participants