-
Notifications
You must be signed in to change notification settings - Fork 247
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: don't generate title tag if title is empty #334
Conversation
Codecov Report
@@ Coverage Diff @@
## master #334 +/- ##
=======================================
Coverage 40.89% 40.89%
=======================================
Files 19 19
Lines 269 269
=======================================
Hits 110 110
Misses 159 159
Continue to review full report at Codecov.
|
@@ -11,7 +11,7 @@ export default function _titleGenerator (options = {}) { | |||
return function titleGenerator (type, data) { | |||
return { | |||
text () { | |||
return `<${type} ${attribute}="true">${data}</${type}>` | |||
return data ? `<${type} ${attribute}="true">${data}</${type}>` : '' |
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 wouldn't think of this behavior normally (when using vue-meta in context of a typical SPA and not going for microfrontends or similar). Please add at least a comment there
Also, maybe checking for undefined
instead of using all falsy values might make sense? 🤔
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 changed the checking to String(data)
for keeping it same behaviour as document.title=....
document.title = undefined // <title>undefined</title>
document.title = null // <title>null</title>
document.title = false // <title>false</title>
document.title = 0 // <title>0</title>
document.title = '' // <title> tag will be removed
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.
It makes sense to be in line with document.title
here but I'm not sure if being in line with the vue-meta
-own conventions might be more important (though that will only be relevant for v2)
If that PR gets merged, we have to port it to the |
I am ok with this as html5 spec says the title element is required unless its reasonable not to. Also chrome/firefox behave the same when title doesnt exists as when its an empty string. Even though you could also argue this issue should be fixed in Nuxt, because vue-meta already provides the option to ignore the title on ssr by simply not calling |
@pimlie I fixed this issue in |
@clarkdo the other options would be to either pass an argument to Strictly speaking (as in according to the spec) the title element could not only be not printed on empty string but also when it only contains inter-element white space. So |
Ready to merge for minor, I let you handle it @pimlie when you feel ready for it :) |
Fix nuxt/nuxt#5281