karax icon indicating copy to clipboard operation
karax copied to clipboard

AssertionError for editable `<p>` tag keydown event

Open liwt31 opened this issue 5 years ago • 1 comments

Example:

include karax / prelude

proc createDom(): VNode =
  result = buildHtml(tdiv):
    p(contenteditable="true"):
      proc onKeydown =
        discard

setRenderer createDom

The code is compiled to JS and typing anything in the <p> tag results in the following error:

Uncaught Error: Error: unhandled exception: /home/wtli/Test/karax/karax/karax.nim(597, 14) `same(kxi.currentTree, getElementById(document, kxi.rootId), 0)`  [AssertionError]
Traceback (most recent call last)
redraw.:anonymous, line: 637
karax.dodraw, line: 597
system.failedAssertImpl, line: 3879
system.raiseAssert, line: 3872
sysFatal.sysFatal, line: 2918

    at unhandledException (test.js:920)
    at raiseException (test.js:672)
    at sys_fatal_20437 (test.js:974)
    at raise_assert_20432 (test.js:984)
    at failed_assert_impl_20481 (test.js:994)
    at dodraw_178631 (test.js:2634)
    at HEX3Aanonymous_180001 (test.js:2699)

Seems that when redraw is called the document tree and the karax instance tree is indeed different.

liwt31 avatar Feb 14 '19 02:02 liwt31

workaround

include karax / prelude

var ins:KaraxInstance
proc createDom(): VNode =
  ins.surpressRedraws = true
  var editor = buildHtml:
    p(contenteditable="true"):
      proc onKeydown =
        discard
  var myEditor = vnodeToDom(editor)
  result = buildHtml(tdiv):
    dthunk(myEditor)

ins = setRenderer createDom

bung87 avatar May 24 '21 08:05 bung87

Now that #244 is merged, the error will not trigger and the code should work as expected, with the inner text of the p elem only being written by Karax if the app itself changes the text (which this example does not do).

geotre avatar Mar 02 '23 20:03 geotre