Skip to content

Popover, Modal: Wrap content in ThemeProvider - #81183

Closed
mirka wants to merge 10 commits into
trunkfrom
popover-theme-provider
Closed

mirka wants to merge 10 commits into
trunkfrom
popover-theme-provider

Conversation

@mirka

@mirka mirka commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

What?

Wraps @wordpress/components Popover and Modal content in ThemeProvider.

Follow up to #81112. Supersedes #81178.

Why?

Portaled popovers and modals render outside their ancestor ThemeProvider wrapper in the DOM, so they do not receive the CSS custom properties emitted on that wrapper even though React context is preserved. WPDS-styled UI inside popovers and modals (buttons, inputs, etc.) can therefore miss admin color scheme tokens.

This matches the pattern already used by @wordpress/ui popup primitives (Popover.Popup, Dialog.Popup, Select.Popup, Tooltip.Popup, etc.), which wrap their portaled content in ThemeProvider to reapply inherited seed values.

Specifically as a backport fix for 7.1

We have a 7.1 regression where certain popovers and modals in the site editor do not inherit the admin color properly.

Simply using isRoot on an editor layout provider was considered as the quickest fix (#81178). However, unlike the block editor which only needs one accent color, the site editor sets an admin scheme color as a background color on the outer UI chrome. This means that this outer background color (not white) would apply to portaled popovers, which is not what we want. We do in fact need React-tree-based theme inheritance to fix this.

How?

  • Wrap the popover floating content in <ThemeProvider> (no color prop), so inherited settings from ancestor providers are re-emitted on the popover wrapper.
  • Wrap the modal frame in <ThemeProvider> inside StyleProvider, for the same reason.

Testing Instructions

  1. Start wp-env and build the branch (npm start).
  2. Open the Site Editor (/wp-admin/site-editor.php).
  3. Switch admin color schemes under Users → Profile (e.g. Ocean, Midnight, Sunrise, Light).
  4. Reload the Site Editor and open a popover or modal, e.g. DataViews "View options" dropdown in Pages, dropdown menus or font modal in Styles.
  5. Confirm WPDS-styled UI inside the popover reflects the chosen scheme's primary/accent colors.
  6. Smoke test for issues in the post editor.
  7. Open a modal in the Site Editor or post editor and confirm WPDS-styled UI inside it also reflects the chosen scheme.

This should also work correctly when cherry picked onto the wp/7.1 branch.

@mirka mirka self-assigned this Aug 4, 2026
@github-actions github-actions Bot added the [Package] Components /packages/components label Aug 4, 2026
@mirka mirka added [Type] Enhancement A suggestion for improvement. Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta labels Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026 •

Copy link
Copy Markdown

Size Change: +53 B (0%)

Total Size: 7.73 MB

📦 View Changed
Filename Size Change
build/scripts/components/index.min.js 256 kB +53 B (+0.02%)

compressed-size-action

@mirka mirka changed the title Popover: Wrap content in ThemeProvider Popover and Modal: Wrap content in ThemeProvider Aug 4, 2026
@mirka mirka changed the title Popover and Modal: Wrap content in ThemeProvider Popover, Modal: Wrap content in ThemeProvider Aug 4, 2026
@t-hamano

t-hamano commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

I will soon start the release process for 7.1 RC1. Let's consider releasing this PR for RC2 if possible.

@mirka

mirka commented Aug 5, 2026

Copy link
Copy Markdown
Member Author

The one risk factor for breakage here is that this adds one extra div wrapper to the Popover and Modal components, which can effect styling if certain styles depend on DOM structure. A scan of the codebase didn't surface any issues in production code, so I think the number of breakages should be relatively small. (Aside from the fact that we don't guarantee DOM stability as a compatibility policy in the first place.)

I found one possibly affected case in the experimental boot code, but I couldn't find an actual code path that exercises this popover transition specifically. And this is likely something that needs to be managed a bit more explicitly, not just targeting the first matching instance of a broad component category. It will be impossible to target broad component categories like this with @wordpress/ui components.

@mirka
mirka marked this pull request as ready for review August 5, 2026 21:31
@mirka
mirka requested review from a team and ajitbohra as code owners August 5, 2026 21:31
@github-actions

github-actions Bot commented Aug 5, 2026 •

Copy link
Copy Markdown

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

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: mirka <0mirka00@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: aduth <aduth@git.wordpress.org>

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

@t-hamano t-hamano left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I might be missing something, but what do you think about inverting the seed?

packages/edit-site/src/components/layout/index.js

<SlotFillProvider>
	<Tooltip.Provider>
		{ /** This needs to be within the SlotFillProvider */ }
		<PluginArea onError={ onPluginAreaError } />
		<ThemeProvider
			isRoot
			color={ {
				primary: themeColors.primary,
				...CONTENT_COLOR,
			} }
		>
			<ThemeProvider color={ themeColors }>
				<Layout { ...props } />
			</ThemeProvider>
		</ThemeProvider>
	</Tooltip.Provider>
</SlotFillProvider>

I believe this is an approach also used in the boot package.

<ThemeProvider
isRoot
color={ { ...themeColors, background: '#f8f8f8' } }
>
<ThemeProvider color={ themeColors }>

@mirka

mirka commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

@t-hamano Good point, not sure how I missed that approach 😅 I have tested that on the 7.1 branch and verified that it's sufficient. Since the correct long-term fix is the one in this PR where we wrap Popover/Modal, I think the preferable thing to do is to land the inverted approach on the 7.1 branch only (#81296), as a backport-specific fix. Is that reasonable?

@mirka mirka removed the Backport to WP 7.2 Beta/RC Pull request that needs to be backported to the WordPress major release that's currently in beta label Aug 6, 2026
@aduth

aduth commented Aug 12, 2026

Copy link
Copy Markdown
Member

Am I correct in understanding that since #81296 has landed for the 7.1 branch and we still think this is the better long-term solution, we'll want to rebase this, merge it to trunk without a backport and have it land in a future release? Do we want to explicitly undo the changes in #81296 at any point or do those continue to be valid?

@mirka
mirka marked this pull request as draft August 12, 2026 16:33
@mirka

mirka commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

Am I correct in understanding that since #81296 has landed for the 7.1 branch and we still think this is the better long-term solution, we'll want to rebase this, merge it to trunk without a backport and have it land in a future release?

Correct. I'll check whether any of the section-level ThemeProvider should have their configs modified now.

Do we want to explicitly undo the changes in #81296 at any point or do those continue to be valid?

I was thinking that can remain in the 7.1 branch indefinitely. Any concerns?

@aduth

aduth commented Aug 13, 2026

Copy link
Copy Markdown
Member

No concerns 👍 Just wanted to clarify my understanding of long-term vs. short-term fix if we need to make a point to remove the short-term fix.

@aduth

aduth commented Aug 13, 2026

Copy link
Copy Markdown
Member

Oh, I guess if it was committed directly to wp/7.1 it doesn't actually exist in trunk and won't exist in future versions, so effectively those changes do get removed? 🤔

@github-actions

Copy link
Copy Markdown

Flaky tests detected in eeab756.
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.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/31827084354
📝 Reported tests:

adds and activates a new tab when pressing Enter at the end of a tab label in /test/e2e/specs/editor/blocks/tabs.spec.js, passed after 1 failed attempt.
Error: expect(locator).toHaveCount(expected) failed

Locator:  locator('[name="editor-canvas"]').contentFrame().getByRole('tab')
Expected: 3
Received: 2
Timeout:  5000ms

Call log:
  - Expect "toHaveCount" with timeout 5000ms
  - waiting for locator('[name="editor-canvas"]').contentFrame().getByRole('tab')
    14 × locator resolved to 2 elements
       - unexpected value "2"

    at /home/runner/work/gutenberg/gutenberg/test/e2e/specs/editor/blocks/tabs.spec.js:146:25

@mirka

mirka commented Aug 14, 2026

Copy link
Copy Markdown
Member Author

I did some more testing, and realized that I was too optimistic about this approach. There seems to be about 10+ popover/modals that are triggered open from the dark mode chrome, and most of those are not theme-ready yet. What's worse is that some of the theming gets applied, and what results is a very broken state like:

Link control popover

If it were just a few occurrences, maybe we could just wrap those instances in a ThemeProvider with a light background as a stopgap. But the number is pretty high, and I think there are a few places where that is not even possible with the current component structure (like the link control in the screenshot).

So all in all, I don't think we're ready to enable "real" dark mode at this scale on legacy componentry yet. It only works in the sidebar chrome because the non-portaled content is fairly simple, and often customized locally to support theming.

Bringing back the inverted approach to trunk in #81653.

@mirka

mirka commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

Closing in favor of the new strategy in #82038

@mirka mirka closed this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Components /packages/components [Type] Enhancement A suggestion for improvement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants