Skip to content
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

Upgrade RHF to v7.11.0 #3043

Merged
merged 9 commits into from
Aug 3, 2021
Merged

Upgrade RHF to v7.11.0 #3043

merged 9 commits into from
Aug 3, 2021

Conversation

LBrian
Copy link
Contributor

@LBrian LBrian commented Jul 15, 2021

This is the same task as #2270 to upgrade react-hook-form to v7 (latest v7.11.0), I created a separated PR coz I don't wanna contaminate the original PR.

@morganmspencer I hope you don't mind that I took the liberty to create a separated PR for the same work you already started mainly try not to contaminate your great works so far. I was tagged by @thedavidprice and @Tobbe a week ago while I was fixing a form related bug #2979 see if I could potentially jump in to help on this. I am happy for you to cherry pick my changes into your PR if you are willing to as you should take the credit as your PR actually speed up my work a lot.

Anyway, even unit tests are all passed and tested with my application, Im still not 100% confident, so would be good to have more eyes on this. Also, open for naming suggestion in general if current naming doesn't provide clear context.

Btw, I noticed a weird behaviour while testing with my application, the formState.dirtyFields returns empty the first time when you change a field then blur, it seems related to this issue happened in v7.0.7. formState.touchedFields and formState.isDirty are all working fine, I don't think this is related to redwood directly, but worth to mention.

const tagProps = inputTagProps(props) as T & {
onChange?: React.ChangeEventHandler<T>
onBlur?: React.FocusEventHandler<T>
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not happy about this type casting but only have few hours today, open for any better suggestions

@LBrian
Copy link
Contributor Author

LBrian commented Jul 21, 2021

@callingmedic911 Fyi, cherry-picked your dataType prop deprecation from #2896 into here as a whole of form changes 😃 cc @thedavidprice

@jtoar
Copy link
Contributor

jtoar commented Jul 23, 2021

@LBrian thanks for your patience! Having a look at this now; will be my focus for the rest for the week.

Comment on lines +146 to +153
const onBlur: React.FocusEventHandler<T> = (event) => {
handleBlur(event)
tagProps?.onBlur?.(event)
}
const onChange: React.ChangeEventHandler<T> = (event) => {
handleChange(event)
tagProps?.onChange?.(event)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with you here that react hook form's blur/change handlers should be invoked first. Also falls in line with their documentation (might have to scroll down a bit to see the screenshot below):

image

@jtoar
Copy link
Contributor

jtoar commented Jul 28, 2021

@LBrian this is awesome; thanks for hacking on the framework with us (and most of all your patience!) 🚀

I think this is ready to go as is, and if we need to release soon we'll just merge it. But I think we still have a few days before the release at least, and there's one other thing we want to do and should've done when we upgraded to v6, and that's use react hook form's native coercion.

When we first introduced coercion via the react context setup we've got now, we were using react hook form v5 which had no native answer. In v6 they added a few options, like valueAsNumber, valueAsDate, and setValueAs (which lets you provide a function to handle the rest of the cases). You can find documentation for them under register here. Would you be up for deprecating the coercion setup we've got going in favor of react hook form's options? Just let me know—I'm happy to merge this one and do it as a separate follow up PR! Thank you again for this.

@thedavidprice
Copy link
Contributor

@jtoar why don't we give this a few more hours today. If Brian doesn't respond, we can assume he's heads down on other things for the time being. So merge this, then open a new issue and loop him in (regarding #3043 (comment)).

Sound good?

@LBrian
Copy link
Contributor Author

LBrian commented Jul 31, 2021

@jtoar @thedavidprice Sorry, I've been crazy busy whole this week coz I moved on and joined a new team this Monday. If possible, may I suggest that we merge first then revisit later? I don't think I will have time in the follow few days to tackle this, it would be good to give me few days to settle in my new team then I will pick it up later.

@LBrian
Copy link
Contributor Author

LBrian commented Aug 1, 2021

@jtoar For coercion refactoring, would you mind create an issue and assign to me so I can follow up later? appreciate 😄

@thedavidprice
Copy link
Contributor

CI error:

  > Module build failed (from ../node_modules/babel-loader/lib/index.js):
108
SyntaxError: /tmp/redwood.FAtTec/web/src/Routes.js: Identifier 'PostsLayout' has already been declared. (6:7)
109

110
  4 | import { Router, Route, Set } from '@redwoodjs/router'
111
  5 | import PostsLayout from 'src/layouts/PostsLayout'
112
> 6 | import PostsLayout from 'src/layouts/PostsLayout'

What the what???

@jtoar
Copy link
Contributor

jtoar commented Aug 2, 2021

@thedavidprice I ran it locally to see if I could reproduce the error but no luck; thanks for rerunning!

@thedavidprice
Copy link
Contributor

It almost feels like it's not starting from a new directory... like it's building on top of something existing. I'll take a look.

@thedavidprice thedavidprice merged commit f3ae546 into redwoodjs:main Aug 3, 2021
dac09 added a commit to dac09/redwood that referenced this pull request Aug 4, 2021
…om-functions-test

* 'main' of github.com:redwoodjs/redwood:
  Better SEO by default on every pages (redwoodjs#3026)
  Add more info in the terminal | Tweak  gitpod settings (redwoodjs#3185)
  Undo accidentally vscode settings change (redwoodjs#3184)
  Upgrade RHF to v7.11.0 (redwoodjs#3043)
  [setup tailwind] Include tailwind by adding directives to index.css (redwoodjs#3181)
  Configure cloud based development for contributors (redwoodjs#3150)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants