-
Notifications
You must be signed in to change notification settings - Fork 93
Adding a function for virtual-dom's defaultValue property. #81
base: master
Are you sure you want to change the base?
Conversation
This is needed if you want to set an initial value for a form element. (In contrast with the "value" property, which sets the value on every re-render.)
Can you explain more about this? Is there any documentation? Is this a custom thing added into the underlying virtual-dom implementation in JS? Is it possible to avoid reseting on every rerender instead? |
Yes, sorry, let me back up a bit and explain. Here's a simple example (which I've lifted from @rtfeldman's signup form sample): As it says, if you type something into the first input box, move the cursor to the start, and type quickly, the cursor position will jump - somehow the input & rendering get out of sync. I believe this is because there's an assumption that the input-update-rerender happens in a single step, but I don't think that's the case. I think that if the event queue is busy enough - which I've simulated with an I've seen a similar problem where characters are dropped, but the cursor-jump is easiest to replicate. One solution is fairly easy. Just set the value on the input field once - using Obviously, "not getting out of sync" would be the ideal solution. But this works for me, and |
Yeah, we've run afoul of this with integration tests - the test runner "types" into the input box too fast, so things sometimes get out of sync (but not always - it's a race condition, possibly having to do with I've always thought I think we should at least discuss other options before doing what React did here. Is there some way to solve the "getting out of sync" race condition problem? Happy to elaborate on stuff we've encountered etc if it would help. |
I thought I'd post here as it was mentioned in the other discussion thread I was involved with I believe the problem observed in the examples is with a selection instead as when you modify the In the project I work we resolved similar issues with |
@Gozala Can you share your solution for tracking selection in model? |
@rofrol I did describe it in the mentioned thread. As of project I mentioned, it is unfortunately not in Elm but in JS that very closely follows Elm architecture and and design (well from version back for now) but feel free to look at how solution looks there: Here is an implementation of what I would turn into a If you look at the generic Edit field code both input and selection events carry input selection information with a message so that two stay in sync and avoid issues described. P.S.: Code is little old & solution is not quite as elegant as a proposal in the discussion thread, but it works. |
I am also having issues with I should say that there are two side by side "panes" -- one, on the left, with the "source" text, the other on the right, with the rendered text (rendered by asciidoctor + mathjax). The right-hand text, which is managed by ports, behaves correctly. For the moment I can live with this, but won't be able to go into production without a solution. Perhaps there is an easy fix ... ??? When I select a new document, it becomes the |
@jxxcarlson You have to also use https://ellie-app.com/3fPSxX6VHK7a1/0 Look at the way reset is implemented. Without the |
Ran into this today with a barcode scanner and an input field. Scanner typed faster than Elm's update/render cycle. This caused characters to get dropped in the input field. It's a shared mutable state problem since both the user and Elm renderer are both writing into I see in the documentation that |
This is needed if you want to set an initial value for a form
element. (In contrast with the "value" property, which sets the value on
every re-render.)