-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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: prevent redirecting to / on form submit #15240
Conversation
@thienlnam @Santhosh-Sellavel One of you needs to copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
@@ -117,6 +117,7 @@ class SetPasswordPage extends Component { | |||
message={error} | |||
isAlertVisible={!_.isEmpty(error)} | |||
isDisabled={!this.state.isFormValid} | |||
disablePressOnEnter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enter should submit the form, right? Can you clarify
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
App/src/pages/SetPasswordPage.js
Line 103 in 94057ba
<FormSubmit onSubmit={this.validateAndSubmitForm}> |
Enter is handled in this component. disablePressOnEnter
prevents attaching a global listener.
preventFormDefault(event) { | ||
// When enter is pressed form is submitted to action url (POST /). | ||
// As we are using controlled component, we need to disable it here. | ||
event.preventDefault(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is intentional right, why prevent that?
cc: @thienlnam
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I believe so, if this was using the form default submit action before then how does this work now?
Is there a onSubmit handler for the form now? Also if there is, then you can prevent eventDefault via the onSubmit handler instead of adding an event listener like this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
App/src/pages/SetPasswordPage.js
Line 103 in 94057ba
<FormSubmit onSubmit={this.validateAndSubmitForm}> |
Form submit is handled in this component. I believe, there is no onSubmit
prop in react-native-web
, this is the reason handled in this way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not use the Form here, curious why?
@luacmartins or @thienlnam ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Password Managers need these attributes to be able to identify the form elements properly. | ||
this.form.setAttribute('method', 'post'); | ||
this.form.setAttribute('action', '/'); | ||
|
||
this.form.addEventListener('submit', this.preventFormDefault); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still confused, here we set post action. And we have a submit
listener which
When enter is pressed form is submitted to action url (POST /).
As we are using controlled component, we need to disable it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Santhosh-Sellavel this is the default browser behaviour to submit form data to action url, and this makes a full page refresh. As in our case this is a web app and does not require refresh. We need to prevent this default behaviour, otherwise user will be redirected to / when he presses enter on password input field. Form submition is manually handled using ajax request.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
react-native-web
does not accept onSubmit
prop, therefore addEventListener
is used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay here, but double checking @thienlnam Any thoughts?
cc: @luacmartins would you like to add anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
react-native-web does not accept onSubmit prop
Where did you find this out? I'm pretty sure this is not true as we have it many places and onSubmit is a common prop that seems like it would be supported in react-native-web
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a look, it seems like in that issue they are trying to add a onSubmit handler to the View which isn't even supported in react-native. The on submit has to be applied to the button event
Following the code, it seems that we're setting up our own onSubmit event handler in FormSubmit which wraps is wrapped in all the sign in content
Can you try preventing default in the FormSubmit component?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried, but it does not work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels off and weird, when I debug this code never executes i.e breakpoint never hit. So I remove the block and checked whether this occurs it didn't occur. But when I turned off debugging I was able to reproduce the issue and adding this back solves the issue.
If we are good with this lets go ahead and merge, thanks! @thienlnam
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Santhosh-Sellavel Have you run through the checklist for this PR yet? I'm hesitant since this feels like a workaround for prevent default submission but can we see if this doesn't break the login flow?
Bump on this comment @Santhosh-Sellavel |
Thanks for the bump @luacmartins Sorry, @thienlnam missed this comment, will run through the checklist and update you! |
Reviewer Checklist
Screenshots/VideosWeb & DesktopScreen.Recording.2023-03-09.at.12.41.30.AM.movMobile Web - ChromeAndroid_mWeb_log.mp4Mobile Web - SafariSimulator.Screen.Recording.-.iPhone.14.-.2023-03-09.at.00.52.14.mp4iOSN/A AndroidN/A |
|
@thienlnam it doesn't break the login flow. Tests well for me! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests well, just waiting for this
Ah yeah, I'd say so now that we added that to the email page (should still be accesible for keyboard users) |
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/thienlnam in version: 1.2.82-0 🚀
|
🚀 Deployed to production by https://github.com/Julesssss in version: 1.2.82-4 🚀
|
Details
This PR prevents the default behaviour of form that is to submit on action url on web.
Fixed Issues
$ #7917
PROPOSAL: #7917 (comment)
Tests
Offline tests
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.Screenshots/Videos
Web
web.mov
Mobile Web - Chrome
mweb-chrome.mov
Mobile Web - Safari
mweb-safari.mov
Desktop
iOS
Android