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

📝 Document SSR & persistence/rehydration related features #1639

Merged
merged 9 commits into from
Oct 29, 2021

Conversation

Shrugsy
Copy link
Collaborator

@Shrugsy Shrugsy commented Oct 24, 2021

Note: This is reliant on #1277

This mainly adds stubs extracted from #1277 (comment)

Cache Management Utils is changed to API Slice Utils. A re-direct has been added to accomodate this.

@Shrugsy Shrugsy requested a review from phryneas October 24, 2021 00:55
@Shrugsy
Copy link
Collaborator Author

Shrugsy commented Oct 24, 2021

@Ephem, @ckalika; if either of you have any thoughts about crucial missing/incorrect pieces for this documentation please let me know

@markerikson
Copy link
Collaborator

Let's target this to point at the SSR PR so we can see exactly what's in this, and we can retarget against the 1.7 branch after the SSR PR is merged.

@markerikson markerikson changed the base branch from v1.7.0-integration to feature/ssr-suspense October 24, 2021 02:16
```ts no-transpile
const getRunningOperationPromise: <EndpointName extends QueryKeys<Definitions>>(
endpointName: EndpointName,
args: QueryArgFrom<Definitions[EndpointName]>
Copy link
Member

Choose a reason for hiding this comment

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

args can also be fixedCacheKey or requestId in the case of a mutation.
Maybe we should write three signatures here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've updated this signature as per #1277 (comment), but note that it hasn't been applied to #1277 at this stage

docs/rtk-query/api/created-api/miscellaneous-utils.mdx Outdated Show resolved Hide resolved
docs/rtk-query/usage/persistence-and-rehydration.mdx Outdated Show resolved Hide resolved
docs/rtk-query/usage/persistence-and-rehydration.mdx Outdated Show resolved Hide resolved
docs/rtk-query/usage/server-side-rendering.mdx Outdated Show resolved Hide resolved
@Ephem
Copy link

Ephem commented Oct 26, 2021

Nice work on this! I'm not very read up on the current state of #1277 so I can't really have any feedback on correctness or missing pieces, but reading this somewhat from an outside perspective I found the docs clear. 😄

One thing I'm curious about that didn't come up, and I'm not sure if it's been discussed, is how to refetch the data on the client after the initial render? With SSG especially, but also SSR with long cache times, the data can be very stale compared to when working inside a single session so to speak, what is the recommended way to revalidate in those cases? Is it/can it be automatic and if not, do you have access to how old a query is etc so you can do it manually? (Note that I'm not a heavy user of RTK Query, maybe this is already covered in other parts of the docs?)

@phryneas
Copy link
Member

phryneas commented Oct 26, 2021

@Ephem good goint! Especially in a SSG scenario one would probably want to set refetchOnmountOrArgChange globally to something like 900.
We could add a recommendation something like that.

Comment on lines +37 to +42
:::tip
In order to avoid providing stale data with Static Site Generation (SSG), you may wish to set
[`refetchOnMountOrArgChange`](../api/createApi.mdx#refetchonmountorargchange) to a reasonable value
such as 900 (seconds) in order to allow data to be re-fetched when accessed if it has been that
long since the page was generated.
:::
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@Ephem @phryneas FYI I've added this note to account for stale SSG data as per #1639 (comment) & #1639 (comment)

@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 26, 2021

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a04208e:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
rsk-github-issues-example Configuration

@phryneas phryneas added this to the 1.7 milestone Oct 28, 2021
@phryneas
Copy link
Member

I've moved the new functions from api.getRunningOperationPromises to api.util.getRunningOperationPromises - so this PR might need a bit of updating.

@Shrugsy Shrugsy changed the base branch from feature/ssr-suspense to v1.7.0-integration October 29, 2021 07:32
@Shrugsy
Copy link
Collaborator Author

Shrugsy commented Oct 29, 2021

I've moved the new functions from api.getRunningOperationPromises to api.util.getRunningOperationPromises - so this PR might need a bit of updating.

I've updated it to account for this:

  • Moved Miscellaneous Utils content into Cache Management Utils
  • Renamed Cache Management Utils to API Slice Utils
  • Added re-directs from the cache-management-utils page to api-slice-utils

@Shrugsy Shrugsy marked this pull request as ready for review October 29, 2021 07:40
Copy link
Member

@phryneas phryneas left a comment

Choose a reason for hiding this comment

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

I'll add some minor changes on top and merge this. Thanks a ton, your help really means a lot 😊

docs/rtk-query/api/createApi.mdx Outdated Show resolved Hide resolved
docs/rtk-query/api/created-api/overview.mdx Outdated Show resolved Hide resolved
packages/toolkit/src/query/core/module.ts Outdated Show resolved Hide resolved
@phryneas phryneas merged commit 87d6e3a into reduxjs:v1.7.0-integration Oct 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

5 participants