Mantle Between Variant Migration Guide
@ngrok/mantle registers a between: Tailwind variant. It applies a class to each child of an element except the last, at zero specificity, as Tailwind's space-* and divide-* do. Mantle's parts now use it for their own spacing and dividers: Accordion.Root and Strata.Root draw dividers with between:border-b, and the menus, lists, and dialog parts space their children with between:mbe-* or between:me-*. A space-* or divide-* class that you pass to one of those parts no longer replaces the part's class through cx, so the part's spacing or divider stays.
TL;DR: On the parts in step 1, rewrite space-y-N to between:mbe-N, space-x-N to between:me-N, divide-y-0 to between:border-b-0, divide-y to between:border-b, and divide-<color> to between:border-<color>. Keep every variant prefix. Leave space-* and divide-* on other elements alone.
Codemod
From a mantle checkout:
In a project that installs @ngrok/mantle:
The rules apply step 2. They rewrite the string literals inside the className of a part in step 1, also inside a cx() call, and inside the className of the element that an asChild part renders. Each rule finds a part through its import from its own @ngrok/mantle/ subpath, so a renamed import matches, and a part from another library or a local name that shadows the import stays. These stay manual, and the rules leave the whole string unchanged:
- Step 3, because a class in a variable or a prop of your own wrapper is not on the part in the JSX.
- A string with
space-x-reverse,space-y-reverse,divide-x-reverse, ordivide-y-reverse.between:has no reverse form: put the margin or the border on the other side, such asbetween:ms-4forspace-x-4 space-x-reverse. - A string where the class sits inside an arbitrary value, such as
[&[data-label='x:space-y-2']]:…. - A string compared with
===,!==,==, or!=, because it chooses a class and is not one.
The codemod is safe to run twice. Pass --dry-run to print the rewrites first, and run your formatter after the rewrite.
You are an agent migrating a codebase. Do this:
- Find the parts whose own classes now use
between::Accordion.Root,Strata.Root,AlertDialog.Body,AlertDialog.Header,AlertDialog.Footer,Empty.Description,Select.Group,Select.Content,DropdownMenu.Group,DropdownMenu.RadioGroup,DropdownMenu.Content,DropdownMenu.SubContent,MultiSelect.Content,Combobox.Content,Combobox.Group,Sidebar.Body,Sidebar.List, andSplitButton.MenuContent. Search for each name and for a renamed import. WithasChild, the override is on the one child element. - In the
classNameof each such part, rewrite eachspace-*anddivide-*class. Keep its variant prefix and its value:space-y-Nbecomesbetween:mbe-N, sospace-y-0becomesbetween:mbe-0, and-space-y-2becomesbetween:-mbe-2.space-x-Nbecomesbetween:me-N, sosm:space-x-2becomessm:between:me-2.divide-y-0becomesbetween:border-b-0, anddivide-ybecomesbetween:border-b.divide-<color>ordivide-<style>becomesbetween:border-<color>orbetween:border-<style>.
- Find a
space-*ordivide-*class that reaches one of those parts through a variable, a constant, or a wrapper component's prop, and rewrite it the same way. - After editing, run the project's formatter, linter, type checker, and tests.
Why a variant? Tailwind compiles
space-y-2to:where(.space-y-2 > :not(:last-child)). The class sits inside:where(), so Chromium cannot skip the rule on its quick ancestor test, and it tries the rule on each element of the page on each style pass. A native modal restyles the whole page as it opens, so each such rule makes eachDialogopen slower.between:mbe-2compiles to:where(.between\:mbe-2) > :where(:not(:last-child)): the same zero specificity, with the class outside, so Chromium skips it at once.
Before → after
Accordion without dividers
A combobox list with no gap between options
Edge cases & gotchas
between:mbe-Nsets only the block-end margin of each child but the last.space-y-Nalso set the block-start margin to 0 at zero specificity. Preflight already sets it to 0, so this differs only when a rule in your own base layer gives those children a top margin.- A
space-*ordivide-*class on an element that is not a part in step 1 keeps working. Rewriting it tobetween:is optional, and it makes the page's style passes cheaper.
How to verify
Search the parts in step 1 for space- and divide- in their className, and expect a match only for the manual cases under Codemod. Then run your formatter, linter, type checker, and tests, and look at each changed accordion, menu, and dialog in a browser.