Coder Social home page Coder Social logo

Comments (13)

asyncLiz avatar asyncLiz commented on September 26, 2024 2

Looks like my only comments on it were documentation, I can merge and tweak those manually.

from origami.

asyncLiz avatar asyncLiz commented on September 26, 2024

Seems like the component factory is not available when I'm scanning for it. A quick workaround is to add the components using @IncludeStyles to the entryComponents of their module.

That fixes for JIT compilation, but neither component has the styling with AOT compilation. I'm going to have to dig into that one further. Not sure if that's an existing bug, or something with the newer versions of Angular.

from origami.

asyncLiz avatar asyncLiz commented on September 26, 2024

I've got a fix for AOT not working, but we come back to the problem of the component factory.

We could document and require that any component using @IncludeStyles needs to be added to the entryComponents. Not a huge fan of that though, since it'll get annoying with many components and it adds extra overhead in creating factories that aren't needed.

We really just need to associate an HTML selector string with one or more Polymer style modules. The only reason I'm using a decorator and component factory is so that it improves the developer experience. There's no reason we can't do something like this:

IncludeStyles.for('app-child')('app-colors');

@Component({
  selector: 'app-child'
})
export class ChildComponent {}

It feels "side effect"-y to me, but it'd solve the problem and could get rid of a lot of code that is trying to dynamically look up the selector provided to @Component.

Using a decorator "feels" much better, but I can't think of a clever way to link a class's type to it's component metadata without the component factory.

If you have any suggestions, I would appreciate it!

from origami.

akaegi avatar akaegi commented on September 26, 2024

Thank you for your time and inputs! I digged further into the issue and it turned out it is a different issue.
I created another demo at https://github.com/akaegi/include-styles-demo2 to illustrate it.

I use vaadin components so I'm not yet sure if the problem might be on their side...
I use a custom-style to include 'lumo-color' and 'lumo-typography' as global style. In combination with using vaadin-tabs this removes the style element from the 'lumo-color' dom-module. (See screenshots). This is ShadyCSS code but seems to be ok?
As a consequence, the @IncludeStyles has the effect of adding an empty style element to my Angular component when using it for 'lumo-color'.

Is the solution that you have to apply some ShadyCSS functions from within your @IncludeStylescode? (The style is still there in the dom-module element but "hidden" within the _styles field).

Hope that explanation is not too confusing...

Note that when the global style-include for 'lumo-color' is deactivated (app.component.ts line 10), then the dom-module style is not "erased" and the @IncludeStyles works as expected)

image

image

from origami.

asyncLiz avatar asyncLiz commented on September 26, 2024

Good find! Looks like cssFromTemplate() does remove the style node from the DomModule element. That makes sense, since we don't want those styles leaking in legacy browsers.

I could change IncludeStyles to use cssFromModules() to get the CSS string instead of manually querying it.

from origami.

akaegi avatar akaegi commented on September 26, 2024

That looks right to me on first sight (but I am a real novice what concerns Polymer and ShadyCSS).
Do you have to handle the case when ShadyCSS is not available?

from origami.

asyncLiz avatar asyncLiz commented on September 26, 2024

ShadyCSS doesn't touch Polymer style modules, so there's no step there I have to worry about. Origami already checks and adds stylesheets to ShadyCSS in another module. All IncludeStyles does is add the string to the component styles, which would get passed through ShadyCSS later.

from origami.

akaegi avatar akaegi commented on September 26, 2024

Seems to work fine :-)
Changed "style retrieval" in patchedRendererFactory to:

const styleModules = getStyleModulesFor(getTypeFor(selector));
      let styles = styleModules.map(styleModule => {
        const styleElements = stylesFromModule(styleModule);
        return styleElements.map(e => e.innerText).join('\n');
      });

where stylesFromModule is imported from '@polymer/polymer/lib/utils/style-gather.js.
(cssFromModules is deprecated).

Shall I issue a PR?

from origami.

asyncLiz avatar asyncLiz commented on September 26, 2024

Sure! PRs are always welcome. If we don't use importStyleModule() anymore, we'll want to add @deprecated warnings to it so that it can be removed in the next major version

from origami.

asyncLiz avatar asyncLiz commented on September 26, 2024

AOT fix is pushed out and will be published shortly, but I'm leaving this open for the other problem

from origami.

akaegi avatar akaegi commented on September 26, 2024

For the style-related issue I issued a PR some time ago. Did you have the chance to look at it so that it can possibly be merged?

from origami.

akaegi avatar akaegi commented on September 26, 2024

I'm not sure why this issue is still open. My PR was merged a long time ago (#90)...

from origami.

asyncLiz avatar asyncLiz commented on September 26, 2024

I left this open for some reason, but I can't think of it now!

from origami.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.