hyperapp: oncreate appears to be broken

OnCreate seems to be broken currently. When porting a rather large application from hyperapp@0.7 to hyperapp@0.9 I experienced a crash.

Broken Code [run]

const { h, app } = hyperapp
/** @jsx h */

app({
  state: null,
  actions: {
    bug: element => element
  },
  view: (element, {bug}) => <h1 oncreate={bug}>{element ? 'yes' : 'no'}</h1>
})

Workaround [run]

const { h, app } = hyperapp
/** @jsx h */

app({
  state: null,
  actions: {
    bug: element => element
  },
  view: (element, {bug}) => <h1 oncreate={data => setTimeout(() => bug(data), 0)}>{element ? 'yes' : 'no'}</h1>
})

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 29 (17 by maintainers)

Most upvoted comments

@jbucaran No, I don’t have time for OpenSource stuff right now. I’m working while being a full-time student.

@jbucaran Sorry to quote myself again, but please re-read my last comment.

This issue isn’t about the way I store the reference to an element, that’s just an example. This issue is about hyperapp’s events breaking when using hyperapp’s own actions. There is no reason why this should break anything if I update the state. Instead, one solution would be to defer the next render until the current render is done.

yeah. if you’re storing refs in some persistent state which can outlive the removal of the dom element. you gotta remember to de-ref the ref in your state during onRemove or whatever to let it get cleaned up.