-
Notifications
You must be signed in to change notification settings - Fork 273
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
refactor: type all queries to return host components #1426
refactor: type all queries to return host components #1426
Conversation
871dcc6
to
9b75b4f
Compare
@pierrezimmermannbam I've got back from my summer break. Great to see your` PRs! Regarding this particular PR, the idea of using host check in I am a bit concerned with the |
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #1426 +/- ##
==========================================
- Coverage 97.57% 97.56% -0.02%
==========================================
Files 74 73 -1
Lines 4338 4312 -26
Branches 636 627 -9
==========================================
- Hits 4233 4207 -26
Misses 105 105
☔ View full report in Codecov by Sentry. |
@pierrezimmermannbam I've done some experiments on this PR and here are some interesting findings:
So React incorrectly assumes that host components would be only HTML tags. Ignoring the React Native situation.
With TS errors like:
Now part for the questions:
@pierrezimmermannbam looking forward for some thoughts on that. |
I don't think it's a big problem that This PR would technically be a breaking change since it narrows the return type of queries. It should have very little impact though but still I think it's probably better to release it with the next major version. Also this PR mostly brings benefits for the code maintenance but holds little to no value for users so there's no real inconvenience in delaying its release |
I think that returning covariant (more specialized) type from query functions should not be considered a breaking change, as any variable assignments that user has would still be valid, as As for TS errors, I've did some checks and using checks like The one decision I am still contemplating is whether we should make the host type information public or keep it internal only. I think that we should rather keep this internal for now, as it would bring some benefits to us in terms of code simplification/expressiveness, while it could be considered confusing for the users and would require proper documentation, etc. |
@mdjastrzebski if I understand correctly you're suggesting that we don't change the public API at all? Or that we only change the naming of the exposed type? |
@pierrezimmermannbam yes, I am proposing to use the |
@mdjastrzebski I agree with your motives, keeping the same public API would indeed make things simpler for users. What bothers me with your changes is that we no longer are certain that queries return host components. I pushed an alternative version that adds an internal type for queries so that we're sure every query return host components while keeping the same public API. It does add a bit of complexity but it seems like a fair price to pay, wdyt? |
@pierrezimmermannbam It seems we are not using queries internally in a way that having return type of |
@mdjastrzebski the return type is indeed not used in the code so specifying it doesn't simplify the code but the true motive here is specifying the type. I think that we want all queries to return host components and that typing enforces that. It's like typing the public API, only it's hidden |
This reverts commit 979f92a83e43b04a30c979445633896ec3496769.
f418adc
to
a8bd444
Compare
Looks good. I've reverted the last commit on InternalQueryAll types, and renamed |
This PR has been released in v12.2.1 🚡 |
Summary
HostReactTestInstance
findAllInternal
rather than on each query levelNow that all queries return host elements, this can be made explicit by a more precise typing. It also ensures that queries will consistently return host elements from now on. I also moved the logic of filtering non host elements in
findAllInternal
rather than on each query level to remove some code duplication and most importantly remove checks that didn't useisHostElement
and therefore were not explicit.Test plan
All existing tests and type checks pass