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

fix: infinite reload bug and exit race condition #96

Closed

Conversation

angeloashmore
Copy link
Member

@angeloashmore angeloashmore commented May 14, 2022

A new PR will be opened that ports these changes without the style commits. Style changes (using Prettier + ESLint) will be moved to a separate PR.


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.

@angeloashmore angeloashmore marked this pull request as draft May 14, 2022 02:39
@angeloashmore
Copy link
Member Author

Closing in favor of #97.

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.

1 participant