-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add areEqualOwners to check for structural equality of fragment owner…
…s. (#4500) Summary: There is a bug in the experimental hooks implementation. useRefetchableFragment will return a new data object every time the refetch function is called, even if the data has not changed. This is because refetch creates a new fragment owner with createOperationDescriptor and refetch variables, and passes it to useFragmentInternal as part of the fragment key. Later in useFragmentInternal, we call areEqualSelectors to check if the fragment selector has changed. The owner is part of the selector, but we only check if the owner is the same object. However, it's possible that the owner is the same but just a new instance of the same object. Proposed fix: * Add areEqualOwners to check that owners are equivalent. This would prevent an endless loop of refetch/setState between components using useRefetchableFragment and the refetch call in the useEffect. Pull Request resolved: #4500 Test Plan: * New unit test-case to useRefetchableFragmentNode-test. * Updated tests for RelayModernSelector. Reviewed By: voideanvalue Differential Revision: D50524883 Pulled By: alunyov fbshipit-source-id: 6d9df3abc80ab997a59bf961e7a721da6ad769e3
- Loading branch information
1 parent
d35e27b
commit 8011e22
Showing
7 changed files
with
417 additions
and
10 deletions.
There are no files selected for viewing
113 changes: 113 additions & 0 deletions
113
...oks/__tests__/__generated__/useRefetchableFragmentNodeTestIdentityTestFragment.graphql.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
178 changes: 178 additions & 0 deletions
178
..._/__generated__/useRefetchableFragmentNodeTestIdentityTestFragmentRefetchQuery.graphql.js
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Oops, something went wrong.