Skip to content

Upload Media: Dominant color test plugin as a consumer of the operation API - #83332

Draft
swissspidy wants to merge 1 commit into
try/82035-upload-operation-apifrom
try/82035-upload-operation-dominant-color
Draft

swissspidy wants to merge 1 commit into
try/82035-upload-operation-apifrom
try/82035-upload-operation-dominant-color

Conversation

@swissspidy

Copy link
Copy Markdown
Member

What?

See #82035. First of the step-3 proofs of concept for the upload operation API: a plugin that adds a step to the upload pipeline and sends what it computed to the server.

Stacked on #83331 (which is stacked on #82474). The diff here is only the test plugin and its spec.

Why?

The proposal's third step is to prove the API from a plugin before promoting anything to core. This is the smallest useful consumer: a plan() that places a step before core/upload, a handler that reads the file in the browser and returns additionalData, and nothing that reaches into the queue. It validates, from outside the package:

  • the wp-upload-media script handle and the wp.uploadMedia global carry the API;
  • plan() placement with { before: 'core/upload' }, and skipping non-images;
  • the handler's item snapshot (item.file is the file as core prepared it — for HEIC that is the converted JPEG);
  • additionalData returned by a handler reaches the server as a field of the create request.

How?

packages/e2e-tests/plugins/upload-operation-dominant-color.php registers a dominant_color REST field on attachments (kept as post meta, validated as a lowercase hex color) and enqueues the script with wp-upload-media as a dependency.

packages/e2e-tests/plugins/upload-operation-dominant-color/index.js registers gutenberg-test/dominant-color. The handler decodes the image with createImageBitmap, draws it at ≤64px onto an OffscreenCanvas, bins pixels by color (8 levels per channel) weighted by opacity, and returns the mean of the heaviest bin as { additionalData: { dominant_color } }. A file the browser cannot decode returns nothing rather than failing the upload.

test/e2e/specs/editor/various/upload-operation-dominant-color.spec.js activates the plugin, uploads 10x10_e2e_test_image_green.png through the Image block, drains the queue, and reads the attachment back through the REST API expecting dominant_color: '#00ff00'. The fixture is half #00ff00 and the rest white at two opacities, so the answer is unambiguous but not trivial. A second test checks the operation is visible through getUploadOperation().

Testing Instructions

npm run test:e2e -- test/e2e/specs/editor/various/upload-operation-dominant-color.spec.js

The spec skips itself where client-side media processing is inactive, like the other upload specs. I could not run it locally (no Docker in this environment), so CI is the first run; the plugin JS and the spec pass eslint, the PHP passes phpcs.

Testing Instructions for Keyboard

N/A — no UI changes.

Screenshots or screencast

N/A.

Use of AI Tools

Authored with Claude Code: the plugin, the spec and this description.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Sr7G5nRsbso744zkruyGHZ


Generated by Claude Code

An e2e test plugin that uses the public registration API the way a
plugin would: one step planned before core/upload, a handler that reads
the image in the browser and returns additionalData, and nothing that
reaches into the queue. The color travels as a field of the upload
request, which the plugin's PHP side accepts on the media endpoint,
keeps as post meta and exposes on the attachment.

The spec uploads the green fixture, half #00ff00 and the rest white at
two opacities, and reads the color back through the REST API. It runs
from outside the package, so it proves the script handle, the global,
the plan placement, the handler contract and the additionalData route
together, not just the store.

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
@github-actions github-actions Bot added the [Package] E2E Tests /packages/e2e-tests label Sep 22, 2026
@swissspidy swissspidy added [Type] Enhancement A suggestion for improvement. [Feature] Client Side Media Media processing in the browser with WASM [Package] E2E Tests /packages/e2e-tests and removed [Package] E2E Tests /packages/e2e-tests labels Sep 22, 2026
@github-actions

github-actions Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

📦 Bundle size

Size Change: 0 B

Total Size: 8.21 MB

6ea06dd Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric b5a9312 try/82035-upload-operation-api % Change
timeToFirstByte 49.05 ms +3.98% -1.33% 49.9 ms +9.42% -3.81% -1.7%
largestContentfulPaint 84 ms +4.76% -4.76% 84 ms +4.76% -4.76% 0%
lcpMinusTtfb 32 ms +14.22% -2.81% 32.75 ms +17.86% -4.43% -2.29%
wpBeforeTemplate 23.57 ms +7.59% -2.33% 23.6 ms +8.35% -2.54% -0.13%
wpTemplate 22.02 ms +1.68% -2.18% 22.2 ms +4.82% -4.14% -0.81%
wpTotal 45.58 ms +3.86% -2.13% 46.22 ms +8.11% -4.26% -1.38%
wpMemoryUsage 7.59 MB +0% -0% 7.58 MB +0% -0% 0.08%
wpDbQueries 17 +0% -0% 17 +0% -0% 0%

front-end-classic-theme

Metric b5a9312 try/82035-upload-operation-api % Change
timeToFirstByte 40 ms +7.13% -2.87% 40.4 ms +2.48% -2.1% -0.99%
largestContentfulPaint 90 ms +4.44% -2.22% 90 ms +2.22% -2.22% 0%
lcpMinusTtfb 49.6 ms +4.03% -3.02% 49.65 ms +3.22% -3.52% -0.1%
wpBeforeTemplate 20.44 ms +2.69% -3.28% 20.41 ms +2.01% -2.6% 0.15%
wpTemplate 16.66 ms +3.84% -5.04% 16.63 ms +2.77% -3.49% 0.18%
wpTotal 37.11 ms +6.14% -3.37% 37.44 ms +2.3% -2.35% -0.88%
wpMemoryUsage 6.21 MB +0% -0% 6.20 MB +0% -0% 0.1%
wpDbQueries 14 +0% -0% 14 +0% -0% 0%

media-processing

Metric b5a9312 try/82035-upload-operation-api % Change
mediaProcessingJpeg 383.77 ms +0.53% -0.4% 385.04 ms +1.03% -1% -0.33%
mediaProcessingAvif 5608.49 ms +0.11% -0.13% 5606.68 ms +0.41% -0.08% 0.03%
mediaProcessingJpegToAvif 3835.06 ms +0.14% -0.06% 3820.8 ms +0.33% -0.17% 0.37%

media-upload

Metric b5a9312 try/82035-upload-operation-api % Change
jpegUploadProcessing 1448.08 ms +0.88% -1.98% 1414.23 ms +1.03% -1.08% 2.39%
pngUploadProcessing 210.88 ms +5.58% -4.08% 193.89 ms +9.49% -2.82% 8.76%
largeJpegUploadProcessing 1407.24 ms +1.27% -1.06% 1404.86 ms +0.8% -0.55% 0.17%
multipleImageUploadProcessing 1500.9 ms +3.42% -1.01% 1490.26 ms +1.75% -0.25% 0.71%

post-editor

Metric b5a9312 try/82035-upload-operation-api % Change
serverResponse 514.19 ms +1.05% -7.34% 512.76 ms +2.69% -4.42% 0.28%
firstPaint 242.52 ms +8.98% -5.49% 231.73 ms +7.29% -12.62% 4.66%
domContentLoaded 1104.38 ms +2.9% -0.55% 1118.29 ms +1.71% -3.53% -1.24%
loaded 1105.81 ms +2.89% -0.56% 1119.8 ms +1.67% -3.53% -1.25%
firstContentfulPaint 455.5 ms +2.86% -1.78% 448.06 ms +5.79% -0.68% 1.66%
firstBlock 3283.48 ms +2.17% -0.65% 3319.84 ms +0.54% -0.75% -1.1%
type 19.3 ms +14.72% -0.78% 21 ms +4.33% -3.67% -8.1%
typeWithoutInspector 19.17 ms +11.68% -1.04% 21.93 ms +3.78% -4.61% -12.59%
typeWithTopToolbar 24.88 ms +2.37% -1.77% 26.35 ms +4.33% -2.39% -5.58%
typeContainer 9.31 ms +5.37% -10.74% 10.11 ms +2.77% -9% -7.91%
focus 83.24 ms +3.75% -7.18% 81.23 ms +6.54% -5.5% 2.47%
firstFocus 233.42 ms +0% -0% 214.91 ms +0% -0% 8.61%
selectAll 554.37 ms +7.79% -3.58% 529.83 ms +5.82% -1.58% 4.63%
listViewOpen 81.8 ms +8.69% -6.47% 77.4 ms +6.14% -9.28% 5.68%
inserterOpen 24.93 ms +2.33% -3.09% 22.79 ms +10.05% -3.29% 9.39%
inserterHover 3.31 ms +11.78% -6.04% 3 ms +9.33% -4.67% 10.33%
inserterSearch 8.33 ms +12.36% -15.13% 7.4 ms +2.97% -8.11% 12.57%
loadPatterns 663.33 ms +2.21% -2.24% 669.58 ms +3.94% -4.84% -0.93%
wpTotal 504.14 ms +0.98% -7.37% 502.48 ms +2.72% -4.42% 0.33%
wpMemoryUsage 13.13 MB +0% -0% 13.12 MB +0% -0% 0.07%
wpDbQueries 54 +0% -0% 54 +0% -0% 0%

site-editor

Metric b5a9312 try/82035-upload-operation-api % Change
serverResponse 319.24 ms +1.62% -12.52% 315.32 ms +1.76% -1.87% 1.24%
firstPaint 190.15 ms +16.07% -10.53% 180.65 ms +13.56% -7.17% 5.26%
domContentLoaded 878.99 ms +2.96% -2.08% 859.67 ms +1.32% -0.31% 2.25%
loaded 880.01 ms +2.95% -2.09% 860.62 ms +1.32% -0.31% 2.25%
firstContentfulPaint 362.89 ms +3.04% -4.25% 349.64 ms +1.29% -1.18% 3.79%
firstBlock 3080.79 ms +1.18% -0.68% 3081.09 ms +0.53% -0.77% -0.01%
type 16.4 ms +6.95% -2.56% 17.25 ms +3.88% -8.06% -4.93%
navigate 100.65 ms +2.94% -3.51% 114.78 ms +0.68% -7.87% -12.31%
loadPatterns 986.92 ms +16% -11.25% 1011.06 ms +4.29% -5.32% -2.39%
loadPages 1035.61 ms +1.44% -2.58% 1034.16 ms +0.23% -1.31% 0.14%
wpTotal 310.8 ms +1.68% -12.9% 306.06 ms +2.05% -1.65% 1.55%
wpMemoryUsage 12.11 MB +0% -0% 12.10 MB +0% -0% 0.05%
wpDbQueries 44 +0% -2.27% 43.5 +1.15% -1.15% 1.15%

6ea06dd Run

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 [Package] E2E Tests /packages/e2e-tests [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants