fix: video editor stuck on loading skeleton after popstate#1917
Open
kishan-gondaliya-7270 wants to merge 1 commit into
Open
fix: video editor stuck on loading skeleton after popstate#1917kishan-gondaliya-7270 wants to merge 1 commit into
kishan-gondaliya-7270 wants to merge 1 commit into
Conversation
…ton)
handlePopState unconditionally called resetStore() (attachmentAPI.util.resetApiState),
which clears the getAttachmentMeta cache. When the popstate does not change the
attachment id, <VideoEditor key={ attachmentID } /> does not remount and the
already-mounted useGetAttachmentMetaQuery hook does not refetch, leaving the
editor permanently on its loading skeleton. Guard handlePopState to no-op when
the attachment id is unchanged; only reset + reinitialise on an actual change.
Fixes #1916
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the Video Editor getting stuck on its loading skeleton after a popstate event by preventing unnecessary RTK Query cache resets when the attachment id hasn’t actually changed.
Changes:
- Adds a
useRefmirror ofattachmentIDto allowpopstatehandling without re-binding listeners on every render. - Guards the
popstatehandler to early-return (no-op) when the attachment id is unchanged, avoiding aresetStore()that would clear RTK Query cache without triggering a refetch.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
108
to
+112
| const newParams = new URLSearchParams( window.location.search ); | ||
| const newId = newParams.get( 'id' ); | ||
|
|
||
| if ( newId && ! isNaN( newId ) ) { | ||
| setRawID( newId ); | ||
| setAttachmentID( newId ); | ||
| } else { | ||
| setRawID( null ); | ||
| setAttachmentID( null ); | ||
| const normalizedId = newId && ! isNaN( newId ) ? newId : null; | ||
|
|
||
| // A popstate that does NOT change the current attachment must be a |
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.
Description
Fixes #1916.
The Video Editor (
admin.php?page=rtgodam_video_editor&id=<id>) becomes permanently stuck on its loading skeleton when apopstateevent fires while the editor is open.pages/video-editor/App.js'spopstatehandler unconditionally callsresetStore()→attachmentAPI.util.resetApiState(), which clears thegetAttachmentMetacache. When thepopstatedoes not change the attachment id,setAttachmentID(newId)sets the same value, so<VideoEditor key={ attachmentID } />does not remount and the mounteduseGetAttachmentMetaQueryhook does not re-fetch.isAttachmentConfigLoadingstaystrueforever → the loading skeleton is shown permanently.Fix
Guard
handlePopStateso it is a no-op when the attachment id is unchanged. It still resets the store and re-initialises when the attachment actually changes (back to the picker, or to a different video). AuseRefmirrors the currentattachmentIDso the handler can compare without re-subscribing the listener on every render.Evidence
On a fully-loaded editor, dispatching a single
popstate:…reverts the editor to the loading skeleton (
.loading-skeletoncount0 → 2, the Preview/Copy Block buttons disappear) and it never recovers (still skeleton after 6s). The attachment-meta request itself is healthy throughout — an in-pagefetch('/wp-json/wp/v2/media/<id>', { headers: { 'X-WP-Nonce': … } })returns 200 with a valid body in ~630ms — confirming it is the RTK cache being wiped without a refetch, not a network/auth issue.How to test
window.dispatchEvent( new PopStateEvent('popstate') )in the console.Notes
history.pushState('?item=…')) triggers apopstateon the editor and bricks it.🤖 Generated with Claude Code