[internals] Replace core-js DisposableStack ponyfill with a minimal fallback#23002
Conversation
Deploy previewhttps://deploy-preview-23002--material-ui-x.netlify.app/Bundle size
Check out the code infra dashboard for more information about this PR. |
…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.
613bd81 to
ad4fb0e
Compare
romgrk
left a comment
There was a problem hiding this comment.
Good catch, didn't realize it wasn't tree-shaken. LGTM, but we can also remove core-js from the dependencies.
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.
Done, removed from dependencies |
There was a problem hiding this comment.
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.
@mui/x-internals/disposablestatically imported the fullcore-js-puredisposable-stack and async-disposable-stack ponyfills as theglobalThis.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