View Transitions: Fix InvalidStateError on bfcache navigations#2438
Merged
westonruter merged 3 commits intotrunkfrom Apr 7, 2026
Merged
View Transitions: Fix InvalidStateError on bfcache navigations#2438westonruter merged 3 commits intotrunkfrom
westonruter merged 3 commits intotrunkfrom
Conversation
When a page is restored from the back-forward cache (bfcache), the browser creates a ViewTransition object on the pageswap/pagereveal events but immediately skips it since no old-page snapshot is available. The ViewTransition.ready and ViewTransition.finished promises reject with "InvalidStateError: Transition was aborted because of invalid state", reported as "Uncaught (in promise)" since no rejection handler was attached. Fix: attach no-op .catch() handlers to both promises at the top of each event handler to prevent unhandled promise rejections. See https://wordpress.org/support/topic/invalidstateerror-transition-was-aborted-because-of-invalid-state-wordpress/ Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
df37ea2 to
8592afb
Compare
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Member
Author
|
Build for testing: |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Co-authored-by: Mukesh Panchal <mukeshpanchal27@users.noreply.github.com>
946cbc8 to
5cd3adf
Compare
Member
|
@westonruter Just pushed 71557ea that fix JS lint |
mukeshpanchal27
approved these changes
Apr 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This addresses an issue reported in a support topic.
I was able to reproduce the issue when going back/forward in the browser. I'd see in the console:
This goes away with the fix in this PR.
Summary (via Claude Code)
Fixes
Uncaught (in promise) InvalidStateError: Transition was aborted because of invalid stateerrors that occur on every back-forward cache (bfcache) navigation.Problem
When a user navigates back/forward and the page is restored from the bfcache, the browser still fires
pageswapandpagerevealevents with aViewTransitionobject — however, the transition is immediately skipped because no old-page snapshot is available for a bfcache restoration. This causes theViewTransition.readyandViewTransition.finishedpromises to reject with anInvalidStateError. Since the plugin's event handlers never attached rejection handlers to these promises, the browser reports them asUncaught (in promise)errors.This was reported as a significant uptick in Sentry errors, particularly on Chrome 146+ (mobile and desktop), affecting all pages on the site.
Fix
In both the
pageswapandpagerevealevent handlers, no-op.catch()handlers are attached toevent.viewTransition.readyandevent.viewTransition.finishedimmediately — before any other interaction with the transition object. This marks the promises as handled, so when they reject due to an aborted transition (as happens with bfcache restorations), the browser no longer reports unhandled promise rejection errors.The rest of the handler logic (calling
types.add(), setting temporary view transition names) continues to work normally for regular navigations where the transition is valid.Use of AI Tools
I provided the support topic to Claude Code and it came up with the fix. No error now appears in the console for me.