Repository navigation
perf: abort superseded block preview requests - #150
Merged
Merged
Conversation
Pass an AbortController signal to the single-block preview request and abort the previous one when a new one starts or the block unmounts. Aborted requests neither show the error state nor clear the preview.
Contributor
|
Included in Blockstudio 7.7.6, now officially released. This PR is merged into main as part of the reviewed release, with full CI and distribution checks passing for the release commit. |
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.
Editing a field schedules a single-block preview request 500 ms after the last change (
src/blocks/components/block/index.tsx:433-474). When the next edit lands while that request is still running, the old response is ignored throughrenderRequestId, but the request itself keeps going: the browser keeps the connection busy, downloads and parses a response nobody uses, and requests that have not reached the server yet are still sent.This passes an
AbortControllersignal toapiFetch(supported since@wordpress/api-fetch5.2.0, which rethrowsAbortError) and aborts the previous request when a new one starts and when the block unmounts. The catch handler returns early for aborted requests, so an abort never shows the error state or clears the current preview. PHP usually finishes a render that has already started, since it only notices a closed connection when it writes output, so this mainly saves client and connection work. The batch fetcher is unchanged because one batch request serves several blocks.Test: a new case in
tests/e2e/components/editor-audit.tsslows the render route to 1.5 s, edits a field three times with 800 ms pauses and expects two aborted requests, one completed request, the previous preview kept in place and the final value rendered. Against the current code it fails with 3 completed and 0 aborted requests; with the change it passes with 1 completed and 2 aborted.npm run checkpasses.