-
Notifications
You must be signed in to change notification settings - Fork 273
fix: add prop to render to skip configureHostComponentNamesIfNeeded #1425
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: add prop to render to skip configureHostComponentNamesIfNeeded #1425
Conversation
Thanks for opening this pr @KrastanD! Regarding the implementation, I don't think the API of This would be a good step forward but it would only make |
Hopefully this update is more of what you had in mind @pierrezimmermannbam. I pulled out only the necessary parts of the render function into the renderHook. I didn't want to change the api in any way so there is a bit of code duplication between |
src/renderHook.tsx
Outdated
@@ -42,12 +43,20 @@ export function renderHook<Result, Props>( | |||
return null; | |||
} | |||
|
|||
const { rerender: baseRerender, unmount } = render( | |||
const wrap = (element: React.ReactElement) => |
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.
What is the purpose of this change? It seems to do the same thing as previous code with just passed wrapper to renderWithAct
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.
renderWithAct
does what render
does but without detecting hostComponentNames
@KrastanD I support resolving the issue of Current implementation feels unnecessarily complex though. I would opt for "internal" (non-documented) Proposed naming:
@pierrezimmermannbam, @KrastanD wdyt? |
@mdjastrzebski My initial version of this PR which you can see here solved the problem in a similar way to what you are suggesting except instead of naming it |
@mdjastrzebski @KrastanD I personally like this implementation, I don't think it's complex, in fact I think it's an improvement. Sure there is a bit of code duplication to handle wrapper option and update with act but it doesn't add an additional prop to the render function just for renderHook's sake. This is a better separation of concern imo, if tomorrow we're to add a new feature that's only for components we'll need to add one more flag. And with this implementation it's very easy to change renderHook or render without changing the behavior of the other one, which is what we want I believe. I think this implementation will be easier to maintain so I would keep it. Also even of the flag is not documented it would be visible to users with autocomplete, it's not a big problem but still a downside |
37a8f48
to
e84bf8c
Compare
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1425 +/- ##
==========================================
+ Coverage 97.02% 97.04% +0.02%
==========================================
Files 68 68
Lines 3863 3898 +35
Branches 568 570 +2
==========================================
+ Hits 3748 3783 +35
Misses 115 115
☔ View full report in Codecov by Sentry. |
e84bf8c
to
c3d1ce0
Compare
@KrastanD, @pierrezimmermannbam I've refactored the code so that it uses internal option |
This PR has been released in v12.1.3 🚢 |
Summary
#1423
Test plan
This change can be tested by running the renderHook.test.tsx tests after clearing the jest cache. Before my change, the first test takes 445 ms and after my change it takes 5 ms.
Before:
After: