Skip to content

Preview and Cache causes draft to go 'live' immediately #143

@Zae

Description

@Zae

Description

When using the cache parameter (which is now default, since 2.7.0), using preview in the CMS causes the API to always return the preview version.

I believe this is because element-api always caches the request and does not check if the request is a preview request. In subsequent requests the cache is found and simply returned.

In 2.6.0 the preview was broken, but because the published version kept being served instead of the draft, now with the changes in 2.7.0 the cache is cleared when a draft is saved which causes the draft to be cached.

Steps to reproduce

  1. Enable cache in element-api (default)
  2. Supply the request with the correct X-Craft-Token
  3. Element-api fills cache with current draft
  4. Element-api serves cached draft version when requested without preview token

Additional info

  • Craft version: 3.6.17
  • PHP version: 7.4
  • Database driver & version: MySQL 8.0.25
  • Plugins & versions:
    • Element-api: 2.7.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions