Code Monkey home page Code Monkey logo

Comments (1)

timotheecour avatar timotheecour commented on May 13, 2024

just ran into this and was puzzled by the results; this is a serious bug...
I verified it's still there on master

here's a reduced case:

  include karax / prelude
  import sugar
  var page = 2
  proc createDom(): VNode = buildHtml(tdiv):
    if page == 3:
      tdiv: text "Some text v3"
    # else: tdiv: text "Some text v2" # uncomment would remove bug
    button(onclick=() => (echo "click 2"; page = 2)): text "2"
    button(onclick=() => (echo "click 3"; page = 3)): text "3"
    tdiv: text "Some text2: " & $page # removing `& $page` would remove bug
  setRenderer createDom

click 3, then click 2: it should print:

click 3
click 2

but prints:

click 3
click 3

looks like dom diffing gets confused by the conditional inclusion of the node tdiv: text "Some text v3"

EDIT

just checked, this is actually a recent regression caused by e422087 /cc @Araq

  • works in d08a035, both this example and the one in top post, so this bug had actually been fixed until it got broken again
  • fails in e422087 avoid exponential DOM diffing
    (although e422087 did help for another bug, as i had mentioned here e422087#commitcomment-35065660)

EDIT:

  • adding let recursive=true right below proc eq(a, b: VNode; recursive: bool): EqResult = makes the bug go away; but that probably is bad for performance (maybe exponential complexity)
  • attaching a (unique) id on each button makes the bug go away; obviously this isn't desirable but could help debugging that issue; maybe what's going on is:
    inside karax.eq, when recursive=false, button 2 and button 3 might get confused; the even listeners are not compared (see # Do not test event listeners here!); not sure how to compare them though, the naive way would likely just always return "different" even if comparing the same nodes
  include karax / prelude
  import sugar
  var page = 2
  proc createDom(): VNode = buildHtml(tdiv):
    if page == 3:
      tdiv: text "Some text v3"
    # else: tdiv: text "Some text v2" # uncomment would remove bug
    button(id = "id1", onclick=() => (echo "click 2"; page = 2)): text "2"
    button(id = "id2", onclick=() => (echo "click 3"; page = 3)): text "3"
    tdiv: text "Some text2: " & $page # removing `& $page` would remove bug
  setRenderer createDom

from karax.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.