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

regression: VNode.dom is nil #117

Open
timotheecour opened this issue Sep 13, 2019 · 1 comment
Open

regression: VNode.dom is nil #117

timotheecour opened this issue Sep 13, 2019 · 1 comment

Comments

@timotheecour
Copy link
Collaborator

timotheecour commented Sep 13, 2019

/cc @Araq after e422087 (avoid exponential DOM diffing) the following minimal example fails
before that it was working.

example 1

import karax / [kbase, vdom, kdom, vstyles, karax, karaxdsl]

proc myonscroll(ev: Event; n: VNode) =
  doAssert n.dom != nil # fails after e422087

proc myonload() =
  document.querySelectorAll(".scrollableArea")[0].style.height = "300px"

proc createDom(): VNode =
  result = buildHtml(tdiv):
    tdiv(class = kstring"scrollableArea", onscroll = myonscroll, style = {StyleAttr.overflow: kstring"scroll"}):
      img(src = "https://d17fnq9dkz9hgj.cloudfront.net/breed-uploads/2018/09/dog-landing-hero-lg.jpg", onload = myonload)

setRenderer createDom, "ROOT"

after

karun -r $timn_D/tests/nim/all/t0736.nim

upon scrolling you'll get (in chrome console):

t0736.js:1129 Uncaught Error: Error: unhandled exception: /Users/timothee/git_clone/nim/timn/tests/nim/all/t0736.nim(14, 12) `n.dom != nil`  [AssertionError]
Traceback (most recent call last)
karax.nim:89 stdWrapper.:anonymous
karax.nim:708 addEventHandler.wrapper
t0736.nim:14 t0736.myonscroll
assertions.nim:41 assertions.failedAssertImpl
assertions.nim:20 assertions.raiseAssert
fatal.nim:39 sysFatal.sysFatal

note:

example 2 (related but different)

we get null after that commit e422087 when calling from chrome console

  include karax / prelude
  proc callback_getVNodeById(id: kstring): VNode {.exportc.} =
    getVNodeById(id) # null after e422087 when called from console

  proc myonload(ev: Event; n: VNode) =
    echo n.dom == nil
    echo getVNodeById(kstring"elementsArea").dom == nil # prints false both before and after e422087

  proc createDom*(): VNode =
    result = buildHtml(tdiv):
      tdiv(id = "elementsArea"):
        img(src = kstring"https://image.shutterstock.com/image-vector/dog-head-icon-flat-style-260nw-1126157240.jpg", onload=myonload)

  setRenderer createDom, "ROOT"
callback_getVNodeById('elementsArea').dom
# after e422087
null
# before e422087
<div id="elementsArea"><img src="https://image.shutterstock.com/image-vector/dog-head-icon-flat-style-260nw-1126157240.jpg"></div>
@timotheecour
Copy link
Collaborator Author

timotheecour commented Sep 18, 2019

workaround for example 1

n.dom
=>
ev.currentTarget # or v.target

see https://developer.mozilla.org/en-US/docs/Web/API/Event/currentTarget for more details on these

workaround for example 2

callback_getVNodeById('elementsArea').dom
=>
document.getElementById("elementsArea")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants