prismicio/prismic-toolbar

Bug: Prismic toolbar new tab refresh loop.

Closed this issue · 6 comments

In certain situations, the prismic toolbar goes into a refresh loop.

Steps to reproduce.

  1. Start a new preview session in a certain page.
  2. Open another page in a new tab. For some reason this only works on pages that are slower to load, or maybe that have a lot of javascript in them.
  3. Close the preview session from the new tab.
  4. The new tab page goes into a refresh loop, refreshing over and over and over again.

This actually managed to take our server down from getting hammered by the refresh loop. (It was on a heavy data export page). Please fix it, as we are using a messy workaround in the meantime.

I have the same problem where my page gets stuck in a refresh loop right after hitting "Save" in Prismic. It happens when the page takes more than 3 seconds to load. (eg. Long time to first byte)

Cause:
I think it's related to the following function updatePreview() which is called every 3 seconds:

async updatePreview() {
const { reload, ref } = await this.client.updatePreview();
this.start(ref);
if (reload) { reloadOrigin(); }
}

What happens is

  1. reloadOrigin() is called for the first time (after changes are made on Prismic)
  2. The page starts reloading...
  3. After 3 seconds, reloadOrigin is called again. But this will automatically cancel the previous reload.
  4. The page starts reloading again
  5. and so on...

Potential fix:
call reloadOrigin only if there is no other reload in progress.

I'm happy to submit a PR for this if you want.

call reloadOrigin only if there is no other reload in progress.

Or simpler, just call this.cancelPreviewUpdates() before calling reloadOrigin()

@danielhuggins If you see some request to your page with the status (canceled) (eg. in Chrome DevTools > Network tab), then it means you may have the same bug

Hey @danielhuggins @paulnta, PR #97 should address the issue. It is pending a review.

@danielhuggins - The fix in your PR has been included in #97. Thanks for that fix! 👍

PR #97 has been merged and deployed. The latest version of the toolbar, v4.0.8, should not experience infinite refreshes as described in this issue.

If you experience infinite refreshing please reply here or open a new issue. Thanks! 🙂