Skip to content

[utils] Fix pseudo-element bounds in dev - #5000

Merged
atomiks merged 4 commits into
mui:masterfrom
atomiks:codex/fix-pseudo-element-dev-bounds
Jun 11, 2026
Merged

atomiks merged 4 commits into
mui:masterfrom
atomiks:codex/fix-pseudo-element-dev-bounds

Conversation

@atomiks

@atomiks atomiks commented Jun 10, 2026 •

Copy link
Copy Markdown
Contributor

Pseudo-element hit-area expansion was skipped in every non-production build. This keeps jsdom on the safe path while allowing real development browsers to calculate pseudo-element bounds.

Root cause

The jsdom workaround was tied to NODE_ENV, so development browsers returned the element rect before reading pseudo-element styles.

Changes

  • Replace the broad non-production guard with a jsdom-specific guard.
  • Add coverage for the jsdom safe path and pseudo-element bounds calculation.

@atomiks atomiks added component: combobox Changes related to the combobox component. component: menu Changes related to the menu component. component: select Changes related to the select component. type: bug It doesn't behave as expected. labels Jun 10, 2026 — with ChatGPT Codex Connector
@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026 •

Copy link
Copy Markdown
  • base-ui-tanstack-start

  • vite-css-base-ui-example

    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/react@5000
    
    pnpm add https://pkg.pr.new/mui/base-ui/@base-ui/utils@5000
    

commit: 0e7b65d

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Bundle size

Bundle Parsed size Gzip size
@base-ui/react 🔺+19B(0.00%) 🔺+6B(0.00%)

Details of bundle changes

Performance

Total duration: 1,096.15 ms -204.06 ms(-15.7%) | Renders: 50 (+0) | Paint: 1,656.81 ms -303.19 ms(-15.5%)

Test Duration Renders
Select mount (200 instances) 127.40 ms ▼-50.72 ms(-28.5%) 3 (+0)
Mixed surface mount (app-like density) 66.23 ms ▼-39.05 ms(-37.1%) 5 (+0)
Menu mount (300 instances) 120.41 ms ▼-32.07 ms(-21.0%) 2 (+0)
Select open (500 options) 47.91 ms ▼-19.87 ms(-29.3%) 14 (+0)

8 tests within noise — details


Check out the code infra dashboard for more information about this PR.

@netlify

netlify Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for base-ui ready!

Name Link
🔨 Latest commit 0e7b65d
🔍 Latest deploy log https://app.netlify.com/projects/base-ui/deploys/6a2a31c6047d190008c8e379
😎 Deploy Preview https://deploy-preview-5000--base-ui.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@atomiks
atomiks force-pushed the codex/fix-pseudo-element-dev-bounds branch from b5b9a55 to ff64de3 Compare June 10, 2026 07:43
@atomiks
atomiks force-pushed the codex/fix-pseudo-element-dev-bounds branch from ff64de3 to 77ce714 Compare June 10, 2026 07:45
@atomiks
atomiks marked this pull request as ready for review June 10, 2026 08:08

atomiks commented Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Code Review (GPT-5.5)

Approve ✅ The patch fixes the dev-browser pseudo-element bounds path while preserving the jsdom escape hatch, with focused coverage in both jsdom and Chromium.

1. Bugs / Issues (None)

I didn’t find any blocking or non-blocking issues in the full branch diff against freshly fetched upstream/master.

2. Root Cause & Patch Assessment

The previous NODE_ENV !== 'production' guard skipped pseudo-element measurement in all dev/test builds, so real development browsers could not account for expanded hit areas. Switching that guard to platform.env.jsdom targets the actual environment that cannot safely read pseudo-element styles, while allowing browser runtimes to use the existing ::before/::after bounds calculation.

3. Test Coverage Assessment

The new tests cover both sides of the behavior: jsdom returns the element rect without calling getComputedStyle, and non-jsdom includes pseudo-element dimensions. I also verified the regression directly: upstream/master returned the plain { left: 100, right: 120, top: 50, bottom: 60 } rect in the simulated dev path, while this branch returned the expanded { left: 90, right: 130, top: 40, bottom: 70 } bounds.

Validation run:

pnpm test:jsdom getPseudoElementBounds --no-watch
pnpm test:chromium getPseudoElementBounds --no-watch
git diff --check upstream/master...HEAD

All passed, and GitHub checks for the PR head are green.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes getPseudoElementBounds so pseudo-element hit-area expansion is no longer skipped in development browsers, while still avoiding jsdom’s unsupported getComputedStyle(..., pseudoElt) behavior. It also adds targeted tests for the jsdom-safe path and for pseudo-element bounds expansion when running in a real browser environment.

Changes:

  • Switch the jsdom workaround from a broad non-production guard to a jsdom-specific environment check.
  • Add a new test suite covering the jsdom path and the browser pseudo-element bounds path.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
packages/react/src/utils/getPseudoElementBounds.ts Updates environment gating so development browsers compute pseudo-element bounds while jsdom returns the element rect.
packages/react/src/utils/getPseudoElementBounds.test.ts Adds tests for the jsdom-safe path and for pseudo-element bounds expansion in browser mode.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@atomiks atomiks added scope: all components Widespread work has an impact on almost all components. and removed component: select Changes related to the select component. component: menu Changes related to the menu component. component: combobox Changes related to the combobox component. labels Jun 11, 2026
@atomiks
atomiks merged commit 08e9ba6 into mui:master Jun 11, 2026
10 checks passed
@atomiks
atomiks deleted the codex/fix-pseudo-element-dev-bounds branch June 11, 2026 04:19
brijeshb42 added a commit to brijeshb42/base-ui that referenced this pull request Nov 26, 2026
A change labeled with a component or all components is for users, even
with a prefix such as [utils]: mui#5000 was published in v1.6.0.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: all components Widespread work has an impact on almost all components. type: bug It doesn't behave as expected.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants