Skip to content

Media editor: Add a panel context facade over the session - #85424

Closed
ramonjd wants to merge 2 commits into
trunkfrom
add/media-editor-panel-context
Closed

ramonjd wants to merge 2 commits into
trunkfrom
add/media-editor-panel-context

Conversation

@ramonjd

@ramonjd ramonjd commented Oct 23, 2026 •

Copy link
Copy Markdown
Member

What

useMediaEditorPanelContext(): what a sidebar panel may read and do. Media type, image and saving flags, whether there is anything to save, the aspect-ratio preset with its options and setter, quarter-turn rotation, and horizontal and vertical flip. Internal for now; nothing exports it yet.

Why

A sidebar panel (#84664) could reach useMediaEditor(), which hands out the whole session: the cropper controller with its state shape, setters, gestures and image loading. Public means frozen, and removing any of that later needs a deprecation cycle; adding to a facade later does not. This is what the next PR of #79175 exports to plugins, in place of the session.

What changed

  • useMediaEditorPanelContext() beside the frame context in the editor component, built from the frame context and the session. The frame context carries mediaType for it.
  • Named edits stay out of it. session.edits, set with setEdit, is session state for the editor's own edit pipeline: isDirty counts it, so Reset clears it, but hasOutputEdits does not, the unsaved-changes check and Save ignore it, and nothing saves it. The architecture note and doc comments say so, a comment at hasChanges says why, and a state test pins it. Applying named edits to the output is the edit pipeline's job and a separate change.
  • A browser test drives the editor through the facade: reads the media type and saving flag, picks the square preset, rotates, flips, and checks the session followed.

A sidebar panel could reach `useMediaEditor()`, which hands out the whole
session: the cropper controller with its state shape, setters, gestures and
image loading. Public means frozen, and removing any of that later needs a
deprecation cycle, while adding to a facade later costs nothing.

`useMediaEditorPanelContext()` gives a panel the media type, the image and
saving flags, whether there is anything to save, the aspect-ratio preset
with its options and setter, a quarter-turn rotation and the two flips. It
is built from the frame context, which now carries the media type, and the
session. Internal for now; nothing exports it yet.
@ramonjd ramonjd added the [Type] Enhancement A suggestion for improvement. label Oct 23, 2026
@github-actions

github-actions Bot commented Oct 23, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground

📦 Bundle size

Size Change: +9 B (0%)

Total Size: 9.06 MB

📦 View Changed
Filename Size Change
build/scripts/editor/index.min.js 620 kB +9 B (0%)

4070267 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 328b484 trunk % Change
timeToFirstByte 40.9 ms +8.8% -4.77% 38.25 ms +10.59% -2.61% 6.93%
largestContentfulPaint 72 ms +5.56% -8.33% 64 ms +6.25% -0% 12.5%
lcpMinusTtfb 30 ms +5.67% -13.5% 25.85 ms +6.58% -6.19% 16.05%
wpBeforeTemplate 20.84 ms +13.77% -4.61% 19.87 ms +13.03% -1.76% 4.88%
wpTemplate 15.94 ms +3.07% -2.07% 15.25 ms +4.13% -7.21% 4.52%
wpTotal 37.44 ms +6.92% -4.91% 35.22 ms +9.26% -2.98% 6.3%
wpMemoryUsage 7.67 MB +0% -0% 7.64 MB +0% -0% 0.43%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 328b484 trunk % Change
timeToFirstByte 29.15 ms +4.12% -2.4% 32.35 ms +7.11% -4.17% -9.89%
largestContentfulPaint 68 ms +0% -5.88% 72 ms +5.56% -0% -5.56%
lcpMinusTtfb 36.35 ms +6.88% -1.79% 39.95 ms +2.88% -5.26% -9.01%
wpBeforeTemplate 17.34 ms +4.67% -1.44% 17.5 ms +9.83% -2.91% -0.91%
wpTemplate 9 ms +4.44% -4.22% 11.99 ms +3.92% -2.42% -24.94%
wpTotal 26.5 ms +5.13% -2.34% 29.57 ms +7.95% -3.31% -10.38%
wpMemoryUsage 6.25 MB +0% -0% 6.33 MB +0% -0% -1.23%
wpDbQueries 9 +0% -0% 13 +0% -0% -30.77%

media-processing

Metric 328b484 trunk % Change
mediaProcessingJpeg 295.54 ms +6.78% -2.42% 290.64 ms +6.75% -1.22% 1.69%
mediaProcessingAvif 4184.66 ms +1.28% -0.78% 4192.76 ms +0.66% -1.35% -0.19%
mediaProcessingJpegToAvif 2870.74 ms +5.16% -2.14% 2853.5 ms +0.38% -1.17% 0.6%

media-upload

Metric 328b484 trunk % Change
jpegUploadProcessing 1414.14 ms +0.84% -0.63% 1391.87 ms +1.43% -0.3% 1.6%
pngUploadProcessing 178.25 ms +2.27% -4.52% 174.25 ms +5.35% -3.75% 2.3%
largeJpegUploadProcessing 1395.71 ms +1.06% -0.49% 1396.67 ms +1.02% -0.98% -0.07%
multipleImageUploadProcessing 1485.81 ms +0.4% -0.16% 1457.84 ms +2.12% -0.53% 1.92%

post-editor

Metric 328b484 trunk % Change
serverResponse 524.15 ms +5.42% -2.3% 521.76 ms +3.6% -5.55% 0.46%
firstPaint 327.37 ms +67.37% -20.33% 388.06 ms +37.04% -44.93% -15.64%
domContentLoaded 1256.54 ms +1.47% -3.37% 1204.98 ms +2.47% -0.88% 4.28%
loaded 1257.75 ms +1.47% -3.36% 1206.07 ms +2.53% -0.87% 4.28%
firstContentfulPaint 540.98 ms +6.05% -28.15% 531.57 ms +0.8% -4.14% 1.77%
firstBlock 3708.27 ms +2.09% -1.97% 3575.77 ms +2.33% -1.3% 3.71%
type 19.38 ms +11.04% -1.39% 17.9 ms +2.35% -3.02% 8.27%
typeWithoutInspector 18.71 ms +3.79% -5.45% 19.88 ms +6.19% -9.26% -5.89%
typeWithTopToolbar 25.35 ms +5.13% -6.51% 24.46 ms +9.69% -1.8% 3.64%
typeContainer 9.06 ms +6.29% -5.63% 9.18 ms +5.12% -10.78% -1.31%
focus 125.83 ms +8.77% -3.38% 117.93 ms +4.51% -2.25% 6.7%
firstFocus 268.58 ms +0% -0% 233.44 ms +0% -0% 15.05%
selectAll 608.47 ms +2.31% -2.89% 582.4 ms +1.65% -0.21% 4.48%
listViewOpen 82.33 ms +8.9% -7.25% 79.09 ms +4.53% -5.94% 4.1%
inserterOpen 43.95 ms +8.35% -13.31% 41.22 ms +7.38% -11.98% 6.62%
inserterHover 12.03 ms +10.64% -5.65% 12.35 ms +9.39% -11.74% -2.59%
inserterSearch 8.52 ms +3.87% -3.87% 7.99 ms +8.39% -3.88% 6.63%
loadPatterns 648.49 ms +1.59% -3.88% 656.41 ms +4.81% -1.85% -1.21%
wpTotal 514.02 ms +5.29% -2.29% 511.31 ms +3.81% -5.51% 0.53%
wpMemoryUsage 14.71 MB +0% -0% 14.67 MB +0% -0% 0.24%
wpDbQueries 55 +0% -1.82% 55 +0% -1.82% 0%

site-editor

Metric 328b484 trunk % Change
serverResponse 402.47 ms +4.68% -6.11% 413.19 ms +3.42% -4.96% -2.59%
firstPaint 213.92 ms +36.36% -7.27% 246.26 ms +4.21% -5.5% -13.13%
domContentLoaded 1151.22 ms +2.05% -2.04% 1182.73 ms +1.04% -0.44% -2.66%
loaded 1152.11 ms +2.04% -2.02% 1183.72 ms +1.03% -0.42% -2.67%
firstContentfulPaint 476.31 ms +6.95% -10.85% 477.52 ms +3.95% -12.07% -0.25%
firstBlock 4246.42 ms +1.02% -0.57% 4315.25 ms +0.48% -1.21% -1.6%
type 17.66 ms +3.79% -1.93% 17.24 ms +5.45% -2.55% 2.44%
navigate 121.04 ms +13.06% -7.29% 126.71 ms +11.53% -4.95% -4.47%
loadPatterns 1302.53 ms +5.21% -3.89% 1366.92 ms +3.73% -4.77% -4.71%
loadPages 990.16 ms +1.71% -0.42% 975.31 ms +4.64% -0.22% 1.52%
wpTotal 393.75 ms +4.75% -6.28% 404.31 ms +3.47% -5.08% -2.61%
wpMemoryUsage 12.72 MB +0% -0% 12.69 MB +0% -0% 0.27%
wpDbQueries 44 +2.27% -0% 44 +2.27% -0% 0%

4070267 Run

🏁 Flaky tests

Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

Regression: updating a specific option will only change its value and will not corrupt others in /test/e2e/specs/editor/various/core-settings.spec.js, passed after 1 failed attempt.
Error: expect(received).toStrictEqual(expected) // deep equality

- Expected  - 1
+ Received  + 1

  Array [
    "rewrite_rules",
-   "SERIALIZED DATA",
+   "",
  ]
    at forEach (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/core-settings.spec.js:46:26)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/various/core-settings.spec.js:43:35

4070267 Run

…t save

`session.edits`, set with `setEdit`, is undoable and cleared by Reset
because `isDirty` counts it, but `hasOutputEdits` does not, the editor's
unsaved-changes check and Save ignore it, and neither the save hook nor the
modal's modifier builder reads it. Say so in the architecture notes, the doc
comments and at `hasChanges`, and pin it with a state test, so a sidebar
panel reaching the session knows what setting one does before the session
is exposed to plugins. Applying named edits to the output is the edit
pipeline's job and a separate change.
@ramonjd ramonjd closed this Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant