-
Notifications
You must be signed in to change notification settings - Fork 62
Description
Is your feature request related to a problem? Please describe.
The only way to know if a preview session is active today is to manually check for Prismic's preview cookie. Even then, only checking for presence of the cookie is not sufficient; it must be parsed to determine if a session is active.
Knowing if a preview is active is useful for displaying preview-only UI, such as a banner letting a content writer know that they are previewing draft content.
Describe the solution you'd like
The client could provide a method that checks if a preview session is active. The client is scoped to a repository name, so the returned data could be specific to a repository. That level of specificity may be useful in sites that source content from multiple repositories.
The preview cookie is already automatically detected in resolvePreviewURL()
, which takes into account the global scope (i.e. document
) or a server request. The same logic could be used to support most runtimes.
Such a method could look like this:
client.isPreviewActive() // => true or false
Describe alternatives you've considered
Load the cookie, parse it, check if a specific repository name is present, return true or false. Very procedural and requires specific knowledge of Prismic's preview implementation.
Additional context
Feature requested by @samlfair