Skip to content

Shadow Root with inline style fails to fetch cssom #4137

@EduSantosBrito

Description

@EduSantosBrito

Product

axe-core

Product Version

4.7.2

Latest Version

  • I have tested the issue with the latest version of the product

Issue Description

Expectation

No errors when testing Lit components

Actual

When I have inline style on my shadowroot, it triggers an error
CleanShot 2023-08-25 at 13 42 44
Removing the inline style, it will not trigger an error.
CleanShot 2023-08-25 at 13 43 37

How to Reproduce

Create a simple Lit component

import { LitElement, css, html } from "lit";
import { customElement, property } from "lit/decorators.js";

@customElement("primitive-accordion")
export class PrimitiveAccordion extends LitElement {
  static styles = css`
    :host {
      color: blue;
    }
  `;

  @property({ reflect: true })
  name: string;

  constructor() {
    super();
    this.name = "World";
  }

  // Render the UI as a function of component state
  render() {
    return html`<div>
      <h1>Hello, ${this.name}!</h1>
    </div>`;
  }
}

declare global {
  interface HTMLElementTagNameMap {
    "primitive-accordion": PrimitiveAccordion;
  }
}

And run this simple test

import { afterEach, beforeEach, describe, it } from "vitest";
import "../lib/accordion";
import { expect, fixture, html } from "@open-wc/testing";

describe("given a single accordion", async () => {
  let root: HTMLDivElement;

  beforeEach(() => {
    root = document.createElement("div");
    document.body.appendChild(root);
  });

  afterEach(() => {
    root?.remove();
  });

  it("should have no accessibility violations in default state", async () => {
    const el = await fixture(
      html` <primitive-accordion name="Testing"></primitive-accordion> `
    );
    console.log(el.shadowRoot?.innerHTML);
    await expect(el).to.be.accessible();
  });
});

Additional context

The error is originated on the function getStylesheetsFromDocumentFragment inside the file preload-cssom.js. The function convertDataToStylesheet will return null on stylesheet.sheet. Checking the value of stylesheet.sheet should fix the issue. I'm creating a PR for that fix right now :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    ungroomedTicket needs a maintainer to prioritize and label

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions