contentful / live-preview

Preview SDK for both the field tagging connection + live content updates
https://www.contentful.com/developers/docs/tutorials/general/live-preview/
MIT License
63 stars 13 forks source link

"Invalid live updates subscription detected" error if entry contains circular entry reference - REST API #847

Open dndrsn opened 3 weeks ago

dndrsn commented 3 weeks ago

Describe the bug

ContentfulLivePreview.subscribe (and useContentfulLiveUpdates) return the following error when attempting to subscribe to a REST API entry that contains a circular reference.

 [Live Preview]: Invalid live updates subscription detected.
            Please keep in mind that the data provided to the live updates needs to have "sys.id", "fields" for REST or the "__typename" for GraphQL on the data structure.

The data object provided is not transformed and does have both sys.id and fields properties as can been seen in the error message itself:

image

This issue may be a problem with the CMS console endpoint that handles the subscription requests, not this codebase.

To Reproduce Steps to reproduce the behavior:

  1. Create a content model with a reference field.
  2. Create two entries using the model, each with references to the other.
  3. Create a web page that uses useContentfulLiveUpdates or ContentfulLivePreview.subscribe to subscribe to the REST data for one of those entries
  4. Open page within live preview
  5. Change content data -> data does not update in live preview frame
  6. View browser log. Notice warning noted above.

Expected behavior No console warning. Live update to data on page in live preview frame.

Context (please complete the following information):

dndrsn commented 3 weeks ago

On further investigation, useContentfulLiveUpdates and ContentfulLivePreview.subscribe return the error if the entry being subscribed to contains a circular reference. For example if an entry has a reference to another entry and that entry has a reference to the original entry. The reference can be via a reference(s) type field or via a entry link within a rich text field.

Updating the issue title and description updated (again).

chrishelgert commented 2 weeks ago

👋 Hey, thanks for bringing this up - we will have a look 👀