Skip to content

Editor: De-duplicate the collaborators overlay styles with a CSS module - #87862

Merged
ciampo merged 6 commits into
trunkfrom
update/collaborators-overlay-css-module
Dec 3, 2026
Merged

ciampo merged 6 commits into
trunkfrom
update/collaborators-overlay-css-module

Conversation

@ciampo

@ciampo ciampo commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What?

Follow-up to #87841 (follow-up 1).

The collaborators overlay now gets its canvas styles from a CSS module, collaborators-overlay/style.module.scss, instead of about 380 lines of CSS in TypeScript strings.

Why?

The TypeScript strings copied the Avatar SCSS and base-styles values by hand, and they had already drifted. Two rules never worked:

  • The white inner ring on a collaborator's block outline used rgba(#fff, 0.7), which is invalid CSS outside Sass.
  • With reduced motion on, jumping to a collaborator still pulsed their caret and avatar.

This is also the first step toward moving the collaborator UI to the @wordpress/ui Avatar (#87841).

How?

  • The module reaches the canvas iframe through @wordpress/style-runtime, now a dependency of @wordpress/editor.
  • It loads the existing Avatar and AvatarGroup SCSS, so the overlay and the header share one source.
  • Overlay rules are scoped to the overlay root, so they don't reach the header avatars. Class names that other code and tests use stay global.
  • The two broken rules now work. A changelog entry covers both fixes.
Details
  • Scope: the runtime injects the module into every registered document, including the root document. The Avatar rules sit under a module class on the overlay root, which also carries the z-index. The block canvas cover has no z-index, so it doesn't create a stacking context, and the overlay stacks as it did when trunk lifted the whole cover. Other fills of the cover are unaffected.
  • Global names: the Avatar classes, .is-collaborator-selected, .collaborators-overlay-cursor-highlighted (added by the cursor registry), the classes the e2e tests query, and the keyframes.
  • Stacking: the z-index rules that JS generated from MAX_BLOCK_LABEL_AVATARS are an SCSS loop. The constant moves to overlay.tsx, and a comment links the two.
  • Block outline: the rule was a copy of the selected-block-focus mixin from base-styles. It now uses the mixin with the collaborator color.
  • Reduced motion: the jump pulse runs inside @media not (prefers-reduced-motion). There's no automated test: it would need a two-user session to check one media query, and its assertion would have to land inside the 2s highlight window.
  • Same output otherwise: I compared the compiled CSS with trunk's rule by rule. Hard-coded values such as 11px are now the --wpds-typography-* tokens the Avatar SCSS uses, with the same values. The unused .collaborators-overlay-fixed rule is removed.
  • Load time: the styles are injected when @wordpress/editor loads, not when the overlay mounts. Without an overlay, they match nothing.

Testing Instructions

  1. Enable Enable real-time collaboration in Gutenberg > Experiments. Open the same post in two browsers as two users.
  2. In the first browser, click into a paragraph. In the second, the caret, selection and avatar badge should look as on trunk.
  3. In the second browser, turn on Preferences > General > Outline collaborators' blocks. The outline now has a thin white inner ring.
  4. Click the collaborators avatars in the header, then the other user. The editor scrolls to their caret, which pulses. With reduced motion on in the operating system, it scrolls without the pulse.

Testing Instructions for Keyboard

No interaction changes.

Screenshots or screencast

Collaborator block outline, zoomed in 4×. Before is trunk (59501fd8406), After is this branch.

Before After
Collaborator block outline on trunk, without the inner ring Collaborator block outline on this branch, with a thin white inner ring
Full captures

Post editor on wp-env, as the second user. Captured with a temporary Playwright spec that isn't part of this PR.

Block outline on. Only the inner ring differs.

Before After
Outlined paragraph with the avatar above it, on trunk Outlined paragraph with the avatar above it, on this branch
Expanded avatar badge above the block, on trunk Expanded avatar badge above the block, on this branch

Block outline off. Identical pixel for pixel.

Before After
Avatar badge on the caret, on trunk Avatar badge on the caret, on this branch
Expanded avatar badge on the caret, on trunk Expanded avatar badge on the caret, on this branch

Use of AI Tools

Written with Claude Code (Claude Opus 5.5), at my direction: Claude made the change, captured the screenshots, and drafted this description.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Dec 2, 2026 •

Copy link
Copy Markdown

🤖 PR meta 🤖

Preview in WordPress Playground Preview in Storybook

🎉 Props

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: ciampo <mciampini@git.wordpress.org>
Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

Updated as activity occurs, without notifying anyone named here. Add the props-bot label to refresh.

📦 Bundle size

Size Change: -32 B (0%)

Total Size: 8.85 MB

📦 View Changed
Filename Size Change
build/modules/core-fields/attachment.min.js 43.9 kB +2 B (0%)
build/scripts/editor/index.min.js 575 kB -36 B (-0.01%)
build/scripts/media-utils/index.min.js 234 kB +2 B (0%)

e5c9998 Run

⚡ Performance

Show the results

Client side metrics exclude the server response time.

front-end-block-theme

Metric 069371c trunk % Change
timeToFirstByte 60.55 ms +3.63% -4.62% 58.05 ms +7.58% -2.84% 4.31%
largestContentfulPaint 92 ms +10.87% -4.35% 88 ms +6.82% -4.55% 4.55%
lcpMinusTtfb 30.8 ms +30.36% -3.41% 29.25 ms +21.37% -5.47% 5.3%
wpBeforeTemplate 32.05 ms +4.68% -4.49% 30.58 ms +12.46% -1.83% 4.81%
wpTemplate 24.19 ms +7.03% -4.71% 22.82 ms +6.66% -1.75% 6%
wpTotal 56.57 ms +2.92% -4.77% 54.32 ms +7.64% -3.2% 4.14%
wpMemoryUsage 7.76 MB +0% -0% 7.72 MB +0% -0% 0.45%
wpDbQueries 16 +0% -0% 16 +0% -0% 0%

front-end-classic-theme

Metric 069371c trunk % Change
timeToFirstByte 49.6 ms +10.58% -4.13% 49.2 ms +6.2% -2.95% 0.81%
largestContentfulPaint 86 ms +6.98% -2.33% 84 ms +11.9% -2.38% 2.38%
lcpMinusTtfb 36.85 ms +2.85% -3.26% 35.55 ms +10.41% -4.92% 3.66%
wpBeforeTemplate 28.08 ms +11.89% -2.07% 27.9 ms +10.29% -0.93% 0.65%
wpTemplate 17.49 ms +9.38% -3.49% 16.88 ms +7.17% -3.61% 3.61%
wpTotal 46.36 ms +9.71% -4.29% 46.1 ms +5.97% -3.84% 0.56%
wpMemoryUsage 6.44 MB +0% -0% 6.41 MB +0% -0% 0.56%
wpDbQueries 13 +0% -0% 13 +0% -0% 0%

media-processing

Metric 069371c trunk % Change
mediaProcessingJpeg 402.23 ms +1.81% -0.25% 410.9 ms +2.53% -0.84% -2.11%
mediaProcessingAvif 6142.96 ms +0.54% -0.14% 6171.29 ms +0.41% -0.15% -0.46%
mediaProcessingJpegToAvif 4243.67 ms +0.07% -0.06% 4256.93 ms +0.12% -0.3% -0.31%

media-upload

Metric 069371c trunk % Change
jpegUploadProcessing 2013.7 ms +1.94% -1.09% 1752.93 ms +13.88% -13.98% 14.88%
pngUploadProcessing 289.72 ms +3.77% -3.5% 270.93 ms +2.23% -1.4% 6.94%
largeJpegUploadProcessing 1986.54 ms +1.06% -24.49% 1749.49 ms +13.76% -14.28% 13.55%
multipleImageUploadProcessing 2095.76 ms +0.58% -6.64% 2074.87 ms +1.56% -1.05% 1.01%

post-editor

Metric 069371c trunk % Change
serverResponse 321.03 ms +1.59% -9.72% 326.74 ms +2.43% -2.27% -1.75%
firstPaint 338.74 ms +4.89% -8.29% 316.91 ms +16.67% -2.83% 6.89%
domContentLoaded 636.86 ms +2.44% -2.11% 651.33 ms +0.71% -1.6% -2.22%
loaded 638.07 ms +2.44% -2.1% 652.58 ms +0.69% -1.6% -2.22%
firstContentfulPaint 359.04 ms +6.07% -1.72% 366.84 ms +2.04% -4.06% -2.13%
firstBlock 1710.92 ms +1.35% -1.36% 1738.66 ms +0.44% -0.77% -1.6%
type 14.23 ms +9.28% -9.56% 13.95 ms +6.74% -4.95% 2.01%
typeWithoutInspector 14.8 ms +7.84% -7.5% 13.6 ms +8.16% -0.88% 8.82%
typeWithTopToolbar 17.72 ms +5.14% -7.45% 18.18 ms +3.63% -5.23% -2.53%
typeContainer 6.93 ms +6.78% -9.81% 6.77 ms +7.24% -10.34% 2.36%
focus 85.91 ms +5.17% -5.62% 86.64 ms +9.6% -4.62% -0.84%
firstFocus 203.69 ms +0% -0% 204.58 ms +0% -0% -0.44%
selectAll 291.34 ms +5.44% -1.77% 293.04 ms +0.39% -0.95% -0.58%
undo 24.26 ms +3.92% -4.78% 24.53 ms +4.32% -3.75% -1.1%
listViewOpen 28.59 ms +3.43% -7.1% 30.49 ms +6.63% -3.48% -6.23%
inserterOpen 30.99 ms +10.78% -6% 30.86 ms +17.79% -2.4% 0.42%
inserterHover 9.02 ms +7.32% -3.22% 9.27 ms +7.66% -3.88% -2.7%
inserterSearch 6.81 ms +5.29% -8.52% 6.73 ms +9.51% -4.9% 1.19%
loadPatterns 510.91 ms +3.25% -5.39% 521.14 ms +4.47% -3.54% -1.96%
wpTotal 312.49 ms +1.62% -9.98% 317.73 ms +2.31% -2.17% -1.65%
wpMemoryUsage 14.80 MB +0% -0% 14.76 MB +0% -0% 0.25%
wpDbQueries 55 +0% -0% 55 +0% -0% 0%

site-editor

Metric 069371c trunk % Change
serverResponse 316.74 ms +1.36% -7.1% 313.4 ms +1.12% -10.17% 1.07%
firstPaint 331.27 ms +13.52% -9.74% 359.3 ms +4.09% -15.01% -7.8%
domContentLoaded 668.97 ms +1.02% -0.58% 653.83 ms +2.69% -0.95% 2.32%
loaded 670.24 ms +1.02% -0.57% 655.17 ms +2.69% -0.99% 2.3%
firstContentfulPaint 375.4 ms +3.49% -0.88% 370.84 ms +2.78% -1.84% 1.23%
firstBlock 2068.07 ms +2.22% -1.27% 2020.62 ms +0.39% -1.18% 2.35%
type 15.03 ms +5.06% -11.58% 14.02 ms +9.13% -3.35% 7.2%
navigate 101.78 ms +0.23% -6.32% 98.3 ms +1.01% -11.87% 3.54%
loadPatterns 1088.94 ms +20.69% -10.2% 1217.87 ms +3.6% -3.7% -10.59%
loadPages 1008.64 ms +1.98% -0.25% 999.63 ms +2.25% -1.29% 0.9%
wpTotal 308.39 ms +1.36% -7.29% 305.1 ms +1.11% -10.47% 1.08%
wpMemoryUsage 12.84 MB +0% -0% 12.80 MB +0% -0% 0.28%
wpDbQueries 45 +0% -0% 45 +0% -0% 0%

e5c9998 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.

should undo without broken temporary state in /test/e2e/specs/editor/blocks/image.spec.js, passed after 1 failed attempt.
Error: expect(received).toBe(expected) // Object.is equality

- Expected  - 2
+ Received  + 2

- <!-- wp:image -->
- <figure class="wp-block-image"><img alt=""/></figure>
+ <!-- wp:image {"id":20,"sizeSlug":"full","linkDestination":"none"} -->
+ <figure class="wp-block-image size-full"><img src="http://localhost:8891/wp-content/uploads/2026/12/c68fb046-adb8-49a1-a481-0015aa160440.png" alt="" class="wp-image-20"/></figure>
  <!-- /wp:image -->
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/image.spec.js:432:49
three users concurrently edit a large post with diverse blocks in /test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts, passed after 1 failed attempt.
TimeoutError: locator.waitFor: Timeout 17500ms exceeded.
Call log:
  - waiting for getByRole('button', { name: /Collaborators list/ }) to be visible

    at map (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/fixtures/collaboration-utils.ts:193:7)
    at CollaborationUtils.waitForMutualDiscovery (/home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/fixtures/collaboration-utils.ts:188:10)
    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/collaboration/collaboration-stress.spec.ts:416:28

e5c9998 Run

@github-actions github-actions Bot added the [Package] Editor /packages/editor label Dec 2, 2026
@ciampo ciampo self-assigned this Dec 2, 2026
@ciampo ciampo added the [Type] Code Quality Issues or PRs that relate to code quality label Dec 2, 2026
@ciampo
ciampo marked this pull request as ready for review December 3, 2026 08:34
@ciampo
ciampo requested review from a team, Mamaduka and ramonjd December 3, 2026 08:34
@ciampo ciampo changed the title Editor: Move the collaborators overlay styles to a CSS module Editor: De-duplicate the collaborators overlay styles with a CSS module Dec 3, 2026

@Mamaduka Mamaduka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the follow-up, @ciampo! The migration looks good to me.

I think we can drop the :has() selector and move the z-index to .overlay. The cover is absolutely positioned without its own z-index, so it doesn't create a stacking context, and the result should be the same. I haven't tested this in the browser.

Happy to drop the e2e test. It needs a two-user session to check a single media query, and the assertion has to land within the 2s highlight window, so it could become flaky.

ciampo and others added 6 commits December 3, 2026 10:14
The collaborators overlay renders in the canvas iframe, so it injected its
styles as CSS written in TypeScript strings, with hand-made copies of the
Avatar SCSS and of base-styles values. A CSS module reaches the iframe
through @wordpress/style-runtime and can load the Avatar SCSS directly.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The overlay styles now load in every registered document, so the cover rule
reached every block canvas cover, including other fills and covers without
an overlay. Lift only the cover that holds the overlay, and leave the
positioning to the cover's own inline styles.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The reduced-motion rule listed the cursor labels, but they only animate
through the highlight rule, which is more specific, so the pulse after
jumping to a collaborator kept running. Run the pulse only when the user
hasn't asked for reduced motion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Without the overlay stylesheet the caret has no animation, so the test
passed whether or not the styles reached the canvas. Assert that the caret
blinks without a motion preference before checking reduced motion. Add a
changelog entry for the visible fixes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The block canvas cover has no z-index, so it doesn't create a stacking
context. A z-index on the overlay stacks it the same way, without a
:has() rule that reaches the cover.
It needs a two-user session to check one media query, and its assertion
has to land inside the 2s highlight window, so it could become flaky.
@ciampo
ciampo force-pushed the update/collaborators-overlay-css-module branch from a0cb36e to e5c9998 Compare December 3, 2026 09:17
@ciampo
ciampo requested a review from Mamaduka December 3, 2026 09:20

@Mamaduka Mamaduka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @ciampo!

P.S. Not sure why Vitest jobs are failing; it could be a fluke.

@ciampo

ciampo commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

They're failing because they check if any of the dependenceis that we're listing are less than 1 day old. The check was triggered by the fact that this PR modified the package-lock.

It was meant as a security check, but I admit it's noisy and not really useful as it stands. I'll look into it

@ciampo
ciampo enabled auto-merge (squash) December 3, 2026 09:30
@ciampo
ciampo merged commit d793b2b into trunk Dec 3, 2026
92 of 101 checks passed
@ciampo
ciampo deleted the update/collaborators-overlay-css-module branch December 3, 2026 09:37
@github-actions github-actions Bot added this to the Gutenberg 24.7 milestone Dec 3, 2026
@ciampo

ciampo commented Dec 3, 2026

Copy link
Copy Markdown
Contributor Author

#87888

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

Labels

[Package] Editor /packages/editor [Type] Code Quality Issues or PRs that relate to code quality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants