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

Span with value zero can break application #43

Open
adrianbarsi opened this issue Oct 30, 2020 · 0 comments · May be fixed by #46
Open

Span with value zero can break application #43

adrianbarsi opened this issue Oct 30, 2020 · 0 comments · May be fixed by #46

Comments

@adrianbarsi
Copy link

adrianbarsi commented Oct 30, 2020

Simple counter application:

const patch = init([
    classModule,
    propsModule,
    styleModule,
    eventListenersModule,
])

let currentVnode: VNode = toVNode(document.getElementById('container') as any)

const view = (count: number) => {
   return <div>
       <button on-click={() => render(count+1)}>Increment</button>
       <span>{count}</span>
       <button on-click={() => render(count-1)}>Decrement</button>
   </div>
}

const render = (count: number) => {
    currentVnode = patch(currentVnode, view(count))
}

render(0)

If I increment above the value 0 and then decrement to -1 then it will give me the error: Uncaught TypeError: Node.removeChild: Argument 1 is not an object. It also gives an error if I decrement below 0 and then try to increment to 1. The fix is to change <span>{count}</span to <span>{String(count)}</span>. This behaviour differs from the hyperscript. The following hyperscript has no problems: h("span", null, count). Also the vnode generated shows that the span with a zero has children: {"sel":"span","data":{},"children":[{"text":0}],"text":0} whereas a span with a 1 has: {"sel":"span","data":{},"text":1}

@tpresley tpresley linked a pull request Jun 1, 2022 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant