Skip to content

Text color is not updated when a class is toggled #7814

Closed

Description

@paulrouget
<style>
  span {
    font-size: 30px;
    color: red;
  }

  span.selected {
    color: green;
  }
</style>

<body>
  <span class='selected'>A</span>
  <span>B</span>
  <span>C</span>
  <span>D</span>
  <pre></pre>
</body>

<script>
  var i = 0;
  setInterval(() => {
    document.querySelector('.selected').classList.remove('selected');
    var span = document.querySelectorAll('span')[i];
    span.classList.add('selected');
    document.querySelector('pre').textContent = span.textContent;
    i = (i + 1) % 4;
  }, 500);
</script>

In Firefox, text color changes from green to red. In Servo, nothing happen.

Activity

  1. jdm commented on Oct 1, 2015

    @jdm
    Member

    Out of curiosity, does it update if you resize the window or move the mouse over the text?

  2. paulrouget commented on Oct 1, 2015

    @paulrouget
    ContributorAuthor

    If I do something like :hover{font-size: something}, it updates the color.

  3. jdm commented on Oct 1, 2015

    @jdm
    Member

    I suspect this occurs because modifying the class attribute through the DOMSettableToken list doesn't end up marking the node as dirty. Modifying the class attribute directly goes through this path instead, which would mark it dirty.

  4. added
    A-content/dom
    on Oct 1, 2015
  5. jdm commented on Oct 1, 2015

    @jdm
    Member

    I suspect the DOMSettableToken methods that mutate attributes should explicitly mark the relevant element as dirty.

  6. self-assigned this
    on Oct 1, 2015
  7. Ms2ger commented on Oct 1, 2015

    @Ms2ger
    Contributor

    That makes no sense. The attribute changing code should handle this; there's even code in Element::attribute_mutated that should.

  8. mbrubeck commented on Oct 1, 2015

    @mbrubeck
    Contributor

    Yes, I verified that the node is correctly marked dirty. Also, changing to use .setAttribute("class", ...) or .className = ... does not fix the behavior. The behavior depends on which style property is changed. color and background don't work, but font-size does. Maybe the problem is that we're not triggering the correct sort of incremental layout, or the incremental layout logic is buggy for these properties.

  9. added
    I-wrong
    and removed
    A-content/dom
    on Oct 1, 2015
  10. mbrubeck commented on Oct 1, 2015

    @mbrubeck
    Contributor

    Debugging shows that style recalc runs as expected, and repair_if_possible is called, and correctly repairs the text fragments, but the display list still ends up with the old colors for some reason.

    background-color updates correctly on block elements, but not on inline elements. Maybe this is related to Flow::repair_style which is a no-op for InlineFlow.

    Disabling incremental layout makes the test case work correctly.

  11. mbrubeck commented on Oct 1, 2015

    @mbrubeck
    Contributor

    The problem is that repair_if_possible repairs the original UnscannedText fragments from the node's ConstructionResult, rather than the InlineFlow and its ScannedText fragments.

    I think this case should just return false; because we can't repair the correct fragment(s) here.

  12. added 2 commits that reference this issue on Oct 1, 2015
    59029be
    6426f71
  13. added 2 commits that reference this issue on Oct 1, 2015
    bad3f04
    69db834
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-layout/uncategorizedI-wrong

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions