-
-
Notifications
You must be signed in to change notification settings - Fork 424
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
Handle the existing title case by using element instead of value (children) #315
Conversation
… is not provided and titleProps is set to true
children Instead of return the children of title from conditional expression, we can return the title element itself e.g. if title is undefined then retun the existing title else return <title>{title}</title> fixes #314
This pull request is automatically deployed with Now. |
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 the update, can you avoid using forEach
in tests, it is kind of messy. I would rather prefer just isolated if with duplication. Is it OK for you?
Yes. I realised the same. Test should be testable while reading :). Will update them. |
@neoziro I updated the tests. There is one more thing I want to do here. I want to preserve the attributes of the existing title. I just need to update the - function createTitle (children = []) {
+ function createTitle (children = [], attributes = [])
return t.jsxElement(
- t.jsxOpeningElement(t.jsxIdentifier('title')),
+ t.jsxOpeningElement(t.jsxIdentifier('title'), attributes),
t.jsxClosingElement(t.jsxIdentifier('title')),
children,
)
} And in the - function getTitleElement(existingTitleChlidren) {
+ function getTitleElement(existingTitle) {
const titleExpression = t.identifier('title')
let titleElement = createTitle(
[t.jsxExpressionContainer(titleExpression)],
+ existingTitle ? existingTitle.openingElement.attributes : [],
)
- if (existingTitleChildren && existingTitleChildren.length)
+ if (existingTitle && existingTitle.children && existingTitle.children.length) {
- const fallbackTitleElement = createTitle(existingTitle.children)
+ const fallbackTitleElement = existingTitle And in our loop over - titleElement = getTitleElement(childPath.node.children)
+ titleElement = getTitleElement(childPath.node)
|
Codecov Report
@@ Coverage Diff @@
## master #315 +/- ##
==========================================
+ Coverage 86.58% 86.63% +0.05%
==========================================
Files 30 30
Lines 477 479 +2
Branches 135 134 -1
==========================================
+ Hits 413 415 +2
Misses 53 53
Partials 11 11
Continue to review full report at Codecov.
|
1 similar comment
Codecov Report
@@ Coverage Diff @@
## master #315 +/- ##
==========================================
+ Coverage 86.58% 86.63% +0.05%
==========================================
Files 30 30
Lines 477 479 +2
Branches 135 134 -1
==========================================
+ Hits 413 415 +2
Misses 53 53
Partials 11 11
Continue to review full report at Codecov.
|
It looks good to me. I merge it. |
Hi @neoziro . Any updates on release that includes this PR ? |
Sorry I have just published it! |
Summary
Fixes #314 titleProps=true not working as expected for existing title
We need to handle existing
title
element's children with a different strategy. Instead of looping through children and creating a children, we can instead, use all the children and push them into a title element. And from the conditional statement for fallback title, instead of returning a title children, we return the title.Test plan
I have updated the test case for the same with different type of existing title elements.