Skip to content

direct CSS imports in TypeScript no longer work #9532

Closed

Description

@vlukashov

Simpler CSS imports added for Fusion in #8843 no longer work in Flow 6.0.0.alpha1:

import styles from './list-view.css';

@customElement('list-view')
export class ListView extends LitElement {
  static styles = [Lumo, styles];
  ...
}

leads to the following error in the browser console Uncaught TypeError: Failed to set the 'adoptedStyleSheets' property on 'ShadowRoot': Failed to convert value to 'CSSStyleSheet'.

Steps to reproduce:

  1. download a TS + HTML project from start.vaadin.com
  2. override the version of Vaadin to 19.0-SNAPSHOT
  3. change the way how hello-world-view defines styles: import them form hello-world-view.css instead of defining inline:
import styles from './hello-world-view.css';
@customElement('hello-world-view')
export class HelloWorldView extends LitElement {
  static styles = [styles];
  ...
  1. delete the types.d file (so that Vaadin regenerates it)
  2. start the app in the dev mode and open the default route
  3. see the blank page and an error in the browser console

Expected behavior:

Implementation notes:
This was probably accidentally broken while working on the application theme epic.

Workaround:
Add the following to the webpack.config.js file (after const flowDefaults = require('./webpack.generated.js'); and before the module.exports = merge(flowDefaults, lines):

flowDefaults.module.rules.filter(rule => rule.test.test('.css')).forEach(rule => {
  rule.use = ['lit-css-loader', 'extract-loader', 'css-loader'];
});

Activity

  1. self-assigned this
    on Nov 30, 2020
  2. caalador commented on Dec 1, 2020

    @caalador
    Contributor

    adding the lit-css-loadr and extract-loader fixes the issue, but the sample styling doesn't seem to actually style anything.
    Even with editing v18 to use this kind of styling doesn't actually apply the style to the element.

    Is there a functional example on how this works as we can now only test that no exception was thrown but that the styling is not there.

  3. vlukashov commented on Dec 1, 2020

    @vlukashov
    Author

    Here is a sample V19 project with the workaround applied in webpack.config.js: css-imports-demo.zip.

    With the workaround the app looks like this (using styles from hello-world-view.css):
    image
    Without the workaround it looks like this:
    image

  4. caalador commented on Dec 1, 2020

    @caalador
    Contributor

    So the generated css targets from start.vaadin.com are faulty?

  5. vlukashov commented on Dec 1, 2020

    @vlukashov
    Author

    So the generated css targets from start.vaadin.com are faulty?

    It looks like the project generated by start.vaadin.com includes the hello-world-view.css file, but does not use it in any way. The styles for the hello-world-view web component in the generated project are provided inline rather than being included from a .css file.

    The attached project differs from the generated in that it includes the styles form a file (not inline), and the contents of the hello-world-view.css file are also changed to make styling very visible.

  6. added a commit that references this issue on Dec 1, 2020
    1cb83cd
  7. added a commit that references this issue on Dec 2, 2020
    ae47abc
  8. added a commit that references this issue on Dec 7, 2020
    5e915fc
  9. added a commit that references this issue on Dec 16, 2020
    8c75d58
  10. added this to the Custom Theme Feature milestone on Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions