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

node wrongly deleted after a redraw if style param is used #287

Open
timotheecour opened this issue May 14, 2024 · 0 comments
Open

node wrongly deleted after a redraw if style param is used #287

timotheecour opened this issue May 14, 2024 · 0 comments

Comments

@timotheecour
Copy link
Collaborator

timotheecour commented May 14, 2024

nim js -o:app_bug.js -d:case_ok app_bug.nim: no bug
nim js -o:app_bug.js -d:case_bug1 app_bug.nim: when you click the button a few times, the foreign node gets (wrongly) deleted

index.html:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8"/>
    <meta content="width=device-width, initial-scale=1" name="viewport"/>
    <title>bug</title>
  </head>
  <body id="body">
    <div id="ROOT"></div>
    <script type="text/javascript" src="/app_bug.js"></script>
  </body>
</html>

app_bug.nim:

#[
nim js -o:app_bug.js app_bug.nim
python -m http.server 8006
d_forward_tunnel_simple $host_node_gpu 8006
http://localhost:8006/
]#

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

{.emit: """
function initTimeline2(){
    var container = document.getElementById('timeline_container');
    const textNode = document.createTextNode("Hello, World!");
    container.appendChild(textNode);
}
""" .}
proc initTimeline2() {.importc.}

type State = ref object
  loaded: bool
  textTimelines: seq[kstring]

let state = State()

proc handleClick(ev: Event; n: VNode) =
  state.textTimelines.add "foo"
  redraw()

proc createDom(data: RouterData): VNode =
  result = buildHtml(tdiv):
    button(onclick=handleClick):
      text "click"
    for i in 0..<len(state.textTimelines):
      tdiv:
        text state.textTimelines[i]

    when defined(case_bug1):
      tdiv(id="timeline_container", style = style(StyleAttr.width, cstring"200px"))
    elif defined(case_bug2):
      tdiv(id="timeline_container", style = "width: 200px".toCss)
    elif defined(case_ok):
      tdiv(id="timeline_container")
    else:
      static: assert false, "use -d:..."

proc clientPostRenderCallback(data: RouterData) =
  if not state.loaded:
    state.loaded = true
    initTimeline2()

setInitializer(createDom, root = "ROOT", clientPostRenderCallback = clientPostRenderCallback)
setForeignNodeId "timeline_container"

notes

  • no idea if related to regression: VNode.dom is nil #117
  • EDIT: it looks like this bug also affects other scenarios, not just when it invovles a setForeignNodeId (eg i've seen this occur on a div which contains some canvas)
@timotheecour timotheecour changed the title setForeignNodeId ineffective (node wrongly deleted after a redraw) if style param is used node wrongly deleted after a redraw if style param is used May 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant