question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Range Input: Order of Attributes Bug

See original GitHub issue

I stumbled upon a bug while working with Preact today. If you create an input range, the initial render of the slider position may be wrong, depending on the order of the attributes. The value attribute needs to be set after min/max/step. If value is applied before min/max/step are properly set, the value will be forced to match the default min=0/max=100/step=1 on a slider.

E.g. if you create two sliders:

// This one renders with the slider at 0
<input type="range" value={0.5} min="0" max="1" step="0.05" />

// This one renders with the slider at 0.5
<input type="range" min="0" max="1" step="0.05" value={0.5} />

image

See minimal code to reproduce here

When creating an dom element from a vnode, it looks like attributes are applied one at a time via a for...in loop. Since the ordering of keys in an object is arbitrary, it seems like diffAttributes needs to apply the attributes in a sorted way. I can’t think of other potential ordering pitfalls with attributes (maybe the react source code would have insights), but at the very least, applying value last should fix this issue.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
mikewesthadcommented, Apr 23, 2019

@marvinhagemeister thanks! Closing my PR

Read more comments on GitHub >

github_iconTop Results From Across the Web

`<input type="range">` is sensitive to the order of attribute setting
For example, we fixed a bug in Glimmer a while ago where we were inserting elements in the wrong order (appending into DOM...
Read more >
html width and height bug on <input type='range'> when rotated
This seems to be a bug in the slider itself. I just put this in a table to show the problem. Width in...
Read more >
A Sliding Nightmare: Understanding the Range Input
We need to bring up DevTools, then go to the range input we want to inspect, right click it, select Inspect Element and...
Read more >
<input>: The Input (Form Input) element - HTML
The <input> HTML element is used to create interactive controls for web-based forms in order to accept data from the user; a wide...
Read more >
HTML input type="range" - W3Schools
Default range is 0 to 100. However, you can set restrictions on what numbers are accepted with the attributes below. max - specifies...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found