-
Notifications
You must be signed in to change notification settings - Fork 61
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
Automatically handle expired refs #333
Labels
enhancement
New feature or request
Comments
@angeloashmore I am interested in contributing to this feature, would you mind let me know if this feature has any high priority, as it would take sometime for me to fix this issue. |
9 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
@prismicio/client
throws aRefExpiredError
when a request's ref is expired. The client typically fetches the active ref automatically before sending a content request, but some environments cache the ref. For example, Next.js cachesfetch()
requests, which could result in a request made with a stale ref.Because
@prismicio/client
handles fetching the ref automatically, developers are not expecting the ref to be expired. Instead, they expect the client to fetch the content they requested.Describe the solution you'd like
Currently, the error provides the master ref as part of the message:
We can extract the master ref from this error message and retry the request with the new ref.
When the client retries a request, the developer should be notified through a console warning.
If the retried request also has an expired ref, we can continue retrying until a valid ref is found. We can limit the number of retries to prevent infinite loops.
When a developer explicitly provides a ref, such as through
defaultParams
, a preview session, or on a per-query basis, the ref should be used as provided. The retry logic and console message should be skipped. This avoids a case where a developer is sure they want to use a specific ref. We should respect that decision and let them handle the error or change their code.Describe alternatives you've considered
Developers can already catch
RefExpiredError
and handle the retry themselves. That is a solution to a leaky abstraction and is not something we should ask developers to do.Developers can also configure their environments to not cache requests to
/api/v2
. This kind of configuration can be tricky to set up, however, and may introduce additional headaches.Additional context
This error most often comes from Next.js websites using the App Router. The App Router caches
fetch()
requests when configured properly, and we recommend caching all Prismic requests.The text was updated successfully, but these errors were encountered: