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
[RFC] fix #4055, generate style on custom component, Don't Merge #4076
Conversation
Can we add an accompanying test case in |
I'm adding tests. But this fix seems to have some problems. Still under investigation. |
There is still a problem left. Code like this {
template: '<section><comp :style="style"></comp></section>',
data: {
style: 'color:red'
},
components: {
comp: {
template: '<div></div>'
}
}
} Will produce code like this Style is lost. This is because the inner template element |
} | ||
}, result => { | ||
expect(result).toContain( | ||
'<div server-rendered="true" style="color:red"></div>' |
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.
<comp>
has a synthetic server-rendered
attrs so it has the chance to execute module logic...
|
||
// construct synthetic data for module processing | ||
// because modules like style also produce code by parent VNode data | ||
if (!node.data && hasAncestorData(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.
Add a synthetic data property if VNode's ancestor has data. I don't this is good enough...
Merge conflict resolved. My concern is the |
Yeah, I think setting empty data object is fine. It seems the style-generating code is only checking the direct parent node, where it's possible to have multi-nested components (A renders B, B renders C...), so we need to do a parent walk loop ( |
}) | ||
}) | ||
|
||
it('nested custom component style', done => { |
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.
@yyx990803 By "multi-nested components", do you mean this?
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.
Ah I see, the generateStyleText
call is recursive, nice.
I think this looks good. If the |
FYI attrs/domProps modules are fixed for similar situations in e5f23d9 |
The fix is discussed in #4055. I think
attrs
module should also have this fix.