-
Notifications
You must be signed in to change notification settings - Fork 25.7k
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
Conversation
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. |
They are moving away from parse5 #14939 |
@DzmitryShylovich It's an on going discussion |
41 file have been changed. doesn't look like a discussion :) |
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. |
There was a problem hiding this 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'); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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(() => { |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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'); | ||
}); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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'); |
There was a problem hiding this comment.
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.
3b620cd
to
693d871
Compare
@@ -145,6 +155,33 @@ export function main() { | |||
}); | |||
})); | |||
|
|||
it('adds title to the document', async(() => { |
There was a problem hiding this comment.
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.
9dc7d88
to
6267578
Compare
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. |
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 { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
This PR needs to be rebased. |
rebased |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Please check if the PR fulfills these requirements
What kind of change does this PR introduce? (check one with "x")
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")