-
Notifications
You must be signed in to change notification settings - Fork 25.3k
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 an exception when HostListener('window:scroll') is used on the server #15019
Conversation
Do you want me to fix title, it can now query the document.head |
for (let i = 0; i < docElement.childNodes.length; i++) { | ||
let node = docElement.childNodes[i]; | ||
if (node.name === 'head') { | ||
doc['head'] = node; |
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.
this needs to be a getter for the head node
doc['head'] = node; | ||
} | ||
if (node.name === 'body') { | ||
doc['body'] = node; |
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.
this needs to be a getter for the body node
you're going to run into the same problem as universal 2.1.x has. There will be a case when you're referencing a detached node if the document was changed after creation. PS: You should include |
if (node.name === 'head') { | ||
doc['head'] = node; | ||
} | ||
if (node.name === 'body') { |
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.
else if / switch
There is another issue when the html string has a Doctype, it appears as the first node of the parsed document. Therefore the head and body nodes aren't retrieved properly. |
@jimjim2a is correct this is also why we had weird searching logic for the rootNode |
@@ -31,7 +31,19 @@ function _notImplemented(methodName: string) { | |||
* Parses a document string to a Document object. | |||
*/ | |||
export function parseDocument(html: string) { | |||
return parse5.parse(html, {treeAdapter: parse5.treeAdapters.htmlparser2}); | |||
let doc = parse5.parse(html, {treeAdapter: parse5.treeAdapters.htmlparser2}); | |||
let docElement = doc.childNodes[0]; |
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.
How does this interact with a <!doctype>
?
This PR now needs to be rebased. |
…ll') is used on the server
@chuckjaz - Rebased |
…ll') is used on the server (angular#15019)
…ll') is used on the server (angular#15019)
…ll') is used on the server (angular#15019)
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. |
Fixes #15000
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)
Trying to bootstrap when a component has @HostListener("window:scroll") causes an exception on the server
What is the new behavior?
No exception
Does this PR introduce a breaking change? (check one with "x")