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

Provide a way to detect if a preview session is active #268

Open
angeloashmore opened this issue Nov 3, 2022 · 0 comments
Open

Provide a way to detect if a preview session is active #268

angeloashmore opened this issue Nov 3, 2022 · 0 comments
Labels
enhancement New feature or request good first issue Good for newcomers v7 Getting addressed or related to version 7 of the kit

Comments

@angeloashmore
Copy link
Member

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

@angeloashmore angeloashmore added enhancement New feature or request good first issue Good for newcomers labels Nov 3, 2022
@angeloashmore angeloashmore added the v7 Getting addressed or related to version 7 of the kit label Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers v7 Getting addressed or related to version 7 of the kit
Projects
None yet
Development

No branches or pull requests

1 participant