Repository navigation
Conversation
Deploy previewBundle size
PerformanceNo regressions in 32 benchmarks · precise to ±5.4% (±15.4% at worst) · ran 2m 18s · details Check out the code infra dashboard for more information about this PR. |
aarongarciah
left a comment
There was a problem hiding this comment.
Thanks for following up on #49844. The direction matches the item in #49337, and the backdrop merge fixes two things that are broken on master: a nested slotProps.root.slotProps.backdrop no longer drops transitionDuration, and it no longer breaks swiping in SwipeableDrawer.
A few things before this can go in:
1. A callback-form nested backdrop gets the Drawer root classes
mergeSlotProps returns a callback when either argument is a function, and that callback adds ownerState.className. Modal resolves it with its own owner state, whose className is the Drawer root's. With
<Drawer open slotProps={{ root: { slotProps: { backdrop: () => ({}) } } }} />the backdrop gets MuiDrawer-root MuiDrawer-modal plus the user's className, and its computed z-index goes from -1 to 1200. On master this case renders a clean backdrop, so it is a regression. Resolving both sides before merging avoids the function branch:
const rootSlotPropsWithBackdrop = (rootOwnerState) => {
const resolvedRootSlotProps = resolveComponentProps(slotProps.root, rootOwnerState);
const nestedBackdrop = resolvedRootSlotProps?.slotProps?.backdrop;
const ownBackdrop = externalForwardedProps.slotProps.backdrop;
return {
...resolvedRootSlotProps,
slotProps: {
...resolvedRootSlotProps?.slotProps,
backdrop: (backdropOwnerState) =>
mergeSlotProps(
resolveComponentProps(nestedBackdrop, backdropOwnerState),
resolveComponentProps(ownBackdrop, backdropOwnerState),
),
},
};
};A top-level callback slotProps.backdrop already has this problem on master, so that part is out of scope here.
2. Merge slots as well
slotProps.root.slots, even an empty object, replaces the slots.backdrop passed through additionalProps. The codemod now moves ModalProps.slots under slotProps.root, so I'd merge it the same way as slotProps:
slots: { backdrop: slots.backdrop, ...resolvedRootSlotProps?.slots },3. Stale entries in scripts/generateProptypes.ts
'ModalProps' is still listed for SwipeableDrawer in useExternalDocumentation and ignoreExternalDocumentation.
4. Upgrade guide
"Props nested inside ModalProps, such as slots and slotProps.backdrop, are applied when moved to slotProps.root" doesn't say they were ignored before, so it doesn't read as a behavior change. Something like: "slots and slotProps nested inside ModalProps were previously ignored. They take effect once moved to slotProps.root." It's also worth saying that the codemod covers ModalProps in the theme's defaultProps.
5. Tests
The new Drawer test covers the className merge. Could you add one asserting that transitionDuration reaches the backdrop when a nested backdrop is set, and one with the nested backdrop as a callback? The second would have caught point 1.
|
Thanks for the detailed review. Addressed in 8525631:
I also made a small related fix in SwipeableDrawer: with a callback |
Part of #49337 (Drawer: remove
ModalPropsin favor ofslotProps.root). This is the v10 removal that follows the deprecation in #49844.Changes (breaking)
ModalPropsfromDrawer. UseslotProps.rootinstead; a nestedslotProps.root.slotProps.backdropis merged with the Drawer's own backdrop props.SwipeableDrawerno longer readsModalProps. ItskeepMounted: truedefault for temporary drawers now goes throughslotProps.root, and a user-providedslotProps.root.keepMountedstill takes precedence.ModalProps.drawer-propscodemod already migrates the prop.ModalPropsentry from the deprecated APIs page, as in [material-ui][InputBase] Remove the deprecateddisableInjectingGlobalStylesprop #49777.SwipeableDrawerkeepMounteddefault and override.Notes
ModalPropssuch asslotsandslotProps.backdropwere not forwarded to the Modal before (useSlotconsumed them), but they take effect when passed throughslotProps.root. Thedrawer-propscodemod movesModalPropsintoslotProps.root, so such values now apply. NestedslotProps.root.slotsstill replaces a custom top-levelslots.backdrop, and a nested backdroprefstill replacesSwipeableDrawer's internal one; both match the existingslotProps.rootbehavior.