-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
show prompt only if form value changed #766
Comments
I started working on this issue so it can be assigned to me. Although I've been a software developer for a few years now I have no experience with React. I already ran into a few challenges where someone might have some ideas or suggestions for. Dirty state React Router Prompt Testing edit page Automated tests Adding the Lodash package |
Thanks for taking the time to look at this and the depth of solution you've worked on here. I think the main issues you've addressed are more than enough, and we don't need to worry about going into 100% accuracy for things like images etc. For the react router, another option could perhaps be seeing if we can use the componentWillUnmount lifecycle event for the form component instead (although I'm not sure if this will trigger on page reload or not, could be worth checking). For the edit page testing, you can indeed just create any testing how-to that you want to use. At some point in the future I'm hoping to improve on this to run the platform fully locally, but this is still some ways away (time is not my friend unfortunately). For cypress, great that we have a test but again I'd say no point testing too extensively, if as you mentioned next we are doing form value comparison correctly then it shouldn't really make much difference. And as you said for form comparison, in theory lodash shouldn't be much of an issue as it uses es modules and so is tree-shakeable (only adding in the chunk of code it needs so not bloating the overall site much at all). That being said I haven't tested the implementation myself, I've tried a couple specific npm packages like deep-equal and fast-deep-equal, and see there also react-fast-compare - I'm happy with anything that works (all seem to give different benchmarks of what is best and I don't expect any would be noticeably different for the small data sizes we are talking about for forms) although would be good to check is working as expected with a handful of form fields as I remember some have quirks depending on the order of keys the object is stored in etc. In any of these cases I'm keen to get your changes in sooner and we can work out finer details later. I'll test a merge today and check everything is running as expected from this side and get back to you. Thanks again for your input on this |
#766 Show prompt only if form value changed
Thanks for the appreciation and the clear reaction. I did a quick check with the componentWillUnmount but it is not triggered when the page is refreshed so I think the best solution for now is in my pull request. |
In how-to form, show the warning when leaving the page without saving only if a change as be made to the form.
Should be doable using the
FormState
of react-final-form. Documentation hereThe text was updated successfully, but these errors were encountered: