Skip to content

Server Error on Live Preview #158

@mihob

Description

@mihob

Description

If x-craft-live-preview parameter is present in request and cache is present in element-api config for endpoint, the element api request results in an server error with the following log message:

[error][craft\elementapi\controllers\DefaultController::actionIndex] Error resolving Element API endpoint: Setting unknown property: craft\elementapi\resources\ElementResource::cache

This in src/DefaultController.php seems to be the problem:

// Before anything else, check the cache
if (!($this->request->getIsPreview() || $this->request->getIsLivePreview())) {
    $cache = ArrayHelper::remove($config, 'cache', true);
} else {
    $cache = false;
}

cache should probably always be removed from $config. The error was introduced in commit fb92fef

Steps to reproduce

  1. cache must be present in element-api config for endpoint
  2. Call element api endpoint with x-craft-live-preview parameter present in url

Additional info

  • Craft CMS version: 3.7.20
  • Element API version: 2.8.3
  • PHP version: 8.0.10
  • Database driver & version: 8.0.27
  • Plugins & versions:
    • Amazon S3 1.3.0
    • Control Panel CSS 2.4.0
    • Element API 2.8.3
    • Enforce password 1.0.4.2
    • Logs 3.0.4
    • Neo 2.11.17
    • Redactor 2.8.8
    • Redactor Anchors 1.1.0
    • Restrict 2.0.3
    • Sentry Logger 1.1.7
    • Typed link field 1.0.25

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