-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix race condition in textfields #161
Comments
I take it the proposal is to use There was discussion on this over on elm-dev, which lead to this comment. |
The ramification is that you cannot update This is usually what you want, though. And if you do want to update the input later on, you will find out that However, consider the following UI example: say your application is dealing with some resource |
For note I've exclusively been using |
The Elm Or, are you using intricate adding and removing of event handlers to circumvent the bug? For instance, the bug does not appear if you are removing the input handler on focus and add it back on blur. But you introduce other problems. I think all test programs that we are considering for this example should be quite large and should not remove the input handler at any time. edit: Actually, package.elm-lang.org does not seem to set |
It is a fairly large DOM though not particularity complex, so likely not. I'm curious how to replicate the issue for me, seem unable to yet. I do however utterly destroy the textfield (removing it from the DOM) for a period of time of no less than the server-roundtrip (replaced with an 'in-progress' indicator) before it is re-created and re-focused. That potentially resets the issue I am guessing? |
The bug is observable in this demo. |
Fascinating, and with that I have figured out how to replicate it on mine. (Oh how I miss C++'s determinance rather than random DOM events) |
I think we should add a We should not remove the Also, the documentation for What do you think? |
What would be the consequence of just redefining the current |
The value would not change I assume after the initial rendering ? Atleast based on http://package.elm-lang.org/packages/elm-lang/html/1.1.0/Html-Attributes#defaultValue |
I very much need access to 'value'. At the very least I need to push a new value update to it to reset the textfield contents (like prepending @somename, surrounding selected text with, say, bold, etc...). I am currently only setting the text when I need to via this: setTextOnMessageInput : String -> Cmd Msg
setTextOnMessageInput newText =
Cmd.batch
[ cmd_from_msg <| UpdateInputMessageText newText
, cmd_delay <| cmd_from_msg <| ClearInputMessageText
] Which sets/clears a key on the model record for the respective messages, just made this change this morning, works perfectly, and I do not care if the cursor jumps, I also made a new So yes, I need 'value', defaultValue would also be useful though (since I do clear the textfield element out of the DOM entirely and re-add once I have confirmation the message has successfully sent). |
As @vipentti said, a input with defaultValue does not update its value ever from the Elm side. It just starts out with defaultValue instead of being empty. So things like automatically adding - to a "date" input YYYY-MM-DD wouldn't work, for instance. |
Correct, that is what I've mentioned as to why I still need normal A defaultValue I'd almost never need for this application, though would be quite useful in various forms. |
Keep in mind that whenever elm re-renders ( |
@debois Tested, and the jump does not happen anymore, however it also makes it so I cannot update it. My functions for highlighting a string of text are changing the backend model (and thus the rendered view) but are not changing what is in the message box, so I need a way to force it to update somehow as this entirely breaks the editor buttons as seen at: https://overminddl1.com/screenshots/work/Textfield-Editor_Broken.gif I wish there were a way to submit a So yeah, as-is-is that test breaks my editor, have any idea on how to fix. :-) |
Consequently, here it is again after I rollback to 7.3.0: https://overminddl1.com/screenshots/work/Textfield-Editor_Working.gif |
I'm not sure I follow. I'd expect your Model to have some field I don't fully understand your current approach with flags. What is it? Why is it necessary? |
That is precisely what I do, but then I need to update the textfield to show the markdown that I applied. In the second image the markdown appears in the textfield, in the first it does not. |
Textfield should support both value and defaultValue functions. That is the best we can do right know according to my knowledge. Please re-open if I am missing a way to improve the situation in Elm. |
This is just a reminder for me that I want to start a discussion about this.
edit: As discussion about this started already before I had a chance to motivate it here, please see the discussion below. In particular, have a look at the comment linked by @debois in his first comment which explains the race condition.
The text was updated successfully, but these errors were encountered: