-
Notifications
You must be signed in to change notification settings - Fork 80
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
Fixed: inspecting document.title deleted it as a side-effect (when cached) #266
Fixed: inspecting document.title deleted it as a side-effect (when cached) #266
Conversation
Switching to linkedom/cached introduced a regression. See WebReflection/linkedom#266
Switching to linkedom/cached introduced a regression. See WebReflection/linkedom#266
esm/html/document.js
Outdated
@@ -77,13 +77,13 @@ export class HTMLDocument extends Document { | |||
*/ | |||
get title() { | |||
const {head} = this; | |||
let title = head.getElementsByTagName('title').shift(); | |||
let title = head.getElementsByTagName('title')[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.
I think these days I would go for .at(0
) instead ... so this could be:
get title() {
const {head} = this;
return head.getElementsByTagName('title').at(0)?.textContent || '';
}
esm/html/document.js
Outdated
@@ -77,8 +77,7 @@ export class HTMLDocument extends Document { | |||
*/ | |||
get title() { | |||
const {head} = this; | |||
let title = head.getElementsByTagName('title')[0]; | |||
return title ? title.textContent : ''; | |||
return head.getElementsByTagName('title')[0]?.textContent || ''; |
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.
.at(0)
... not [0]
... [0]
bails out performance if no title
exists, .at(0)
doesn't suffer this issue.
ec40b5d
to
ad2ae02
Compare
Thanks! It's up and running. If you had an issue please be sure that gets closed too 👋 |
Minimal reproducible example with linkedom 0.16.10: