Skip to content

Commit

Permalink
Fix hydration LIS computation lookup range
Browse files Browse the repository at this point in the history
  • Loading branch information
hbirler committed Jun 10, 2021
1 parent 8f35b0e commit 37b552f
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/runtime/internal/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type NodeEx = Node & {
};

function upper_bound(low: number, high: number, key: (index: number) => number, value: number) {
// Return first index of value larger than input value
// Return first index of value larger than input value in the range [low, high)
while (low < high) {
const mid = low + ((high - low) >> 1);
if (key(mid) <= value) {
Expand Down Expand Up @@ -69,7 +69,7 @@ function init_hydrate(target: NodeEx) {
// Find the largest subsequence length such that it ends in a value less than our current value

// upper_bound returns first greater value, so we subtract one
const seqLen = upper_bound(1, 0, idx => children[m[idx]].claim_order, current) - 1;
const seqLen = upper_bound(1, longest + 1, idx => children[m[idx]].claim_order, current) - 1;

p[i] = m[seqLen] + 1;

Expand Down Expand Up @@ -366,7 +366,7 @@ export function claim_text(nodes: ChildNodeArray, data) {
return claim_node<Text>(
nodes,
(node: ChildNode): node is Text => node.nodeType === 3,
(node: Text) => node.data = '' + data,
(node: Text) => { node.data = '' + data },
() => text(data),
true // Text nodes should not update last index since it is likely not worth it to eliminate an increasing subsequence of actual elements
);
Expand Down

0 comments on commit 37b552f

Please sign in to comment.