prismicio / prismic-toolbar

An embeddable UI for Prismic content and previews directly on your website.
12 stars 19 forks source link

Listen for changes only if page is visible #75

Closed srenault closed 3 years ago

srenault commented 3 years ago

fixes prismicio/issue-tracker-wroom#298

veloce commented 3 years ago

Using https://developer.mozilla.org/en-US/docs/Web/API/Document/visibilityState

This property is supported by all browsers according to MDN. I tested locally and it works as expected: preview is refreshed when the browser page is visible (even if it has not the focus), and the refreshing is stopped when the page is hidden.

Heyrows commented 3 years ago

With these changes, a tab won't be updated unless it is fully visible. It means that the preview won't be updated when the changes occur but when the tab is visible.

For the dual screen it is a good thing. However, for a single screen with multiple tab, the preview will only be updated when the preview tab is selected, I don't know if this is acceptable.

Heyrows commented 3 years ago

I just tested the PR locally, it work as expected and I can confirm that if both tabs are on the same browser, the preview isn't updated if the tab is the not the active one.