fixes overly aggressive text node reuse DOM diff'ing bug
This commit is contained in:
parent
75739f8170
commit
87edc4cdb9
2 changed files with 5 additions and 4 deletions
|
|
@ -233,7 +233,7 @@ proc eq(a, b: VNode): EqResult =
|
||||||
if a.kind == VNodeKind.text:
|
if a.kind == VNodeKind.text:
|
||||||
if a.text != b.text:
|
if a.text != b.text:
|
||||||
when defined(profileKarax): inc reasons[deText]
|
when defined(profileKarax): inc reasons[deText]
|
||||||
return similar
|
return different # similar
|
||||||
elif a.kind == VNodeKind.vthunk or a.kind == VNodeKind.dthunk:
|
elif a.kind == VNodeKind.vthunk or a.kind == VNodeKind.dthunk:
|
||||||
if a.text != b.text: return different
|
if a.text != b.text: return different
|
||||||
if a.len != b.len: return different
|
if a.len != b.len: return different
|
||||||
|
|
@ -648,7 +648,8 @@ proc setRenderer*(renderer: proc (): VNode, root: cstring = "ROOT",
|
||||||
clientPostRenderCallback: proc () = nil): KaraxInstance {.discardable.} =
|
clientPostRenderCallback: proc () = nil): KaraxInstance {.discardable.} =
|
||||||
## Setup Karax. Usually the return value can be ignored.
|
## Setup Karax. Usually the return value can be ignored.
|
||||||
proc wrapRenderer(data: RouterData): VNode = result = renderer()
|
proc wrapRenderer(data: RouterData): VNode = result = renderer()
|
||||||
proc wrapPostRender(data: RouterData) = clientPostRenderCallback()
|
proc wrapPostRender(data: RouterData) =
|
||||||
|
if clientPostRenderCallback != nil: clientPostRenderCallback()
|
||||||
setRenderer(wrapRenderer, root, wrapPostRender)
|
setRenderer(wrapRenderer, root, wrapPostRender)
|
||||||
|
|
||||||
proc setInitializer*(renderer: proc (data: RouterData): VNode, root: cstring = "ROOT",
|
proc setInitializer*(renderer: proc (data: RouterData): VNode, root: cstring = "ROOT",
|
||||||
|
|
|
||||||
|
|
@ -156,14 +156,14 @@ proc testWild() =
|
||||||
let a = createEntries(entries)
|
let a = createEntries(entries)
|
||||||
entries = @[cstring("0"), cstring("1"), cstring("2"), cstring("3"), cstring("4"), cstring("5")]
|
entries = @[cstring("0"), cstring("1"), cstring("2"), cstring("3"), cstring("4"), cstring("5")]
|
||||||
let b = createEntries(entries)
|
let b = createEntries(entries)
|
||||||
doDiff(a, b, "pkDetach button 7", "pkRemove nil", "pkDetach div 5", "pkRemove nil")
|
doDiff(a, b, "pkDetach button 7", "pkRemove nil", "pkDetach div 7", "pkRemove nil")
|
||||||
|
|
||||||
proc testWildInsert() =
|
proc testWildInsert() =
|
||||||
var entries = @[cstring("0"), cstring("1"), cstring("2"), cstring("3"), cstring("4"), cstring("5")]
|
var entries = @[cstring("0"), cstring("1"), cstring("2"), cstring("3"), cstring("4"), cstring("5")]
|
||||||
let a = createEntries(entries)
|
let a = createEntries(entries)
|
||||||
entries = @[cstring("0"), cstring("1"), cstring("2"), cstring("3"), cstring("4"), cstring"7", cstring("5")]
|
entries = @[cstring("0"), cstring("1"), cstring("2"), cstring("3"), cstring("4"), cstring"7", cstring("5")]
|
||||||
let b = createEntries(entries)
|
let b = createEntries(entries)
|
||||||
doDiff(a, b, "pkInsertBefore button 7", "pkAppend div 5")
|
doDiff(a, b, "pkInsertBefore button 7", "pkInsertBefore div 7")
|
||||||
|
|
||||||
kxi = KaraxInstance(rootId: cstring"ROOT", renderer: proc (data: RouterData): VNode = discard,
|
kxi = KaraxInstance(rootId: cstring"ROOT", renderer: proc (data: RouterData): VNode = discard,
|
||||||
byId: newJDict[cstring, VNode]())
|
byId: newJDict[cstring, VNode]())
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue