-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Experiment: tracked networkStatus
on useBackgroundQuery
#11183
base: main
Are you sure you want to change the base?
Conversation
…to `useBackgroundQuery`
|
size-limit report 📦
|
const c1 = screen.getByTestId("Consumer1"); | ||
const c1rc = within(c1).getByTestId("renderCount"); | ||
const c1ns = within(c1).getByTestId("networkStatus"); | ||
const c2 = screen.getByTestId("Consumer2"); | ||
const c2rc = within(c2).getByTestId("renderCount"); | ||
|
||
expect(c1rc).toHaveTextContent("1"); | ||
expect(c1ns).toHaveTextContent(String(NetworkStatus.loading)); | ||
expect(c2rc).toHaveTextContent("1"); | ||
|
||
const c1childRc = await within(c1).findByTestId("childRenderCount"); | ||
const c1childNs = within(c1).getByTestId("childNetworkStatus"); | ||
const c2childRc = within(c2).getByTestId("childRenderCount"); | ||
const c2childNs = within(c2).getByTestId("childNetworkStatus"); | ||
|
||
expect(c1rc).toHaveTextContent("2"); // !!! | ||
expect(c1ns).toHaveTextContent(String(NetworkStatus.ready)); | ||
expect(c1childRc).toHaveTextContent("1"); | ||
expect(c1childNs).toHaveTextContent(String(NetworkStatus.ready)); | ||
expect(c2rc).toHaveTextContent("1"); // !!! | ||
expect(c2childRc).toHaveTextContent("1"); | ||
expect(c2childNs).toHaveTextContent(String(NetworkStatus.ready)); |
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.
Here we have Component 1 accessing networkStatus
while Component 2 does not.
As a result, Component 1 renders twice, while Component 2 only renders once.
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
This is an experiment, and if we want to follow up could also be very useful on other hooks:
It adds a
networkStatus
field touseBackgroundQuery
, but in an "access-tracking" way: If the component doesn't read the field from the result object, the component will not rerender ifnetworkStatus
changes, but if the component does read the field, the component will rerender.Checklist: