Repository navigation
Fix request tracking, media drag setup, and session-save loop - #962
Conversation
|
@claude can you review? Is there any other opportunity related to the 4th point but in other code paths that could leed to the await/kill tab behaviour? |
|
Claude finished @AllTerrainDeveloper's task in 2m 26s —— View job Review
Code reviewAll four fixes check out; each is a real, narrowly-scoped bug fix with clean regression coverage. 1. XHR 2. Heartbeat classification before auth retry ( 3. Media drag adapter init order ( 4. Session-save loop fix ( Other code paths with the same shape? (the question asked)I searched
So: no, I don't see another code path with this exact failure mode currently in the tree. The pattern that caused it (a loop awaiting a shared promise, combined with cleanup living inside the async body instead of chained via Per the PR's own "Scope and remaining uncertainty" section, this doesn't confirm or rule out the originally reported upload Wait/Kill freeze — it's a distinct, independently-reproduced bug class, and the PR is honest about that. No changes requested; the fixes and tests look correct as written. |
OpenStation could retain request callbacks, register duplicate Media drag listeners, retry failed Heartbeats unnecessarily, and enter an endless session-save loop after a synchronous request error. This PR fixes those four defects and adds behavioral regression coverage.
The fixes were identified while investigating Chrome becoming unresponsive during Media uploads and drag-and-drop into Gutenberg. The reported upload-related Wait/Kill freeze remains unconfirmed; this PR does not claim to resolve its root cause.
What changes
1. Release XHR callbacks when their request finishes.
The iframe bridge attached a new
loadendlistener on everysend()but left previous listeners attached. If an uploader or another script reused the same XHR object, later completions ran all earlier callbacks again, multiplying network reports and activity-end messages. Each listener is now removed when its request completes. Ifsend()throws synchronously, cleanup also removes the listener, balances the activity indicator, and rethrows the original error.2. Recognize Heartbeat requests before starting authentication recovery.
WordPress normally sends
action=heartbeatin the POST body. The bridge checked only the URL, so a Heartbeat response with status 401/403 could triggerheartbeat.connectNow()and immediately retry itself. The bridge now checks the URL and supported request-body formats before sending, then uses the result for both activity tracking and authentication recovery. Other requests still trigger normal authentication checks. The completion callbacks retain the classification flag without adding a reference to the upload body.3. Initialize the Media drag adapter before its first scan.
The adapter called
start()before assigning its selectors and delegation guard. Existing grid tiles could miss their initial enhancement, and resetting the guard after startup allowed a later list refresh to install duplicate drag handlers. Initializing these values first makes the initial scan work and keeps list drag handlers installed once.4. Clear the active session-save promise after it has been assigned.
A synchronous exception during request setup could run the async function's inline
finallybefore the surrounding assignment completed. Cleanup setactiveSavetonull, but the assignment then replaced it with the already-settled promise. The nextflush()repeatedly awaited that same promise, continuously scheduling microtasks and preventing timers and rendering from running.Cleanup now runs through the returned promise's
.finally(), after assignment. A regression test covers the failure and retry without allowing the defective implementation to hang the test worker.Evidence and validation
These are targeted reproductions, not measurements of typical upload performance:
The Heartbeat integration check uses the site's real WordPress Heartbeat and jQuery scripts in jsdom against a local HTTP server; neither
connectNow()nor jQuery AJAX is mocked. The session-save comparison uses Chrome 154 and isolates the defective code in a worker to protect the editing tab. The session-save report explains the mechanism and reproduction limits.Scope and remaining uncertainty
XHR callback amplification requires reuse of a native XHR object, which has not been established in the reported failing upload. Heartbeat retries were already bounded by the existing five-second cooldown. The session-save loop requires a synchronous request-setup exception; ordinary asynchronous network rejection does not trigger it, and the known in-tree flush caller is reload-after-deploy. The reproduction does not establish retained heap growth or a connection to the upload action.
The separate Media grid disappearance after an attachment-change refresh remains outside this patch. Public APIs and bridge payloads are unchanged.