Skip to content

[internals] Replace core-js DisposableStack ponyfill with a minimal fallback#23002

Merged
sai6855 merged 8 commits into
mui:masterfrom
sai6855:scheduler-core-js
Jun 30, 2026
Merged

[internals] Replace core-js DisposableStack ponyfill with a minimal fallback#23002
sai6855 merged 8 commits into
mui:masterfrom
sai6855:scheduler-core-js

Conversation

@sai6855

@sai6855 sai6855 commented Jun 29, 2026

Copy link
Copy Markdown
Member

@mui/x-internals/disposable statically imported the full core-js-pure disposable-stack and async-disposable-stack ponyfills as the globalThis.X ?? ... fallbacks, so the polyfill (plus its core-js internals) was bundled unconditionally even on engines with native support.

Replace them with a minimal, spec-compatible built-in implementation covering the methods used across the codebase (use/adopt/defer/move/dispose/disposed and the dispose symbols), still preferring the native class when present. Removes ~11.7KB gzip from the scheduler barrel and 12kb from tree view

@code-infra-dashboard

code-infra-dashboard Bot commented Jun 29, 2026

Copy link
Copy Markdown

Deploy preview

https://deploy-preview-23002--material-ui-x.netlify.app/
QR code for https://deploy-preview-23002--material-ui-x.netlify.app/

Bundle size

Bundle Parsed size Gzip size
@mui/x-data-grid 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-pro 0B(0.00%) 0B(0.00%)
@mui/x-data-grid-premium 0B(0.00%) 0B(0.00%)
@mui/x-charts 0B(0.00%) 0B(0.00%)
@mui/x-charts-pro 0B(0.00%) 0B(0.00%)
@mui/x-charts-premium 0B(0.00%) 0B(0.00%)
@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 ▼-33.1KB(-33.05%) ▼-12.1KB(-37.61%)
@mui/x-tree-view-pro ▼-33.1KB(-21.11%) ▼-12KB(-24.17%)
@mui/x-scheduler ▼-33.2KB(-8.53%) ▼-11.7KB(-10.81%)
@mui/x-scheduler-premium ▼-33.2KB(-6.49%) ▼-11.7KB(-8.16%)
@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.

@sai6855 sai6855 added type: enhancement It’s an improvement, but we can’t make up our mind whether it's a bug fix or a new feature. scope: tree view Changes related to the tree view. This includes TreeView, TreeItem. scope: scheduler Changes related to the scheduler. labels Jun 29, 2026
sai6855 added 2 commits June 29, 2026 18:52
…allback

`@mui/x-internals/disposable` statically imported the full `core-js-pure`
disposable-stack and async-disposable-stack ponyfills as the
`globalThis.X ?? ...` fallbacks, so the polyfill (plus its core-js internals)
was bundled unconditionally even on engines with native support.

Replace them with a minimal, spec-compatible built-in implementation covering
the methods used across the codebase (use/adopt/defer/move/dispose/disposed
and the dispose symbols), still preferring the native class when present.
Removes ~11.7KB gzip from the scheduler barrel and benefits every package
that builds on x-internals.

Verified against the existing disposable unit tests and the scheduler store
dispose tests.
Add coverage that exercises the minimal fallback classes (not the native
`globalThis.DisposableStack`) by stubbing the global away and re-importing,
so the `?? fallback` branch is the one under test. Covers use (incl. LIFO
order, null no-op, non-disposable TypeError), adopt, defer, move, idempotent
dispose, registration-after-dispose throwing, and SuppressedError aggregation
both with and without a native `SuppressedError`, plus the async stack.
@sai6855
sai6855 force-pushed the scheduler-core-js branch from 613bd81 to ad4fb0e Compare June 29, 2026 18:53
@sai6855
sai6855 requested a review from Copilot June 29, 2026 19:05

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@sai6855
sai6855 marked this pull request as ready for review June 29, 2026 19:12
@sai6855
sai6855 requested a review from romgrk as a code owner June 29, 2026 19:12
@romgrk
romgrk requested a review from rita-codes June 29, 2026 19:40

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

Good catch, didn't realize it wasn't tree-shaken. LGTM, but we can also remove core-js from the dependencies.

sai6855 and others added 4 commits June 30, 2026 03:56
With the disposable stacks no longer importing core-js-pure, x-internals was
its only consumer, so drop it from the package dependencies, the workspace
catalog, and the build-script allowlist, and refresh the lockfile.
@sai6855

sai6855 commented Jun 30, 2026

Copy link
Copy Markdown
Member Author

but we can also remove core-js from the dependencies.

Done, removed from dependencies

@rita-codes rita-codes 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.

Nice cleanup!! Thanks for taking care of this 🙇‍♀️ the fallback is spec-faithful and actually covers the full surface 🙌

One nit before merge: the suppressed-error fallback message gets minified (registered as code 295) and isn't MUI X:-prefixed, unlike the other two new errors in the file which are /* minify-error-disabled */. Since it's meant to mirror the native SuppressedError default text, I'd mark it /* minify-error-disabled */ and drop the 295 entry, that keeps the native-compatible message in production and matches the other errors here 👀

Thanks!

…fier

The fallback message mirrors the native SuppressedError default text, so it
should ship verbatim in production rather than be replaced by an error code.
Mark the `new Error` `/* minify-error-disabled */` (matching the other
fallback errors in the file) and drop the now-unused error code 295.
@sai6855
sai6855 merged commit b785d10 into mui:master Jun 30, 2026
21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

scope: scheduler Changes related to the scheduler. scope: tree view Changes related to the tree view. This includes TreeView, TreeItem. 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.

4 participants