-
-
Notifications
You must be signed in to change notification settings - Fork 66
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
Input not controlled when value and on-change specified. #148
Comments
@FreekPaans Nothing, I think you found a bug in sablono. :) |
That could also be it :) Do you need help fixing it? |
I guess the problem is in |
Ok, I'm looking into it but having troubles running the tests:
Maybe you can give me a quick pointer? |
@FreekPaans Looks like the node dependencies are not installed. Run
|
@r0man that did the trick! |
@r0man so I looked into it a little bit, but I'm not sure what's going on in Will look more into it later. |
@FreekPaans Yes, this is a bit tricky. I think having an See also 579f3d7 for the issue with IE and facebook/react#7027 To make it even more tricky, the whole |
@FreekPaans The IE bug should be fixed in the next version of React. Then we can remove the workaround code and this should behave as expected. There's also a similar workaround near the end of the comments: facebook/react#7027 |
Looked into it a bit more, but don't really know how to move forward. The design around |
Any advance on this ? |
@DjebbZ No, not yet. I haven't investigated if the IE fix is already in the latest version of React, or if this will ship with version 16. |
I was trying to track down why my refs weren't working and came across this issue. I want to share what I've learned in case it helps anybody, but take my analysis with a grain of salt because I could be totally wrong. The wrap-form-element was initially introduced in the following commit to om with the commit message "form element wrapper so we can get the correct behavior even in the presence of requestAnimationFrame": https://github.com/omcljs/om/blob/c1ebe9dbc750b290eea13843ba7f4836230e9180/src/om/dom.cljs It was imported into Sablono here as a fix for a bug where the cursor moves to the end of the input on each update: The basic gist of the problem can be seen by reading this monster thread from react: I think this is the problem: the state of a controlled input must be updated when a user hits a key and only then. Otherwise, the component will rerender and move the cursor around and if you type fast enough you'll drop characters since the subsequent events will not reflect the previous update. I think Om batches updates with requestAnimationFrame or some other mechanism. So I think the whole point here is to bypass that mechanism with real javascript event handler. (For the record, I don't understand the cursor-resetting issue, unless the entire dom node were being replaced, though the letter-dropping issue makes sense to me.) Later on, someone added a fix for an IE11 bug related to the on-change handler. If I'm right, I wonder if this wrapper is needed in for libraries that don't do whatever om is doing. (Like rum, for example.) |
This smells related: I'm having trouble with advanced compilation and have tracked it down to this code: (js/ReactDOM.render
;; this gives an error about some minified variable being undefined
(html [:input {:type "text"
:value ""}])
#_ ;; this works fine
(js/React.createElement
"input"
#js {:type "text"
:value ""})
(.getElementById js/document "app")) |
@gfredericks I can't reproduce this. Your example works for me. Do you have the proper externs for React in place? |
No, I'm using |
@gfredericks Then this might be the problem? sablono itself doesn't have any annotations that could be picked up by |
I didn't realize I needed to provide the externs; I'll look into that. I also didn't know about |
Adding the externs file seems to fix it. Thanks again! |
I had to change some config in project.clj otherwise Fighweel wouldn't run.
My current workaround is to re-render the component when {:did-mount (fn [state]
(let [comp (:rum/react-component state)]
(rum/request-render comp)
state))} |
Hi @r0man, could I help in any way to get this fixed? |
@pedrorgirardi Yes, if you have a good idea how to fix this, and can test this in multiple browsers I would love to get help on this. I don't have time to look into this myself at the moment. |
Ah, nice! Let me try then. :) |
Hi @r0man , may I ask why we need the wrappers? The React issue was fixed awhile ago so I tried to not use wrappers at all. I created this https://github.com/pedrorgirardi/sablono-issue-148 which uses my fork of Sablono without wrappers. Maybe the wrappers are no longer needed since the React issue was fixed? What am I missing? 😃 |
@pedrorgirardi If I remember correctly this was needed for libraries like om that render on requestAnimationFrame. I'm afraid I don't remember all the details. Do you have a link to the React issue that was fixed? |
What you reckon? |
This seems like an unrelated bug. This thing inside sablono is definitely support for requestAnimationFrame-based rendering. |
@piranha it's a bit confusing because it seems there are two "issues": 1) wrap controlled input component to support requestAnimationFrame-based rendering as you said; 2) workaround an IE specific issue which seems to have been fixed here facebook/react#7027 . |
@pedrorgirardi As @piranha mentioned I think we should keep the wrapped inputs to support libs that use RAF for rendering. I'm afraid I don't have time to look into this myself. |
Hi, when I create a component like this
The input becomes an uncontrolled component, while I would expect it to be a controlled one. When I create it manually:
It is controlled.
What am I doing wrong?
Thanks!
The text was updated successfully, but these errors were encountered: