Skip to content

[internal] Use @base-ui/utils/platform for platform detection#22710

Merged
romgrk merged 16 commits into
mui:masterfrom
romgrk:refactor-platform-detection
Jun 22, 2026
Merged

[internal] Use @base-ui/utils/platform for platform detection#22710
romgrk merged 16 commits into
mui:masterfrom
romgrk:refactor-platform-detection

Conversation

@romgrk

@romgrk romgrk commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Replaces MUI X's ad-hoc platform/navigator detection with the new @base-ui/utils/platform module, removing the duplicated in-house detection code.

Changes

Removed old detection code:

  • packages/x-internals/src/platform/index.ts (isFirefox, isJSDOM)
  • packages/x-data-grid/src/utils/isJSDOM.ts (duplicate isJSDOM)
  • Dead isAndroid export in useField.utils.ts and the local isAndroid in tree-view-pro's itemPlugin.ts

Migrated to @base-ui/utils/platform flags:

Old New
platform.isFirefox platform.engine.gecko
platform.isJSDOM / isJSDOM platform.env.jsdom
navigator.platform Mac checks platform.os.mac
isAndroid() platform.os.android

Touched: x-virtualizer, x-data-grid, x-data-grid-premium, x-internal-gestures, x-tree-view-pro.

Tests: redirected telemetry + formatNumber tests to the shared test/utils/skipIf helper; refactored skipIf.ts itself (isJSDOMenv.jsdom, isOSXos.mac) and a navigator.platform check in the cell-selection test.

Dependencies: added @base-ui/utils to the consuming packages and to root devDependencies (for the test helper).

Notes

  • useReduceAnimations.ts is intentionally left untouched — it needs OS version numbers, which the boolean platform module doesn't express. Whether to keep/replace that heuristic is a separate behavior decision.
  • The platform subpath only exists in the not-yet-released @base-ui/utils, so wiring it up (linking/rebuilding the local checkout) is still pending — CI typecheck/tests won't pass until then. eslint passes.

🤖 Generated with Claude Code

Comment thread packages/x-date-pickers/src/internals/hooks/useReduceAnimations.ts Outdated

@LukasTy LukasTy 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.

LGTM with a few observations.

Claude review

Blocking (external dependency, not a code defect)

# Item Detail
1 Unreleased ./platform subpath The cataloged and latest-published @base-ui/utils is 0.2.9, whose exports has no ./platform entry. Every import { platform } from '@base-ui/utils/platform' therefore fails to resolve, which is what turns typecheck/unit/browser/build/package CI red. Unblock by publishing a base-ui version that exposes ./platform, then bump the catalog (pnpm-workspace.yaml:18, currently ^0.2.9).
2 Lockfile not regenerated @base-ui/utils was added to 5 package.json files but pnpm-lock.yaml is untouched, so pnpm install --frozen-lockfile fails on its own. Run pnpm install (+ pnpm dedupe) and commit the lockfile once the new version is cataloged.

Suggestions

# File Suggestion
1 KeyboardManager.ts:107 (and confirm useGridCellSelection.ts:306) Real behavior change worth a conscious decision: base-ui os.mac is !ios && platform.startsWith('mac') and excludes iPadOS (it routes platform === 'macintel' && maxTouchPoints > 1 to ios), whereas the old navigator.platform.includes('Mac') treated iPad as Mac. So in the cross-platform ControlOrMeta check, an iPad with a keyboard now maps to Control instead of Meta/Cmd. If iPad should keep Cmd semantics, use platform.os.apple (= mac

What Looks Good

  • Equivalence verified against base-ui source: engine.gecko = Firefox, os.android/os.mac as expected, and env.jsdom = /jsdom|happydom/ so HappyDOM is still matched (no regression vs the old /jsdom|HappyDOM/).
  • @mui/x-internals uses a "./*": "./src/*/index.ts" wildcard export, so deleting the platform source needs no export-map cleanup.
  • Dependency hygiene is right: the 4 newly-importing packages declare @base-ui/utils, x-tree-view-pro already had it, and root gets it as a devDependency for the test/utils/skipIf helper.
  • Good cleanup: dead isAndroid export removed and telemetry/formatNumber tests redirected to the shared skipIf helper, cutting duplicated detection logic.

@zannager zannager added the internal Behind-the-scenes enhancement. Formerly called “core”. label Jun 9, 2026
romgrk and others added 2 commits June 10, 2026 07:49
base-ui os.mac excludes iPadOS (routed to os.ios), so an iPad with a
keyboard would map ControlOrMeta to Control. Use os.apple (mac || ios)
to keep Cmd/Meta as the primary modifier on Apple platforms.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@romgrk romgrk marked this pull request as draft June 10, 2026 12:09
@romgrk romgrk marked this pull request as ready for review June 12, 2026 17:44
@romgrk romgrk added the type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. label Jun 12, 2026
The 0.3.0 exports map dropped the ./store/useStore deep subpath, so
import it from ./store instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@code-infra-dashboard

code-infra-dashboard Bot commented Jun 17, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-22710--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 🔺+213B(+0.05%) 🔺+44B(+0.04%)
@mui/x-data-grid-pro 🔺+211B(+0.04%) 🔺+97B(+0.06%)
@mui/x-data-grid-premium 🔺+326B(+0.05%) 🔺+147B(+0.07%)
@mui/x-charts 🔺+453B(+0.12%) 🔺+206B(+0.17%)
@mui/x-charts-pro 🔺+441B(+0.08%) 🔺+225B(+0.14%)
@mui/x-charts-premium 🔺+441B(+0.07%) 🔺+234B(+0.12%)
@mui/x-date-pickers 0B(0.00%) 0B(0.00%)
@mui/x-date-pickers-pro 0B(0.00%) 0B(0.00%)
@mui/x-tree-view 0B(0.00%) 0B(0.00%)
@mui/x-tree-view-pro 🔺+395B(+0.25%) 🔺+210B(+0.43%)
@mui/x-license 0B(0.00%) 0B(0.00%)

Details of bundle changes


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

romgrk and others added 6 commits June 17, 2026 13:26
@base-ui/utils 0.3.0 removed the "./*" wildcard export, so the deep
"./store/useStore" subpath no longer resolves. Import from the package's
"./store" entry point, which re-exports useStore, instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@romgrk romgrk requested review from JCQuintas and LukasTy June 17, 2026 18:38

@LukasTy LukasTy 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.

LGTM. 👍
Great work, nice improvement.

Comment thread packages/x-date-pickers/src/internals/hooks/useReduceAnimations.ts Outdated
@github-actions github-actions Bot added the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

romgrk and others added 2 commits June 22, 2026 10:37
…s.ts

Co-authored-by: Lukas Tyla <llukas.tyla@gmail.com>
Signed-off-by: Rom Grk <romgrk@users.noreply.github.com>
# Conflicts:
#	packages/x-internals/src/platform/index.ts
@github-actions github-actions Bot removed the PR: out-of-date The pull request has merge conflicts and can't be merged. label Jun 22, 2026
@romgrk romgrk merged commit bf9ddd5 into mui:master Jun 22, 2026
21 checks passed
@romgrk romgrk deleted the refactor-platform-detection branch June 22, 2026 17:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal Behind-the-scenes enhancement. Formerly called “core”. type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants