-
Notifications
You must be signed in to change notification settings - Fork 176
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
V 14.2.0: Component with styles exposed via WebComponentExporter #8543
Comments
Hello @darmro , thank you for ticket! Could you please re-upload the |
Could this be related to #5363? A fix for style scoping was included in 14.2. This looks like the fix: #7074 |
Hi, I've changed the zip in the conntent of this issue. Previous file was packed as rar (sorry :) New one is standard zip. |
I'm not able to reproduce this with Unfortunately the example in the ticket contains a lot of extra info:
Below the steps to reproduce without all extra unrelated info:
The same steps with the
|
OK, now I see the same behavior in |
But it seems this is not related to embedding in fact. What happens here:
the |
Ah , sorry. |
So in fact it works as designed. See Jouni comment about this : #8543 (comment). To be able to style the web component you may use style directly in the web component:
or do the same thing as you did in I will check the documentation about embedded components. It might be that we forgot to update it. |
Thank you Denis for your investigation. In fact I expected such an answer (I've read before that you're plannig changes how styles and modules are applied) but for me this is bad news :/ |
Sorry, but I was wrong. Just adding to a widget (web component created by WebComponentExporter) each style module (via |
Right. But embedding makes a web component wrapper. Well, we have no other way to deal with this at the moment. |
I've made a ticket in docs how to style the embedded component : https://github.com/vaadin/flow-and-components-documentation/issues/1300 For now the easiest way I see is: make you own web component (which will be wrapped into a generated web component). |
Thank you Denis. I realize that you are not going to change the behavior back- to be honest I was sure you would say that :) But this means that using |
Denis, what did you mean by:
I've changed |
No. So the only way to style the embedded component is to wrap it into a web component with its own styles. Or set styles inline (hardcode via Element API |
So, in the end:
I'm closing this one since as I said: the behavior is expected. |
Conceptually, this is what should be done. The exported component should “inherit” all the styles, which would normally be in the global style scope, to its local style scope. |
Oh, didn’t notice Denis’s later comments. I don’t agree that this works as intended/expected. Maybe it was technically designed to work like this, but I don’t think there’s justification why it should work like this. Good that you created #8564 To clarify: we will most likely need better support for this for design system documentation needs, when customers have done theme customizations for components. The Java component examples in the documentation are done using Flow embedding. |
Well, shadow root has been added to the generated wrapper by design. There is no any justification that it should work in any other way in fact. I also don't agree with the fact that global styles should be applied to the exported web component. Embedded web component is a different world which is embedded to some universe. But: I'm not an expert in this area. There was no exact requirements for this all all our judgment is done on our personal preference. If you think this is a bug then we can close #8564 since the current ticket makes it useless. |
Yes, that’s indeed the correct way to do it, and for that the justification is sound, that the component should be isolated from the parent page. That wasn’t the thing I was arguing against 😄 With “global styles” I was referring to the styles that are applied in Flow using html {
--lumo-primary-color: red;
} I would want that to be applied in the exported component as well. I don’t know how that should be done, if the developer needs to explicitly do something else in addition to having a |
Now, after writing the above example, I realize that doesn’t really make sense, as the embedded component won’t have any The |
I know, and I apologize if I came off as accusatory. My intention was not to shame or point fingers. Just point out that I think we should still work on making this better 🤗 |
it's fine. |
I don'w want to complain but for me it is a very big problem :| As I said I have many java components (not web components / polymer components), which extends Div or Composite. Each one has its own styling in js file (mainly margins, paddings, flex attributes, size, sometimes colors or font properties). They are simple and primitive but I use them as lego bricks and put them in many other layouts, divs etc. In Flow app everything is nice and works. But when such layout (coponent) which contains these simple java components (with their own styling) I have to expose to be embedded somewhere else (WebComponentExporter was perfect for that) then it seems impossible (or very difficult or in rather ugly way). I think my scenario is rather common and it turns out that WebComponentExporter is not very usefull to generate embeddable web components :| |
There is a ticket about this: #8564 |
Thank You denis and jouni. I am looking forward to any improvements :) For now I have to stay on V 14.1.28. |
Part of vaadin/flow#8543 Co-authored-by: Johannes Eriksson <joheriks@vaadin.com>
Description of the bug
I have a component (simple div) annotated by
@CssImport
or@JsModule
(contains styles for the component). I'm embedding it in another page as exposed web component via WebComponentExporter.In V 14.1.x (till 14.1.28) everything was fine, styles was applied when component was embedded.
The same in V 14.2.0 stoped working ie the component doesn't see any of its styles.
The same component added to MainView (so not as a embedded component) of course looks fine (styles are applied). They are not applied only when component is embedded via WebComponentExporter.
Minimal reproducible example
@JsModule
. I just set a background of div (LoginForm) to red.Run it (/example)
![image](https://user-images.githubusercontent.com/56316289/84293117-a35c8a00-ab47-11ea-8560-d4e9729a2bef.png)
For V 14.1.28 the result:
And for V 14.2.0 the result:
![image](https://user-images.githubusercontent.com/56316289/84293029-8758e880-ab47-11ea-9a5b-e1bd35966400.png)
The code (project)
starter-spring-war.zip
Expected behavior
Styles should be applied to the embedded component in V 14.2.0 as they were in V 14.1.28.
Summary
I'm not sure whether it's a bug. However everything was ok in V 14.1.x. Maybe I should add styles to the embedded component in some other way, but the documentation (link above) says nothing about it.
The text was updated successfully, but these errors were encountered: