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

Differentiating between entry update types #858

Closed neilvanbeinum closed 2 weeks ago

neilvanbeinum commented 2 weeks ago

Hello,

We would like to integrate live previewing with our client app.

We would like to perform a simple page reloading to achieve this, as opposed to updating the DOM. We are using vanilla JS.

The issue we're facing is that the handler passed to the ContentfulLivePreview.subscribe function is called each time the page is reloaded. We would need to introduce a delay following reload to prevent an infinite reload loop. We'd prefer to avoid the delay.

Is there a way (either current or planned) to differentiate between updates fired from an entry update "directly" and entry updates following a page reload?

Thanks,

Neil

chrishelgert commented 2 weeks ago

👋 Do you subscribe to the save or edit (default) event? The edit event replays the last changes again - which could trigger the mentioned infinite loop, at the moment we have nothing to avoid this. Maybe the save event is what you could use for this approach (Note: the save event is coupled to the inspectorMode at the moment)

neilvanbeinum commented 2 weeks ago

Thank you for the reply, Chris.

I now understand that save event subscriptions are only triggered if the relevant entry is tagged on the page.

We'll go and have a think about whether we want to go down that route for our specific use case.

Thanks again. I'll close the issue.

chrishelgert commented 2 weeks ago

Created a ticket for us internally too, to give the opportunity to disable the tagged element check