Skip to content
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

Incorrect return value of getPropertyValue for nested custom properties without fallback value #1363

Closed
odanado opened this issue Mar 25, 2024 · 0 comments · Fixed by #1381
Closed
Labels
bug Something isn't working

Comments

@odanado
Copy link
Contributor

odanado commented Mar 25, 2024

Describe the bug
An incorrect return value of getPropertyValue for nested custom properties without fallback value.

import { Window } from "happy-dom";

const window = new Window({ url: "https://localhost:8080" });

const div = window.document.createElement("div");

const style = window.document.createElement("style");

style.textContent = `
  div {
    --my-color1: pink;
    --my-color2: red;

    border-color: var(--my-color1);

    color: var(--my-color1, var(--my-color2, blue));

    background-color: var(--my-color1, var(--my-color2));
  }
`;

window.document.head.appendChild(style);
window.document.body.appendChild(div);

// OK: expected: pink, actual: pink
console.log(window.getComputedStyle(div).getPropertyValue("border-color"));

// with fallback value
// OK: expected: pink, actual: pink
console.log(window.getComputedStyle(div).getPropertyValue("color"));

// without fallback value
// NG: expected: red, actual: "" (empty string)
console.log(window.getComputedStyle(div).getPropertyValue("background-color"));

To Reproduce
Steps to reproduce the behavior:

  1. Run git clone https://github.com/odan-sandbox/happy-dom-getComputedStyle-with-css-variables-sandbox
  2. Run npm ci
  3. Run node src/repro-non-fallback.js

Expected behavior
--my-color1 is defined, so the background-color should be pink.

Device:

  • Node.js: v18.12.1
  • happy-dom: 14.3.6
@odanado odanado added the bug Something isn't working label Mar 25, 2024
odanado added a commit to odanado/happy-dom that referenced this issue Apr 4, 2024
odanado added a commit to odanado/happy-dom that referenced this issue Apr 4, 2024
odanado added a commit to odanado/happy-dom that referenced this issue Apr 5, 2024
odanado added a commit to odanado/happy-dom that referenced this issue Apr 5, 2024
capricorn86 added a commit to odanado/happy-dom that referenced this issue Apr 5, 2024
capricorn86 added a commit that referenced this issue Apr 5, 2024
fix: [#1363] Fix bug with missing fallback value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant