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

Sharing keyed/unkeyed logic leads to inconsistent behavior #2003

Closed
pygy opened this Issue Oct 28, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@pygy
Copy link
Member

pygy commented Oct 28, 2017

This is a core bug in updateNodes

const cmp = {
  view(){},
  oncreate(){console.log('C')},
  onupdate(){console.log('U')},
  onremove(){console.log('R')}
}

console.log('different length')
m.render(document.body, [m(''), null, m(cmp)])
m.render(document.body, [m(''), m(cmp)])
m.render(document.body, [m(''), null, m(cmp)])

console.log('same length')
m.render(document.body, [m(''), m(cmp), null])
m.render(document.body, [m(''), null, m(cmp)])

logs

'different length'
'C'
'U'
'U'
'same length'
'R'
'C'
'R'
'C'

Flems

Replacing nulls with false or '' in the first half also causes onremove/oncreate to fire as I'd expect.

This is due to the fact that keyed/unkeyed diff share the same logic when the old and new lists have different length and keyed diff skips null nodes. There's a special loop for unkeyed diff when both the old and the new list have the same length though, which explains the "same length" behavior (it is only triggered when two nodes at the same index in old and vnode are both non-null and unkeyed, hence the m('') in the example above).

Suggested fix: Move all unkeyed diff to its own loop (PR incoming).

Also, good news, at long last I'm starting to feel at ease in updateNodes() :-)

@pygy

This comment has been minimized.

Copy link
Member

pygy commented Oct 31, 2017

Another updateNode bug (when mixing the pool with vnodes cached in user land).

I have a POC fix for the various updateNodes bugs that have popped up recently, but there are perf regressions (the unkeyed diff has too many branches and fetches from the pool even for possibly sparse tuples of identical lengths where it doesn't make sense (what is currently handled by the isunkeyed loop)).

I have another solution I want to test. If I get it to work, I'll slice the result into piecemeal tests/fix pairs (one per issue) and submit a PR.

@pygy pygy added the bug label Oct 31, 2017

@pygy pygy self-assigned this Oct 31, 2017

@orbitbot

This comment has been minimized.

Copy link
Contributor

orbitbot commented Nov 6, 2017

Is this a repro of the same issue or something slightly different?

pygy added a commit to pygy/mithril.js that referenced this issue Nov 21, 2017

pygy added a commit to pygy/mithril.js that referenced this issue Nov 21, 2017

render/updateNodes: revamp unkeyed list detection, don't skip null no…
…des in unkeyed lists when old and vnodes don't have the same length

Fix MithrilJS#2003 partim 2

pygy added a commit to pygy/mithril.js that referenced this issue Nov 21, 2017

pygy added a commit to pygy/mithril.js that referenced this issue Nov 21, 2017

render/updateNodes: revamp unkeyed list detection, don't skip null n…
…odes in unkeyed lists when old and vnodes don't have the same length

Fix MithrilJS#2003 partim 2

pygy added a commit to pygy/mithril.js that referenced this issue Nov 21, 2017

render/updateNodes: revamp unkeyed list detection, don't skip null n…
…odes in unkeyed lists when old and vnodes don't have the same length

Fix MithrilJS#2003 partim 2

@pygy pygy referenced this issue Nov 21, 2017

Merged

Fix updateNodes() (mostly vdom diffing logic). #2021

6 of 10 tasks complete
@pygy

This comment has been minimized.

Copy link
Member

pygy commented Nov 21, 2017

@orbitbot sorry for the delay, in your example, the lists has mixed keyed and unkeyed children, which is unsupported.

pygy added a commit to pygy/mithril.js that referenced this issue Nov 22, 2017

pygy added a commit to pygy/mithril.js that referenced this issue Nov 22, 2017

render/updateNodes: revamp unkeyed list detection, don't skip null n…
…odes in unkeyed lists when old and vnodes don't have the same length

Fix MithrilJS#2003 partim 2

pygy added a commit to pygy/mithril.js that referenced this issue Nov 23, 2017

pygy added a commit to pygy/mithril.js that referenced this issue Nov 23, 2017

pygy added a commit to pygy/mithril.js that referenced this issue Dec 4, 2017

pygy added a commit to pygy/mithril.js that referenced this issue Dec 4, 2017

render/updateNodes: revamp unkeyed list detection, don't skip null n…
…odes in unkeyed lists when old and vnodes don't have the same length

Fix MithrilJS#2003 partim 2

pygy added a commit to pygy/mithril.js that referenced this issue Dec 4, 2017

@pygy pygy closed this in eaa9f58 Dec 4, 2017

pygy added a commit that referenced this issue Dec 4, 2017

render/updateNodes: revamp unkeyed list detection, don't skip null n…
…odes in unkeyed lists when old and vnodes don't have the same length

Fix #2003 partim 2

pygy added a commit that referenced this issue Dec 4, 2017

pygy added a commit to pygy/mithril.js that referenced this issue Dec 8, 2017

pygy added a commit to pygy/mithril.js that referenced this issue Dec 8, 2017

render/updateNodes: revamp unkeyed list detection, don't skip null n…
…odes in unkeyed lists when old and vnodes don't have the same length

Fix MithrilJS#2003 partim 2

pygy added a commit to pygy/mithril.js that referenced this issue Dec 8, 2017

isiahmeadows added a commit to isiahmeadows/mithril.js that referenced this issue Oct 12, 2018

isiahmeadows added a commit to isiahmeadows/mithril.js that referenced this issue Oct 12, 2018

render/updateNodes: revamp unkeyed list detection, don't skip null no…
…des in unkeyed lists when old and vnodes don't have the same length

Fix MithrilJS#2003 partim 2

isiahmeadows added a commit to isiahmeadows/mithril.js that referenced this issue Oct 12, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment