Skip to content
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 skip causing loading to always be true during SSR #7567

Merged
merged 3 commits into from
Jan 14, 2021

Conversation

rgrove
Copy link
Contributor

@rgrove rgrove commented Jan 11, 2021

PR #7310 introduced a regression that causes skipped SSR queries to always set loading to true, which doesn't match the behavior of useQuery() on the client and can result in hydration mismatches.

The problem is that skip: true was being treated as equivalent to ssr: false, but they're not actually equivalent. I think the correct solution is to let this.getQueryResult() provide a suitable result when skip is truthy, which ensures that skipped SSR queries will get the same result as skipped non-SSR queries.

An alternative approach would be to simply back out the changes from PR #7310, but then we'd lose the benefit of avoiding the unnecessary QueryPromise when skip is truthy.

Fixes #7380 (note that this issue's title and description are inaccurate, but its comments describe the problem correctly)

Checklist:

  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

PR apollographql#7310 introduced a regression that caused skipped SSR queries to
always set `loading` to `true`, which doesn't match the behavior of
`useQuery()` on the client and can result in hydration mismatches.

The problem is that `skip: true` was being treated as equivalent to
`ssr: false`, but they're not actually equivalent. I think the correct
solution is to let `this.getQueryResult()` provide a suitable result
when `skip` is truthy, which ensures that skipped SSR queries will get
the same result as skipped non-SSR queries.

Fixes apollographql#7380
@benjamn benjamn assigned benjamn and unassigned benjamn Jan 12, 2021
@benjamn benjamn self-requested a review January 12, 2021 23:36
Copy link
Member

@benjamn benjamn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rgrove Thanks for digging into this and coming up with a good solution! I pushed a commit to make sure result.networkStatus is defined in the skip: true case, but that's just because I thought it was strange you needed to test expect(networkStatus).toBeUndefined(). This PR should land in the next patch version, @apollo/client@3.3.7.

@benjamn benjamn merged commit 00284d2 into apollographql:main Jan 14, 2021
@rgrove
Copy link
Contributor Author

rgrove commented Jan 14, 2021

@benjamn Thanks for the quick review and the cleanup!

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[3.3.0] Queries during SSR is always skipped.
2 participants