Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: prevent infinite refreshes and exiting race condition #97

Merged
merged 3 commits into from
Jul 4, 2022

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented May 14, 2022

This PR addresses two related issues:

  1. Previews can sometimes get into a state where the page refreshes endlessly. See Bug: Prismic toolbar new tab refresh loop. #66 for details and how to reproduce the issue.
  2. When two preview windows for the same session are open, and one is exited, the other window will re-enable previews. This happens because the non-exited window is checking for preview updates on an interval and upserts (i.e. re-enables) the preview cookie that was deleted by the exiting window.

These issues are resolved by treating the preview state from the prismic.io iframe as the source of truth.

  • Before starting a preview session, check if a ref is present in the latest preview state. If not, there is no active preview session. The toolbar does not need to refresh the page.
  • On each interval where the toolbar checks for preview updates, first check if the preview cookie exists. If it does not, exit the preview.

This has the nice side-effect of exiting previews across all windows at once from a single toolbar "X" click.

Reproduction to test PR

This repo can be used as a test: https://github.com/angeloashmore/prismic-toolbar-issue-66-repro

Copy link
Member

@lihbr lihbr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look good to me, will test!

Can you review too @arnaudlewis?

@lihbr lihbr requested a review from arnaudlewis May 14, 2022 10:16
@angeloashmore
Copy link
Member Author

Awesome! Here's a repo to test the issue: https://github.com/angeloashmore/prismic-toolbar-issue-66-repro

@matheusrufinos
Copy link

Hello, do you have a date for merge/release this pull request? 🙏

@lihbr
Copy link
Member

lihbr commented Jun 22, 2022

Hey there, it should be released this week 👌

@scottgulliver
Copy link

Hi, just wondering if this is still planned for this/next week? We're currently blocked by this, and it comes at a crucial time where our client is evaluating CMS platforms 😅

@lihbr
Copy link
Member

lihbr commented Jul 1, 2022

Hey there,

First of all, I'm sorry for the extra delay, back and forth, and lack of visibility that has been going on with this pull request.

I synced with our DevOps team this morning about it, they scheduled it for Monday morning. If it doesn't happen then, I'll make sure to sync with them again to have it shipped.

Thank you for your understanding 🙏

@lihbr lihbr merged commit 196e7c6 into master Jul 4, 2022
@lihbr lihbr deleted the aa/fix-infinite-reload-and-exit-race-condition-2 branch July 4, 2022 11:20
@lihbr
Copy link
Member

lihbr commented Jul 4, 2022

This PR has been deployed, thanks for your patience! 🎉

Let us know if you encounter the issue again 🙏

@matheusrufinos
Copy link

@lihbr Thanks for the release!
Is the prismic toolbar automatically updated within the PrismicProvider or PrismicPreview? I say because I'm using Next.js and the implementation documentation doesn't mention a manual implementation of PrismicToolbar.

@lihbr
Copy link
Member

lihbr commented Jul 4, 2022

Yes, the toolbar is automatically updated for everyone. If you check the network tab you should see iframe.html being served from a 4.0.8 folder.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants