-
Notifications
You must be signed in to change notification settings - Fork 272
fix: prevent non editable textinputs from being updated through getByTestID #1092
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
Merged
mdjastrzebski
merged 4 commits into
callstack:main
from
pierrezimmermannbam:fix/nonEditableInput
Sep 13, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
e582ddd
fix: prevent non editable textinputs from being updated through getBy…
a23787e
refactor: add comment to explain double check in isTextInput function
9d4aaf1
Update src/__tests__/fireEvent.test.tsx
mdjastrzebski 26d484b
Update src/__tests__/fireEvent.test.tsx
mdjastrzebski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Wondering if this should be handled directly in
filterNodeByType
? That'd require a bit more refactoring, and some form ofhost component -> composite
element mapping. It would also add some overhead in branches that don't really care about it (all theText
based one for instance since we're not usingbyID
.So fine with me, but perhaps some other maintainer might feel different about that.
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.
You mean if filterNodeByType made the comparison for both the component and the component name ? It would involve that every query would need to filter composite components afterwards (except testId queries that already filter host components), I think it would introduce additional complexity and I don't see clearly how it could be beneficial so I'm not sure about it either
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 exactly. I was wondering if that would be the sort of abstraction we would like to move out of
fireEvent
. But given it's a very specific usecase for now, and given the complexity it implies, I agree that it's not probably worth it (hence my approval)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.
Isn't
TextInput
(composite) always renderingTextInput
(host) as its child? In such case we might only focus on one of these (preferably host one). ThoughTextInput
(host) might have different props/prop naming thanTextInput
(composite).Wdyt?
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.
BTW I am against having
filterNodeByType
to match against bothtype
andtype.name
has it would get confusing what thing will you actually get back.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.
Yes TextInput (composite) is always rendering a host TextInput, I was suggesting events could only be triggered on host component in the discussion on the other pr #1080 (comment) but as @AugustinLF noticed, it would be an issue for props with different naming. This could maybe be fixed by mapping native props name with composite components props name but it seems rather complicated and I'm not sure such a mapping is entirely possible. Also props from custom components that do not match any native prop couldn't be triggered through fake events anymore
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.
re query returning host components: iirc we had this assumption with @thymikee that all of the queries should always return host components (maybe except the
UNSAFE_getBy...
queries), just like in RTL where you are given actual DOM components (likediv
, etc), and not composite components as only host components result directly with "visible" UI.re
TextInput
predicate: we have have at least two options for noweditable=false
.node.parent
to verify its props.Both of the methods rely in some way on "internal" component structure from React Native, the question is which is less likely to change. I suspect that 1st option might be more stable as it probably refers to touch event handling, but we would need to research which prop is actually being set when
editable=false
.@pierrezimmermannbam, @AugustinLF, @thymikee which one would you pick, do you see other alternatives?
Additionally we should create a test case where we test whether our simulation works fine, so that we are able to detect when things break. That probably should be something like: