Skip to content

Upload Media: Public API for registering upload operations - #83331

Draft
swissspidy wants to merge 2 commits into
try/82035-upload-queue-registryfrom
try/82035-upload-operation-api
Draft

swissspidy wants to merge 2 commits into
try/82035-upload-queue-registryfrom
try/82035-upload-operation-api

Conversation

@swissspidy

@swissspidy swissspidy commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

What?

See #82035. Step 2 of the rollout plan in #82035 (comment): the public API on top of the registry from #82474.

Stacked on #82474 — the diff here is only the public surface; the base branch is try/82035-upload-queue-registry and will be retargeted to trunk once that merges.

Adds to @wordpress/upload-media:

  • registerUploadOperation( name, settings )
  • unregisterUploadOperation( name )
  • getUploadOperation( name ) / getUploadOperations()
  • registerUploadConcurrencyPool( name, { limit } )
  • context.createBlobURL( file ) on the handler context
  • UploadOperationType, UploadOperationArgs and the UploadOperation* types.

Why?

#82474 rebuilt the queue on a registry but exposed nothing; core registers its steps through private store actions. This is the surface a plugin uses, shaped after registerFormatType(): name first, settings second, an object back on success and undefined plus a console error on rejection.

Things the proposal specified differently from what the private contract had, settled here at the boundary:

  • Handlers and plans get a snapshot of their item, not the queue's own record. Same File objects, the item's identity (id, parentId, batchId), and whatever earlier steps set aside — but no callbacks, no abort controller, no pipeline. It's frozen and additionalData is copied, so writing to it changes nothing in the store; updates go through the handler's result. The fields it carries are derived from PROTECTED_ITEM_KEYS, the same list that decides what a result may set, so what a step may write, the next step may read.
  • Pools have a registration function, since Upload Media: Rebuild the upload queue on an operation registry #82474 made them a registry of their own.
  • updateProgress stays 0–100, which is what the store holds and the UI reads; the proposal's 0..1 was a sketch.

Two additions that came out of the step-3 proofs of concept (#83333 in particular):

  • context.createBlobURL( file ). A preview URL has to outlive the handler — the editor shows it until the server's URL replaces it — so a handler cannot revoke it, and a plugin had no way into the list the queue revokes with the item. This creates the URL and records it against the item, the same thing core's steps do by hand with the private CacheBlobUrl action. Explicit rather than sniffing attachment.url, so it works for any field a plugin puts the URL in.
  • UploadOperationArgs is exported and the README says which core steps take arguments, because a replacement of a core step receives the arguments core placed it with and has to understand them. The README also notes that core only places core/transcode-image when the site asks for a conversion, so a replacement meant to run on every image plans itself in.

How?

The store's dispatch() resolves through a promise, so a wrapper that merely dispatched the thunk could not return the registered operation synchronously the way registerBlockType() does. The checks the thunks run were extracted into store/utils/registry.ts; the public functions run them first and dispatch only what will go through, and the thunks call the same helpers. One set of messages, two callers.

snapshotItem() in store/utils/operations.ts builds the item snapshot; runOperation and planOperations hand it to handlers and plans. createOperationContext() gains createBlobURL.

The README gets an "Upload operations" section covering registration, planning, the handler contract, pools and core's operations, and the API reference token now covers the package index. docgen does not document TypeScript types, so the type exports appear as "Undocumented declaration.", as they do in @wordpress/block-editor and others.

Testing Instructions

npm run test:unit -- packages/upload-media

  • src/test/upload-operations.ts — the public functions against the default registry: register/get/unregister, the name argument winning over settings.name, rejections returning undefined with the store's message, replacing core/finalize and putting it back, pool registration and an operation joining an unregistered pool.
  • src/store/test/operations.ts — "hands the handler a snapshot of its item" (frozen; no status/operations/abortController/onSuccess; a write to additionalData does not reach the store), "hands a plan the same snapshot", and "revokes a blob URL a handler created when the item leaves".

483 tests pass in upload-media; npm run typecheck, eslint and lint:published-deps are clean.

Testing Instructions for Keyboard

N/A — no UI changes.

Screenshots or screencast

N/A.

Use of AI Tools

Authored with Claude Code: the implementation, tests and this description. Design decisions (item snapshot, progress scale, sync registration via shared validation, createBlobURL on the context) were reviewed and settled in discussion before implementation.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Sr7G5nRsbso744zkruyGHZ

registerUploadOperation, unregisterUploadOperation, getUploadOperation,
getUploadOperations and registerUploadConcurrencyPool, wrapping the
store's registry the way registerFormatType wraps the rich-text store.
Each answers on the spot: a dispatched thunk only reports back through a
promise, so the same checks the thunks run now live in one place and the
public functions run them before dispatching anything that would not go
through.

Handlers and plans are handed a snapshot of their item rather than the
queue's own record: the same File objects, the item's identity, and
whatever earlier steps set aside, but none of the callbacks, the abort
controller or the pipeline. The snapshot is frozen and additionalData is
copied, so writing to it changes nothing; updates go through the result.
The fields it carries are derived from the same list that decides what a
result may set, so what a step may write, the next step may read.

The README documents the contract and the architecture doc points at it.
The API reference token now covers the package's index; docgen does not
document TypeScript types, so the type exports show as undocumented, as
they do in other packages.

Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sr7G5nRsbso744zkruyGHZ
@swissspidy swissspidy added [Type] Enhancement A suggestion for improvement. [Feature] Client Side Media Media processing in the browser with WASM labels Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

📦 Bundle size

Size Change: +270 B (0%)

Total Size: 8.21 MB

📦 View Changed
Filename Size Change
build/scripts/upload-media/index.min.js 18.3 kB +270 B (+1.5%)

8f5fbd7 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 15fc986 try/82035-upload-queue-registry % Change
timeToFirstByte 45.45 ms +10.56% -5.94% 43.55 ms +10.68% -2.41% 4.36%
largestContentfulPaint 76 ms +0% -5.26% 78 ms +2.56% -7.69% -2.56%
lcpMinusTtfb 28.9 ms +1.9% -6.23% 33.1 ms +9.67% -13.6% -12.69%
wpBeforeTemplate 21.97 ms +22.67% -1.37% 21.78 ms +8.4% -0.83% 0.87%
wpTemplate 18.7 ms +3.42% -5.72% 18.53 ms +2.27% -4.16% 0.92%
wpTotal 42.26 ms +9.99% -6.79% 40.36 ms +11.3% -2.08% 4.71%
wpMemoryUsage 7.59 MB +0% -0% 7.59 MB +0% -0% 0.07%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric 15fc986 try/82035-upload-queue-registry % Change
timeToFirstByte 35.75 ms +5.31% -1.12% 36.3 ms +9.64% -2.75% -1.52%
largestContentfulPaint 80 ms +0% -0% 80 ms +10% -0% 0%
lcpMinusTtfb 44.25 ms +0.9% -1.13% 44.6 ms +3.25% -3.48% -0.78%
wpBeforeTemplate 19.21 ms +3.49% -0.78% 19.33 ms +10.19% -1.14% -0.62%
wpTemplate 13.8 ms +2.17% -1.09% 13.94 ms +6.46% -2.22% -1%
wpTotal 33.1 ms +6.16% -1.03% 33.55 ms +10.49% -2.12% -1.34%
wpMemoryUsage 6.21 MB +0% -0% 6.20 MB +0% -0% 0.09%
wpDbQueries 14 +0% -0% 14 +0% -0% 0%

media-processing

Metric 15fc986 try/82035-upload-queue-registry % Change
mediaProcessingJpeg 324.68 ms +2.01% -1.55% 322.69 ms +1.68% -1.02% 0.62%
mediaProcessingAvif 4798.51 ms +0.04% -0.51% 4760.84 ms +0.11% -0.16% 0.79%
mediaProcessingJpegToAvif 3341.37 ms +0.22% -0.16% 3340.46 ms +0.26% -0.15% 0.03%

media-upload

Metric 15fc986 try/82035-upload-queue-registry % Change
jpegUploadProcessing 1430.03 ms +1.04% -1.69% 1416.53 ms +2.2% -0.97% 0.95%
pngUploadProcessing 174.2 ms +4.7% -5.55% 171.78 ms +3.33% -1.65% 1.41%
largeJpegUploadProcessing 1406.31 ms +1.13% -0.69% 1406.65 ms +0.48% -0.72% -0.02%
multipleImageUploadProcessing 1488.53 ms +0.4% -0.68% 1496.14 ms +0.8% -1.23% -0.51%

post-editor

Metric 15fc986 try/82035-upload-queue-registry % Change
serverResponse 513.83 ms +5.95% -4.24% 514.04 ms +2.81% -9.38% -0.04%
firstPaint 253.27 ms +16.58% -8.3% 243.08 ms +25.36% -6.07% 4.19%
domContentLoaded 1089.15 ms +3.52% -3.18% 1081.94 ms +1% -2.14% 0.67%
loaded 1090.76 ms +3.49% -3.23% 1083.15 ms +0.99% -2.14% 0.7%
firstContentfulPaint 452.54 ms +1.58% -4.57% 445.83 ms +1.69% -4.39% 1.51%
firstBlock 3284.69 ms +3.08% -0.94% 3266.16 ms +1.34% -1.19% 0.57%
type 19.69 ms +5.69% -5.18% 20.5 ms +3.56% -4.44% -3.95%
typeWithoutInspector 19.66 ms +4.37% -5.8% 19.48 ms +5.24% -4.31% 0.92%
typeWithTopToolbar 27.74 ms +4.97% -2.42% 23.38 ms +10.39% -3.17% 18.65%
typeContainer 8.95 ms +1.9% -7.37% 8.72 ms +7.57% -6.65% 2.64%
focus 71.27 ms +8.46% -2.99% 74.41 ms +9.76% -4.65% -4.22%
firstFocus 195.58 ms +0% -0% 211.91 ms +0% -0% -7.71%
selectAll 527.29 ms +6.8% -4.86% 524.09 ms +4.33% -0.91% 0.61%
listViewOpen 73.35 ms +3.91% -10.17% 76.1 ms +9.63% -8.09% -3.61%
inserterOpen 23.73 ms +3.08% -1.22% 21.75 ms +20.41% -4.69% 9.1%
inserterHover 2.88 ms +6.25% -6.94% 2.83 ms +10.25% -7.42% 1.77%
inserterSearch 7.45 ms +2.82% -4.3% 7.86 ms +14.38% -10.81% -5.22%
loadPatterns 628.99 ms +5.57% -2.06% 641.25 ms +14.96% -5.52% -1.91%
wpTotal 503.76 ms +6.05% -4.25% 504.22 ms +2.79% -9.51% -0.09%
wpMemoryUsage 13.13 MB +0% -0% 13.12 MB +0% -0% 0.07%
wpDbQueries 54 +0% -1.85% 54 +0% -1.85% 0%

site-editor

Metric 15fc986 try/82035-upload-queue-registry % Change
serverResponse 509.23 ms +3.5% -5.04% 499.52 ms +7.23% -4.96% 1.94%
firstPaint 265.02 ms +3.62% -2.36% 235.28 ms +20.44% -9.3% 12.64%
domContentLoaded 1146.62 ms +0.69% -0.83% 1147.51 ms +1.48% -1.8% -0.08%
loaded 1148.1 ms +0.69% -0.82% 1148.75 ms +1.49% -1.8% -0.06%
firstContentfulPaint 457.93 ms +2.38% -1.14% 456.61 ms +0.83% -1.77% 0.29%
firstBlock 4218.77 ms +0.3% -0.52% 4255.3 ms +0.62% -0.9% -0.86%
type 19.8 ms +3.89% -2.27% 20.39 ms +4.02% -3.29% -2.89%
navigate 119.26 ms +8.91% -5.79% 121.07 ms +8.39% -9.59% -1.5%
loadPatterns 1312.31 ms +13.33% -5.3% 1312.25 ms +4.35% -5.5% 0%
loadPages 1065.95 ms +3.55% -1.32% 1095.01 ms +1.85% -1.44% -2.65%
wpTotal 499.17 ms +3.66% -5.14% 489.39 ms +7.42% -4.93% 2%
wpMemoryUsage 12.11 MB +0% -0% 12.10 MB +0% -0% 0.04%
wpDbQueries 43 +2.33% -0% 43.5 +1.15% -1.15% -1.15%

8f5fbd7 Run

A preview URL has to outlive the handler that made it: the editor shows
it until the server's URL replaces it, so a handler cannot revoke it and
a plugin had no way into the list the queue revokes with the item.
context.createBlobURL( file ) creates the URL and records it against
the item, the same way core's steps do by hand.

A replacement of a core step receives the arguments core placed the
step with, so UploadOperationArgs is exported and the README says which
core steps take arguments, and that core/transcode-image is only placed
when the site asks for a conversion.

Co-authored-by: Pascal Birchler <pascal.birchler@gmail.com>
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Sr7G5nRsbso744zkruyGHZ

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Feature] Client Side Media Media processing in the browser with WASM [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants