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

The value of getPropertyValue is wrong when using style attributes and custom properties #1364

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

Comments

@odanado
Copy link
Contributor

odanado commented Mar 25, 2024

Describe the bug
The value of getPropertyValue is wrong when using style attributes and custom properties.

import { Window } from "happy-dom";

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

const div = window.document.createElement("div");
div.setAttribute("style", "--my-color1: pink;");

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

style.textContent = `
  div {
    border-color: var(--my-color1);
  }
`;

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

// OK: expected: pink, actual: "" (empty string)
console.log(window.getComputedStyle(div).getPropertyValue("border-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
@capricorn86 capricorn86 self-assigned this Mar 26, 2024
capricorn86 added a commit that referenced this issue Mar 27, 2024
@capricorn86 capricorn86 linked a pull request Mar 27, 2024 that will close this issue
capricorn86 added a commit that referenced this issue Apr 1, 2024
capricorn86 added a commit that referenced this issue Apr 1, 2024
…tyvalue-is-wrong-when-using-style-attributes-and-custom-properties

fix: [#1364] Fixes problem with CSS variable declaration
@capricorn86
Copy link
Owner

Thank you for reporting @odanado! 🙂

There is a fix in now:
https://github.com/capricorn86/happy-dom/releases/tag/v14.3.10

@odanado
Copy link
Contributor Author

odanado commented Apr 4, 2024

Thank you!

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.

2 participants