question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Firefox] Attributes are reassigned if used in styles

See original GitHub issue

If using the attribute values in the style tag, the values of attributes are reassigned between each other. I created a simple demo: Stackblitz Demo

In the demo the relevant code looks like:

_render({top, left, animal, whales}) {
    return html`
      <style>
        :host {
          display: block;
          position:absolute;
          top: ${top}px;
          left: ${left}px;
        }
      </style>
      <h4>Type: ${animal}</h4>
      <div>Whales: ${'🐳'.repeat(whales)}</div>
      <p>Top: ${top}, Left: ${left}</p>
      <slot></slot>
    `;
  }

In Chrome it works but in Firefox animal and top, and whales and left will have changed values with each other. Removing top and left from style declaration makes the issue go away.

firefox_bug

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:9

github_iconTop GitHub Comments

2reactions
valdrinkoshicommented, May 24, 2018

Modifying the content of a stylesheet is bad practice, because that invalidates all the styles of that stylesheet, potentially causing unnecessary layout/paint. The most efficient way would be to use css custom properties as suggested in https://github.com/Polymer/lit-element/issues/74#issuecomment-391368188

2reactions
eskancommented, May 23, 2018

Hi, this look more a lit-html issue but i’m not sure you can use expression inside <style>, template are a dom hack to substitute values in places. To achieve this you need to use inline style

style$=${`top: ${top}; left: ${left};`}

you can also use css custom properties

:host {
          display: block;
          position:absolute;
          --my-top: 100px;
          --my-left: 300px;
          top: var(--my-top);
          left: var(--my-left);
        }

and this.style.setProperty('--my-top','400px');

Read more comments on GitHub >

github_iconTop Results From Across the Web

Examine and edit CSS — Firefox Source Docs documentation
It represents the CSS properties assigned to the element via its style attribute. , giving you a convenient way to highlight the currently...
Read more >
HTMLElement.style - Web APIs | MDN
The style read-only property returns the inline style of an element in the form of a CSSStyleDeclaration object that contains a list of...
Read more >
256630 - [firefox only] style attribute doesn't show up in style rules view
People. (Reporter: dbaron, Assigned: dbaron) ... I don't see how the style attribute can be used "to help webpages attack the user's computer"....
Read more >
Poor style calculation performance for attribute selectors ...
Click "Force style recalc". Actual results: The duration of style/layout/render as measured by the benchmark is ~190ms on my MacBook Pro running Firefox...
Read more >
C++ Coding style — Firefox Source Docs documentation
This document attempts to explain the basic styles and patterns used in the Mozilla codebase. New code should try to conform to these...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found