Skip to content

Commit

Permalink
fix(hdom): always update "value" attrib last in diffAttributes()
Browse files Browse the repository at this point in the history
- fixes issue when patching <input type=range> elements
  with changed min/max limits
  • Loading branch information
postspectacular committed Jul 10, 2018
1 parent fcfd4bf commit 126103b
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/hdom/src/diff.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ const isString = iss.isString;
const diffArray = diff.diffArray;
const diffObject = diff.diffObject;

const SEMAPHORE = Symbol("SEMAPHORE");

/**
* Takes a DOM root element and two hiccup trees, `prev` and `curr`.
* Recursively computes diff between both trees and applies any
Expand Down Expand Up @@ -128,17 +130,29 @@ function diffAttributes(el: Element, prev: any, curr: any) {
let i, e, edits;
const delta = diffObject(prev, curr);
removeAttribs(el, delta.dels, prev);
let value = SEMAPHORE;
for (edits = delta.edits, i = edits.length; --i >= 0;) {
e = edits[i];
const a = e[0];
if (a.indexOf("on") === 0) {
el.removeEventListener(a.substr(2), prev[a]);
}
setAttrib(el, a, e[1], curr);
if (a !== "value") {
setAttrib(el, a, e[1], curr);
} else {
value = e[1];
}
}
for (edits = delta.adds, i = edits.length; --i >= 0;) {
e = edits[i];
setAttrib(el, e, curr[e], curr);
if (e !== "value") {
setAttrib(el, e, curr[e], curr);
} else {
value = curr[e];
}
}
if (value !== SEMAPHORE) {
setAttrib(el, "value", value, curr);
}
}

Expand Down

0 comments on commit 126103b

Please sign in to comment.