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

[low priority] give more informative error msg when reusing dthunk #123

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

Comments

@timotheecour
Copy link
Collaborator

timotheecour commented Sep 30, 2019

D20190929T173159
reduced example:

import karax / [kbase, vdom, kdom, karax, karaxdsl]
import js/jsffi

var elem = document.createTextNode("hello world")

proc foo(): VNode =
  result = buildHtml(tdiv):
    dthunk(elem)

proc createDom(): VNode =
  result = buildHtml(tdiv):
    foo()
    foo()

when isMainModule:
  setRenderer createDom, "ROOT"

gives:
Uncaught Error: Error: unhandled exception: /Users/timothee/git_clone/nim/karax/karax/karax.nim(649, 12) same(kxi.currentTree, document.getElementById(kxi.rootId)) [AssertionError]

(same error as #86 but seems unrelated)

@timotheecour
Copy link
Collaborator Author

timotheecour commented Sep 30, 2019

EDIT:
cloneNode is needed to insert same DOM Node twice, see https://stackoverflow.com/questions/20203143/how-to-insert-the-same-html-element-twice

  # workaround
  import karax / [kbase, vdom, kdom, karax, karaxdsl]
  import js/jsffi

  var elem = document.createTextNode("hello world")
  let elem2 = elem.cloneNode(false)

  proc createDom(): VNode =
    result = buildHtml(tdiv):
      dthunk(elem)
      # dthunk(elem) # would give error
      dthunk(elem2) # works

  when isMainModule:
    setRenderer createDom, "ROOT"

but maybe karax could provide a better error msg in this case, pointing to the 2 usages of the same Node; so leaving this issue open as low priority

@timotheecour timotheecour changed the title reusing dthunk gives AssertionError: same(kxi.currentTree, document.getElementById(kxi.rootId)) [low priority] give more informative error msg when reusing dthunk Sep 30, 2019
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