Skip to content

perf: abort superseded block preview requests - #150

Merged
dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:perf/abort-stale-previews
Oct 22, 2026
Merged

dnnsjsk merged 1 commit into
inline0:mainfrom
Contributolo:perf/abort-stale-previews

Conversation

@Contributolo

Copy link
Copy Markdown
Collaborator

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 through renderRequestId, 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 AbortController signal to apiFetch (supported since @wordpress/api-fetch 5.2.0, which rethrows AbortError) 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.ts slows 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 check passes.

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.
@dnnsjsk
dnnsjsk merged commit 7b0a3c6 into inline0:main Oct 22, 2026
@dnnsjsk

dnnsjsk commented Oct 22, 2026

Copy link
Copy Markdown
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.

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.

2 participants