medusa-ui/medusa

Conditional makes it so that the wrong xpath can be provided

kevindeyne opened this issue · 2 comments

Our xpath refers to things as 'the fifth span in the third div' but that could change if you introduce ifs. Perhaps we need to enforce order here or we need a better way than XPath to refer to unique parts of the UI.

Example seen:

                <section>
                    Your name: <span th:if="${conditionalValue}">Conditional Value</span> <br/>
                    SCORE: <span th:text="${valueThatChanges1}">100</span>/<span th:text="${valueThatChanges2}">100</span>
                </section>

Confirmed bug in conditional page in branch rewrite-1.0.0-cond_wrong_xpath.

The example page contains a lot of conditional tags, and they get rendered and rerendered correctly. The problem seems to occur only if conditional are used in nested tags?
Here the score is shown twice, only after you first entered a value greater then 17710 (max number is specific for this example)
and then entered a valid number.

    <div>
        <p th:if="${!#lists.contains(fibo,0)}">You score is<span th:text="${#lists.size(fibo)}">0</span></p>
        <p th:if="${#lists.contains(fibo,0)}">You failed!</p>
    </div>

But the bug is hard to reproduce....
Tried to simplify the example but this works fine?

  public List<Attribute> toggleShow() {
        show = !show;
        String message =  show ? "now, you see me" : "now you don't";
        return List.of(
                new Attribute("message", message),
                new Attribute("show", show)
        );
    }
<div>
    <p th:if="${!show}"> <span>Nothing</span> </p>
    <p th:if="${show}"> <span th:text="${message}">Something</span></p>
    <button m:click="toggleShow()">Toggle show</button>
</div>

some debug info...

JSReadyDiff{content='<p>You score is<span>7</span></p>', xpath='/html[1]/body[1]/div[3]/p[1]', type=EDIT}
JSReadyDiff{content='<span>7</span>', xpath='/html[1]/body[1]/div[3]/p[1]/::first', type=ADDITION}

<span>7</span> is marked as ADDITION, but was already marked as EDIT in de p-tag